1 import { ICAL_ATTENDEE_STATUS } from '@proton/shared/lib/calendar/constants';
2 import { getSelfAddressData } from '@proton/shared/lib/calendar/deserialize';
3 import { buildVcalOrganizer } from '@proton/shared/lib/calendar/vcalConverter';
4 import { ADDRESS_RECEIVE, ADDRESS_SEND, ADDRESS_STATUS, ADDRESS_TYPE } from '@proton/shared/lib/constants';
5 import { buildMailTo } from '@proton/shared/lib/helpers/email';
6 import type { Address } from '@proton/shared/lib/interfaces';
8 const buildVcalAttendee = ({
15 partstat?: ICAL_ATTENDEE_STATUS;
18 value: buildMailTo(email),
21 partstat: partstat || ICAL_ATTENDEE_STATUS.NEEDS_ACTION,
26 describe('getSelfAddressData()', () => {
27 const originalAddress = {
29 Email: 'me@proton.me',
31 Status: ADDRESS_STATUS.STATUS_ENABLED,
32 Receive: ADDRESS_RECEIVE.RECEIVE_YES,
33 Send: ADDRESS_SEND.SEND_YES,
34 Type: ADDRESS_TYPE.TYPE_ORIGINAL,
36 const freePmMeAddress = {
37 DisplayName: "It's me",
40 Status: ADDRESS_STATUS.STATUS_ENABLED,
41 Receive: ADDRESS_RECEIVE.RECEIVE_YES,
42 Send: ADDRESS_SEND.SEND_NO,
43 Type: ADDRESS_TYPE.TYPE_PREMIUM,
45 const protonMailAddress = {
46 DisplayName: "It's still me",
47 Email: 'me@protonmail.com',
49 Status: ADDRESS_STATUS.STATUS_ENABLED,
50 Receive: ADDRESS_RECEIVE.RECEIVE_YES,
51 Send: ADDRESS_SEND.SEND_YES,
52 Type: ADDRESS_TYPE.TYPE_ALIAS,
54 const protonMailChAddress = {
55 DisplayName: "It's me in CH",
56 Email: 'me@protonmail.ch',
58 Status: ADDRESS_STATUS.STATUS_ENABLED,
59 Receive: ADDRESS_RECEIVE.RECEIVE_YES,
60 Send: ADDRESS_SEND.SEND_YES,
61 Type: ADDRESS_TYPE.TYPE_ALIAS,
63 const aliasDisabledAddress = {
64 DisplayName: 'Disabled me',
65 Email: 'disabled_alias@protonmail.com',
67 Status: ADDRESS_STATUS.STATUS_DISABLED,
68 Receive: ADDRESS_RECEIVE.RECEIVE_NO,
69 Send: ADDRESS_SEND.SEND_NO,
70 Type: ADDRESS_TYPE.TYPE_ALIAS,
72 const customDomainAddress = {
73 DisplayName: 'Never gonna give you up',
74 Email: 'rick@does.not.give.you.up',
76 Status: ADDRESS_STATUS.STATUS_ENABLED,
77 Receive: ADDRESS_RECEIVE.RECEIVE_YES,
78 Send: ADDRESS_SEND.SEND_YES,
79 Type: ADDRESS_TYPE.TYPE_CUSTOM_DOMAIN,
81 const externalAddress = {
82 DisplayName: 'Much crypto',
83 Email: 'someone_else@else.888',
85 Status: ADDRESS_STATUS.STATUS_ENABLED,
86 Receive: ADDRESS_RECEIVE.RECEIVE_NO,
87 Send: ADDRESS_SEND.SEND_NO,
88 Type: ADDRESS_TYPE.TYPE_EXTERNAL,
101 it('identifies me as an organizer when organizing an event', () => {
102 const organizer = buildVcalOrganizer('me@proton.me');
104 const protonAttendee = buildVcalAttendee({
105 email: 'someone@proton.me',
107 partstat: ICAL_ATTENDEE_STATUS.DECLINED,
109 const externalAttendee = buildVcalAttendee({
110 email: 'someone_else@else.888',
112 partstat: ICAL_ATTENDEE_STATUS.ACCEPTED,
114 const attendees = [protonAttendee, externalAttendee];
116 expect(getSelfAddressData({ organizer, attendees, addresses })).toEqual({
119 selfAddress: originalAddress,
123 it('does not identify me as an organizer when organizing an event with an external address', () => {
124 const organizer = buildVcalOrganizer(externalAddress.Email);
126 const protonAttendee = buildVcalAttendee({
127 email: 'someone@proton.me',
129 partstat: ICAL_ATTENDEE_STATUS.DECLINED,
131 const otherAttendee = buildVcalAttendee({
134 partstat: ICAL_ATTENDEE_STATUS.ACCEPTED,
136 const attendees = [protonAttendee, otherAttendee];
138 expect(getSelfAddressData({ organizer, attendees, addresses })).toEqual({
141 selfAddress: undefined,
142 selfAttendee: undefined,
143 selfAttendeeIndex: undefined,
147 it('does not identify me as an attendee when attending an event with an external address', () => {
148 const organizer = buildVcalOrganizer('someone@proton.me');
150 const externalAddressAttendee = buildVcalAttendee({
151 email: externalAddress.Email,
153 partstat: ICAL_ATTENDEE_STATUS.ACCEPTED,
155 const otherAttendee = buildVcalAttendee({
158 partstat: ICAL_ATTENDEE_STATUS.TENTATIVE,
160 const attendees = [externalAddressAttendee, otherAttendee];
162 expect(getSelfAddressData({ organizer, attendees, addresses })).toEqual({
165 selfAddress: undefined,
166 selfAttendee: undefined,
167 selfAttendeeIndex: undefined,
171 describe('identifies me as an attendee when attending an event', () => {
172 const organizer = buildVcalOrganizer('someone@proton.me');
174 it('picks first active answered attendee', () => {
175 const originalAttendee = buildVcalAttendee({
176 email: originalAddress.Email,
177 partstat: ICAL_ATTENDEE_STATUS.NEEDS_ACTION,
179 const freePmMeAttendee = buildVcalAttendee({
180 email: freePmMeAddress.Email,
181 partstat: ICAL_ATTENDEE_STATUS.ACCEPTED,
183 const protonMailAttendee = buildVcalAttendee({
184 email: protonMailAddress.Email,
185 partstat: ICAL_ATTENDEE_STATUS.NEEDS_ACTION,
187 const protonMailChAttendee = buildVcalAttendee({
188 email: protonMailChAddress.Email,
189 partstat: ICAL_ATTENDEE_STATUS.TENTATIVE,
191 const aliasDisabledAttendee = buildVcalAttendee({
192 email: aliasDisabledAddress.Email,
193 partstat: ICAL_ATTENDEE_STATUS.DECLINED,
195 const customDomainAttendee = buildVcalAttendee({
196 email: customDomainAddress.Email,
197 partstat: ICAL_ATTENDEE_STATUS.ACCEPTED,
199 const externalAttendee = buildVcalAttendee({
200 email: externalAddress.Email,
201 partstat: ICAL_ATTENDEE_STATUS.ACCEPTED,
209 customDomainAttendee,
211 aliasDisabledAttendee,
214 protonMailChAttendee,
221 selfAddress: protonMailChAddress,
222 selfAttendee: protonMailChAttendee,
223 selfAttendeeIndex: 6,
227 it('picks first active unanswered attendee if only inactive answered', () => {
228 const originalAttendee = buildVcalAttendee({
229 email: originalAddress.Email,
230 partstat: ICAL_ATTENDEE_STATUS.NEEDS_ACTION,
232 const freePmMeAttendee = buildVcalAttendee({
233 email: freePmMeAddress.Email,
234 partstat: ICAL_ATTENDEE_STATUS.ACCEPTED,
236 const protonMailAttendee = buildVcalAttendee({
237 email: protonMailAddress.Email,
238 partstat: ICAL_ATTENDEE_STATUS.NEEDS_ACTION,
240 const protonMailChAttendee = buildVcalAttendee({
241 email: protonMailChAddress.Email,
242 partstat: ICAL_ATTENDEE_STATUS.NEEDS_ACTION,
244 const aliasDisabledAttendee = buildVcalAttendee({
245 email: aliasDisabledAddress.Email,
246 partstat: ICAL_ATTENDEE_STATUS.ACCEPTED,
248 const customDomainAttendee = buildVcalAttendee({
249 email: customDomainAddress.Email,
250 partstat: ICAL_ATTENDEE_STATUS.NEEDS_ACTION,
252 const externalAttendee = buildVcalAttendee({
253 email: externalAddress.Email,
254 partstat: ICAL_ATTENDEE_STATUS.ACCEPTED,
262 customDomainAttendee,
264 aliasDisabledAttendee,
267 protonMailChAttendee,
274 selfAddress: originalAddress,
275 selfAttendee: originalAttendee,
276 selfAttendeeIndex: 4,
280 it('picks first inactive answered attendee if all inactive', () => {
281 const freePmMeAttendee = buildVcalAttendee({
282 email: freePmMeAddress.Email,
283 partstat: ICAL_ATTENDEE_STATUS.NEEDS_ACTION,
285 const aliasDisabledAttendee = buildVcalAttendee({
286 email: aliasDisabledAddress.Email,
287 partstat: ICAL_ATTENDEE_STATUS.DECLINED,
289 const externalAttendee = buildVcalAttendee({
290 email: externalAddress.Email,
291 partstat: ICAL_ATTENDEE_STATUS.ACCEPTED,
297 attendees: [externalAttendee, freePmMeAttendee, aliasDisabledAttendee],
303 selfAddress: aliasDisabledAddress,
304 selfAttendee: aliasDisabledAttendee,
305 selfAttendeeIndex: 2,
310 it('identifies me as an attendee when using a pm.me address', () => {
311 const organizer = buildVcalOrganizer('other@proton.me');
313 const anotherAttendee = buildVcalAttendee({ email: 'another@not_proton.me', cn: 'external' });
314 const pmMeAttendee = buildVcalAttendee({
317 partstat: ICAL_ATTENDEE_STATUS.ACCEPTED,
319 const attendees = [anotherAttendee, pmMeAttendee];
321 const originalAddress = {
323 Email: 'me@proton.me',
325 Receive: ADDRESS_RECEIVE.RECEIVE_YES,
326 Send: ADDRESS_SEND.SEND_YES,
327 Type: ADDRESS_TYPE.TYPE_ORIGINAL,
329 const pmMeAddress = {
330 DisplayName: "It's me",
333 Receive: ADDRESS_RECEIVE.RECEIVE_YES,
334 Send: ADDRESS_SEND.SEND_NO,
335 Type: ADDRESS_TYPE.TYPE_PREMIUM,
337 const addresses = [originalAddress, pmMeAddress];
339 expect(getSelfAddressData({ organizer, attendees, addresses })).toEqual({
342 selfAttendee: pmMeAttendee,
343 selfAddress: pmMeAddress,
344 selfAttendeeIndex: 1,