|
| 1 | +import {normalizeAttendee, normalizeAttendees} from '@libs/AttendeeUtils'; |
| 2 | +import type {Attendee} from '@src/types/onyx/IOU'; |
| 3 | + |
| 4 | +describe('AttendeeUtils', () => { |
| 5 | + describe('normalizeAttendee', () => { |
| 6 | + it('should trim email and omit it when blank', () => { |
| 7 | + const attendee: Attendee = { |
| 8 | + email: ' ', |
| 9 | + displayName: ' John Smith ', |
| 10 | + avatarUrl: '', |
| 11 | + login: ' john@example.com ', |
| 12 | + }; |
| 13 | + |
| 14 | + const result = normalizeAttendee(attendee); |
| 15 | + |
| 16 | + expect(result).toEqual({ |
| 17 | + displayName: 'John Smith', |
| 18 | + avatarUrl: '', |
| 19 | + login: 'john@example.com', |
| 20 | + }); |
| 21 | + }); |
| 22 | + |
| 23 | + it('should fall back to login when displayName and email are missing', () => { |
| 24 | + const attendee: Attendee = { |
| 25 | + displayName: ' ', |
| 26 | + avatarUrl: '', |
| 27 | + login: ' login-only@example.com ', |
| 28 | + }; |
| 29 | + |
| 30 | + const result = normalizeAttendee(attendee); |
| 31 | + |
| 32 | + expect(result).toEqual({ |
| 33 | + displayName: 'login-only@example.com', |
| 34 | + avatarUrl: '', |
| 35 | + login: 'login-only@example.com', |
| 36 | + }); |
| 37 | + }); |
| 38 | + |
| 39 | + it('should use normalized email as the display name when displayName is missing', () => { |
| 40 | + const attendee: Attendee = { |
| 41 | + email: ' attendee@example.com ', |
| 42 | + displayName: ' ', |
| 43 | + avatarUrl: '', |
| 44 | + }; |
| 45 | + |
| 46 | + const result = normalizeAttendee(attendee); |
| 47 | + |
| 48 | + expect(result).toEqual({ |
| 49 | + email: 'attendee@example.com', |
| 50 | + displayName: 'attendee@example.com', |
| 51 | + avatarUrl: '', |
| 52 | + login: undefined, |
| 53 | + }); |
| 54 | + }); |
| 55 | + }); |
| 56 | + |
| 57 | + describe('normalizeAttendees', () => { |
| 58 | + it('should return an empty array when attendees are undefined', () => { |
| 59 | + expect(normalizeAttendees(undefined)).toEqual([]); |
| 60 | + }); |
| 61 | + |
| 62 | + it('should normalize each attendee in the list', () => { |
| 63 | + const attendees: Attendee[] = [ |
| 64 | + {email: ' one@example.com ', displayName: ' One ', avatarUrl: '', login: ' one@example.com '}, |
| 65 | + {displayName: ' ', avatarUrl: '', login: ' two@example.com '}, |
| 66 | + ]; |
| 67 | + |
| 68 | + expect(normalizeAttendees(attendees)).toEqual([ |
| 69 | + {email: 'one@example.com', displayName: 'One', avatarUrl: '', login: 'one@example.com'}, |
| 70 | + {displayName: 'two@example.com', avatarUrl: '', login: 'two@example.com'}, |
| 71 | + ]); |
| 72 | + }); |
| 73 | + }); |
| 74 | +}); |
0 commit comments