Skip to content

test(vue): add unit tests for getDisplayName utility#530

Open
salabili212 wants to merge 1 commit into
asgardeo:mainfrom
salabili212:test-coverage-vue-sdk
Open

test(vue): add unit tests for getDisplayName utility#530
salabili212 wants to merge 1 commit into
asgardeo:mainfrom
salabili212:test-coverage-vue-sdk

Conversation

@salabili212

@salabili212 salabili212 commented Jun 9, 2026

Copy link
Copy Markdown

Purpose

I noticed that the getDisplayName utility function in the @asgardeo/vue package had no unit tests at all. This PR adds 6 tests covering all the main code paths — including fallback behavior when user attributes are missing, and when displayAttributes are provided.

Related Issues

Related PRs

  • N/A

Checklist

  • Followed the CONTRIBUTING guidelines.
  • Manual test round performed and verified.
  • Documentation provided. (Add links if there are any)
  • Unit tests provided.

Security checks

Summary by CodeRabbit

  • Tests
    • Added test coverage for display name functionality, including default values, name combinations, fallback scenarios, and configurable attributes.

@coderabbitai

coderabbitai Bot commented Jun 9, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

This pull request adds a comprehensive test suite for the getDisplayName utility in the Vue SDK. The test file verifies fallback behaviors when constructing display names from user profile data, including default values, name concatenation, and override parameters.

Changes

Display Name Utility Tests

Layer / File(s) Summary
getDisplayName test suite with mocks and fallback validation
packages/vue/src/__tests__/utils/getDisplayName.test.ts
Test suite mocks getMappedUserProfileValue and validates display name generation: defaults to 'User' when no data is present, combines first and last names, falls back to username or email when names are missing, and respects an optional displayAttributes parameter that skips empty attribute arrays.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A tester's delight, so neat and so clean,
Display names now tested in every scene!
From fallbacks to attributes, no path left alone,
Coverage blooms bright in this test-file zone! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main change: adding unit tests for the getDisplayName utility in the Vue package.
Description check ✅ Passed The description follows the template with all major sections completed: Purpose, Related Issues, Related PRs, Checklist items marked, and Security checks completed.
Linked Issues check ✅ Passed The PR successfully addresses issue #170 by adding 6 unit tests covering main code paths, fallback behavior, and displayAttributes handling, directly fulfilling the objective to improve test coverage for untested code paths.
Out of Scope Changes check ✅ Passed All changes are scoped to adding unit tests for the getDisplayName utility, directly aligned with issue #170's objective to improve test coverage for untested code paths in @asgardeo/vue.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
packages/vue/src/__tests__/utils/getDisplayName.test.ts (1)

26-59: ⚡ Quick win

The tests validate return order but not lookup keys.

Using only mockReturnValueOnce can still pass if getDisplayName calls getMappedUserProfileValue with wrong attribute names but the same call count/order. Add argument assertions (e.g., toHaveBeenNthCalledWith) or switch to a key-based mock implementation map.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/vue/src/__tests__/utils/getDisplayName.test.ts` around lines 26 -
59, The tests for getDisplayName currently only assert call order via
mockReturnValueOnce, which can hide wrong lookup keys; update the tests in
getDisplayName.test.ts to assert the actual lookup keys passed to
getMappedUserProfileValue (or mockGet) — either replace the sequenced
mockReturnValueOnce approach with a key-based mock implementation (e.g.,
mockGet.mockImplementation(key => ({ firstName: 'Jane', lastName: 'Doe',
username: 'janedoe', email: 'jane@example.com' }[key]))) or add explicit
argument assertions using toHaveBeenNthCalledWith against mockGet for each case;
target the tests that call getDisplayName(mergedMappings, user, ...) and verify
mockGet/getMappedUserProfileValue was called with the expected attribute names.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@packages/vue/src/__tests__/utils/getDisplayName.test.ts`:
- Around line 33-47: Add a new unit test to cover the `name` fallback in
getDisplayName: in the test file using the same helpers (`mockGet`,
`mergedMappings`, `user`), set mockGet to return undefined for firstName,
lastName, username, and email (four consecutive mockReturnValueOnce(undefined)
calls) and then return a non-empty string for `name` (e.g., 'Jane Doe'); call
getDisplayName(mergedMappings, user) and assert the result equals that `name`
value so the explicit `name` branch in getDisplayName is exercised.

---

