1 import { generateAttendeeToken, getAttendeeEmail } from '../../lib/calendar/attendees';
2 import { parse } from '../../lib/calendar/vcal';
4 const expectedToken = 'c2d3d0b4eb4ef80633f9cc7755991e79ca033016';
6 describe('generateAttendeeToken()', () => {
7 it('should produce correct tokens', async () => {
8 const token = await generateAttendeeToken('james@mi6.org', 'uid@proton.me');
9 expect(token).toBe(expectedToken);
13 describe('getAttendeeEmail()', () => {
14 it('should prioritize the attendee value', async () => {
15 const ics = `BEGIN:VEVENT
16 ATTENDEE;CN=email2@test.com;EMAIL=email3@test.com;PARTSTAT=NEEDS-ACTION;ROLE=REQ-PARTICIPANT:mailto:email@test.com
18 const { attendee } = parse(ics);
19 const email = await getAttendeeEmail(attendee[0]);
20 expect(email).toBe('email@test.com');
23 it('should prioritize the email value if attendee value is not an email', async () => {
24 const ics = `BEGIN:VEVENT
25 ATTENDEE;CN=email2@test.com;EMAIL=email3@test.com;PARTSTAT=NEEDS-ACTION;ROLE=REQ-PARTICIPANT:IAmNotAnEmail
27 const { attendee } = parse(ics);
28 const email = await getAttendeeEmail(attendee[0]);
29 expect(email).toBe('email3@test.com');
32 it('should return cn value if attendee and email values are not emails', async () => {
33 const ics = `BEGIN:VEVENT
34 ATTENDEE;CN=email2@test.com;EMAIL=IAmNotAnEmailEither;PARTSTAT=NEEDS-ACTION;ROLE=REQ-PARTICIPANT:IAmNotAnEmail
36 const { attendee } = parse(ics);
37 const email = await getAttendeeEmail(attendee[0]);
38 expect(email).toBe('email2@test.com');
41 it('should fall back to the attendee value if attendee, cn and email values are not emails', async () => {
42 const ics = `BEGIN:VEVENT
43 ATTENDEE;CN=IAmNotAnEmailEither;EMAIL=NoEmailToBeFound;PARTSTAT=NEEDS-ACTION;ROLE=REQ-PARTICIPANT:IAmNotAnEmail
45 const { attendee } = parse(ics);
46 const email = await getAttendeeEmail(attendee[0]);
47 expect(email).toBe('IAmNotAnEmail');