import { describe, expect, it } from 'vitest' import { isUuidLike, resolveParticipantDisplayName, } from './resolveParticipantDisplayName' describe('isUuidLike', () => { it('returns true for standard UUID strings', () => { expect(isUuidLike('a1b2c3d4-e5f6-4789-a012-3456789abcde')).toBe(true) }) it('returns false for regular display names', () => { expect(isUuidLike('Alice')).toBe(false) }) }) describe('resolveParticipantDisplayName', () => { it('returns a valid name when present', () => { expect( resolveParticipantDisplayName({ id: 'user-1', name: 'Alice', username: 'alice', }) ).toBe('Alice') }) it('prefers username when name is missing', () => { expect( resolveParticipantDisplayName({ id: 'user-1', username: 'alice', }) ).toBe('alice') }) it('prefers username when name is UUID-like', () => { expect( resolveParticipantDisplayName({ id: 'user-1', name: 'a1b2c3d4-e5f6-4789-a012-3456789abcde', username: 'alice', }) ).toBe('alice') }) it('never falls back to user id', () => { expect( resolveParticipantDisplayName({ id: 'opaque-user-id', name: 'opaque-user-id', }) ).toBe('Unknown member') }) it('treats the `Follower ` placeholder name as missing', () => { expect( resolveParticipantDisplayName({ id: 'opaque-user-id', name: 'Follower opaque-user-id', }) ).toBe('Unknown member') }) it('falls back to username when the name is the `Follower ` placeholder', () => { expect( resolveParticipantDisplayName({ id: 'opaque-user-id', name: 'Follower opaque-user-id', username: 'alice', }) ).toBe('alice') }) it('does not treat a real name beginning with "Follower" as the placeholder', () => { expect( resolveParticipantDisplayName({ id: 'opaque-user-id', name: 'Follower of Jesus', }) ).toBe('Follower of Jesus') }) it('returns Unknown member when no usable fields exist', () => { expect(resolveParticipantDisplayName({ id: 'user-1' })).toBe( 'Unknown member' ) expect(resolveParticipantDisplayName(undefined)).toBe('Unknown member') }) it('ignores whitespace-only values', () => { expect( resolveParticipantDisplayName({ id: 'user-1', name: ' ', username: 'alice', }) ).toBe('alice') }) })