Nitpick comments:
In `@packages/vue/src/__tests__/utils/getDisplayName.test.ts`:
- Around line 26-59: The tests for getDisplayName currently only assert call
order via mockReturnValueOnce, which can hide wrong lookup keys; update the
tests in getDisplayName.test.ts to assert the actual lookup keys passed to
getMappedUserProfileValue (or mockGet) — either replace the sequenced
mockReturnValueOnce approach with a key-based mock implementation (e.g.,
mockGet.mockImplementation(key => ({ firstName: 'Jane', lastName: 'Doe',
username: 'janedoe', email: 'jane@example.com' }[key]))) or add explicit
argument assertions using toHaveBeenNthCalledWith against mockGet for each case;
target the tests that call getDisplayName(mergedMappings, user, ...) and verify
mockGet/getMappedUserProfileValue was called with the expected attribute names.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bf893e0e-aae8-48fc-a88f-6e6eb13031b1

📥 Commits

Reviewing files that changed from the base of the PR and between 66838b8 and 2d9ecad.

📒 Files selected for processing (1)
  • packages/vue/src/__tests__/utils/getDisplayName.test.ts

Comment on lines +33 to +47
it('returns username when no firstName or lastName', () => {
mockGet.mockReturnValueOnce(undefined);
mockGet.mockReturnValueOnce(undefined);
mockGet.mockReturnValueOnce('janedoe');
const result = getDisplayName(mergedMappings, user);
expect(result).toBe('janedoe');
});

it('returns email when no firstName lastName or username', () => {
mockGet.mockReturnValueOnce(undefined);
mockGet.mockReturnValueOnce(undefined);
mockGet.mockReturnValueOnce(undefined);
mockGet.mockReturnValueOnce('jane@example.com');
const result = getDisplayName(mergedMappings, user);
expect(result).toBe('jane@example.com');

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor | ⚡ Quick win

Missing coverage for the name fallback branch.

getDisplayName has an explicit name fallback after username and email, but this suite never asserts that path. Add a test where firstName/lastName/username/email are absent and name is present.

Suggested test addition
+  it('returns name when firstName, lastName, username, and email are missing', () => {
+    mockGet.mockReturnValueOnce(undefined); // firstName
+    mockGet.mockReturnValueOnce(undefined); // lastName
+    mockGet.mockReturnValueOnce(undefined); // username
+    mockGet.mockReturnValueOnce(undefined); // email
+    mockGet.mockReturnValueOnce('Jane Fullname'); // name
+    const result = getDisplayName(mergedMappings, user);
+    expect(result).toBe('Jane Fullname');
+  });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
it('returns username when no firstName or lastName', () => {
mockGet.mockReturnValueOnce(undefined);
mockGet.mockReturnValueOnce(undefined);
mockGet.mockReturnValueOnce('janedoe');
const result = getDisplayName(mergedMappings, user);
expect(result).toBe('janedoe');
});
it('returns email when no firstName lastName or username', () => {
mockGet.mockReturnValueOnce(undefined);
mockGet.mockReturnValueOnce(undefined);
mockGet.mockReturnValueOnce(undefined);
mockGet.mockReturnValueOnce('jane@example.com');
const result = getDisplayName(mergedMappings, user);
expect(result).toBe('jane@example.com');
it('returns username when no firstName or lastName', () => {
mockGet.mockReturnValueOnce(undefined);
mockGet.mockReturnValueOnce(undefined);
mockGet.mockReturnValueOnce('janedoe');
const result = getDisplayName(mergedMappings, user);
expect(result).toBe('janedoe');
});
it('returns email when no firstName lastName or username', () => {
mockGet.mockReturnValueOnce(undefined);
mockGet.mockReturnValueOnce(undefined);
mockGet.mockReturnValueOnce(undefined);
mockGet.mockReturnValueOnce('jane@example.com');
const result = getDisplayName(mergedMappings, user);
expect(result).toBe('jane@example.com');
});
it('returns name when firstName, lastName, username, and email are missing', () => {
mockGet.mockReturnValueOnce(undefined); // firstName
mockGet.mockReturnValueOnce(undefined); // lastName
mockGet.mockReturnValueOnce(undefined); // username
mockGet.mockReturnValueOnce(undefined); // email
mockGet.mockReturnValueOnce('Jane Fullname'); // name
const result = getDisplayName(mergedMappings, user);
expect(result).toBe('Jane Fullname');
});
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@packages/vue/src/__tests__/utils/getDisplayName.test.ts` around lines 33 -
47, Add a new unit test to cover the `name` fallback in getDisplayName: in the
test file using the same helpers (`mockGet`, `mergedMappings`, `user`), set
mockGet to return undefined for firstName, lastName, username, and email (four
consecutive mockReturnValueOnce(undefined) calls) and then return a non-empty
string for `name` (e.g., 'Jane Doe'); call getDisplayName(mergedMappings, user)
and assert the result equals that `name` value so the explicit `name` branch in
getDisplayName is exercised.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

chore: add unit test coverage for untested code paths in @asgardeo/vue SDK

1 participant