Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions packages/vue/src/__tests__/utils/getDisplayName.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import { describe, it, expect, vi, beforeEach } from 'vitest';
import getDisplayName from '../../utils/getDisplayName';

vi.mock('../../utils/getMappedUserProfileValue', () => ({
default: vi.fn(),
}));

import getMappedUserProfileValue from '../../utils/getMappedUserProfileValue';

const mockGet = getMappedUserProfileValue as ReturnType<typeof vi.fn>;

describe('getDisplayName', () => {
const mergedMappings = {};
const user = {} as any;

beforeEach(() => {
mockGet.mockReset();
});

it('returns User when nothing is found', () => {
mockGet.mockReturnValue(undefined);
const result = getDisplayName(mergedMappings, user);
expect(result).toBe('User');
});

it('returns firstName and lastName combined', () => {
mockGet.mockReturnValueOnce('Jane');
mockGet.mockReturnValueOnce('Doe');
const result = getDisplayName(mergedMappings, user);
expect(result).toBe('Jane Doe');
});

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');
Comment on lines +33 to +47

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.

});

it('returns value from displayAttributes when found', () => {
mockGet.mockReturnValueOnce('John');
const result = getDisplayName(mergedMappings, user, ['firstName']);
expect(result).toBe('John');
});

it('skips empty displayAttributes and uses firstName and lastName', () => {
mockGet.mockReturnValueOnce('Jane');
mockGet.mockReturnValueOnce('Doe');
const result = getDisplayName(mergedMappings, user, []);
expect(result).toBe('Jane Doe');
});
});