import { describe, expect, it } from 'vitest' import { resolveConversationParticipant } from './resolveConversationParticipant' const OFFICIAL_SENDER_USER_ID = 'linktree-official-sender' const members = { [OFFICIAL_SENDER_USER_ID]: { user: { id: OFFICIAL_SENDER_USER_ID, name: 'Linktree' }, }, 'account-uuid': { user: { id: 'account-uuid', name: 'Jane Linker' } }, } as never describe('resolveConversationParticipant', () => { it('returns the member that is not the current user for a normal channel', () => { const participant = resolveConversationParticipant( members, 'account-uuid', 'messaging' ) expect(participant?.user?.id).toBe(OFFICIAL_SENDER_USER_ID) }) it('returns the official sender for the official channel when the linker views it (member)', () => { const participant = resolveConversationParticipant( members, 'account-uuid', 'linktree-official' ) expect(participant?.user?.name).toBe('Linktree') }) it('returns the official sender for the official channel when a guest views it (non-member)', () => { // A guest's random Stream id isn't a member, so the "not me" heuristic // would otherwise fall back to the linker's member and show their name. const participant = resolveConversationParticipant( members, 'guest-random-uuid-account-uuid', 'linktree-official' ) expect(participant?.user?.name).toBe('Linktree') }) it('falls back to the non-current member when the official sender is absent', () => { const withoutSender = { 'account-uuid': { user: { id: 'account-uuid', name: 'Jane Linker' } }, } as never const participant = resolveConversationParticipant( withoutSender, 'guest-random-uuid', 'linktree-official' ) expect(participant?.user?.id).toBe('account-uuid') }) it('returns undefined when there are no members', () => { expect( resolveConversationParticipant(undefined, 'account-uuid', 'messaging') ).toBeUndefined() }) })