2 generateOwnedPersonalCalendars,
3 generateSharedCalendars,
4 generateSubscribedCalendars,
5 } from '@proton/testing/lib/builders';
7 import { getHasUserReachedCalendarsLimit, willUserReachCalendarsLimit } from '../../lib/calendar/calendarLimits';
8 import { MAX_CALENDARS_FREE, MAX_CALENDARS_PAID } from '../../lib/calendar/constants';
10 describe('getHasUserReachedCalendarLimit()', () => {
11 describe('informs whether the calendar limits for a free user have been reached', () => {
15 calendars: generateOwnedPersonalCalendars(MAX_CALENDARS_FREE - 1),
18 isCalendarsLimitReached: false,
19 isOtherCalendarsLimitReached: false,
23 calendars: generateOwnedPersonalCalendars(MAX_CALENDARS_FREE),
26 isCalendarsLimitReached: true,
27 isOtherCalendarsLimitReached: true,
31 calendars: generateOwnedPersonalCalendars(MAX_CALENDARS_FREE + 1),
34 isCalendarsLimitReached: true,
35 isOtherCalendarsLimitReached: true,
40 calendars: generateSharedCalendars(MAX_CALENDARS_FREE - 1),
43 isCalendarsLimitReached: false,
44 isOtherCalendarsLimitReached: true,
48 calendars: generateSharedCalendars(MAX_CALENDARS_FREE),
51 isCalendarsLimitReached: false,
52 isOtherCalendarsLimitReached: true,
56 calendars: generateSharedCalendars(MAX_CALENDARS_FREE + 1),
59 isCalendarsLimitReached: false,
60 isOtherCalendarsLimitReached: true,
63 // subscribed calendars
65 calendars: generateSubscribedCalendars(MAX_CALENDARS_FREE - 1),
68 isCalendarsLimitReached: false,
69 isOtherCalendarsLimitReached: true,
73 calendars: generateSubscribedCalendars(MAX_CALENDARS_FREE),
76 isCalendarsLimitReached: false,
77 isOtherCalendarsLimitReached: true,
81 calendars: generateSubscribedCalendars(MAX_CALENDARS_FREE + 1),
84 isCalendarsLimitReached: false,
85 isOtherCalendarsLimitReached: true,
88 // shared and owned personal
90 calendars: [...generateOwnedPersonalCalendars(1), ...generateSharedCalendars(MAX_CALENDARS_FREE - 1)],
93 isCalendarsLimitReached: true,
94 isOtherCalendarsLimitReached: true,
98 calendars: [...generateOwnedPersonalCalendars(2), ...generateSharedCalendars(MAX_CALENDARS_FREE - 2)],
101 isCalendarsLimitReached: true,
102 isOtherCalendarsLimitReached: true,
106 calendars: [...generateOwnedPersonalCalendars(1), ...generateSharedCalendars(MAX_CALENDARS_FREE)],
109 isCalendarsLimitReached: true,
110 isOtherCalendarsLimitReached: true,
113 // subscribed and owned personal
116 ...generateOwnedPersonalCalendars(1),
117 ...generateSubscribedCalendars(MAX_CALENDARS_FREE - 1),
121 isCalendarsLimitReached: true,
122 isOtherCalendarsLimitReached: true,
127 ...generateOwnedPersonalCalendars(2),
128 ...generateSubscribedCalendars(MAX_CALENDARS_FREE - 2),
132 isCalendarsLimitReached: true,
133 isOtherCalendarsLimitReached: true,
137 calendars: [...generateOwnedPersonalCalendars(1), ...generateSubscribedCalendars(MAX_CALENDARS_FREE)],
140 isCalendarsLimitReached: true,
141 isOtherCalendarsLimitReached: true,
144 // subscribed and shared
146 calendars: [...generateSharedCalendars(1), ...generateSubscribedCalendars(1)],
149 isCalendarsLimitReached: false,
150 isOtherCalendarsLimitReached: true,
154 calendars: [...generateSharedCalendars(1), ...generateSubscribedCalendars(MAX_CALENDARS_FREE - 2)],
157 isCalendarsLimitReached: false,
158 isOtherCalendarsLimitReached: true,
162 calendars: [...generateSharedCalendars(MAX_CALENDARS_FREE - 2), ...generateSubscribedCalendars(1)],
165 isCalendarsLimitReached: false,
166 isOtherCalendarsLimitReached: true,
170 calendars: [...generateSubscribedCalendars(2), ...generateSharedCalendars(MAX_CALENDARS_FREE - 2)],
173 isCalendarsLimitReached: false,
174 isOtherCalendarsLimitReached: true,
178 calendars: [...generateSharedCalendars(1), ...generateSubscribedCalendars(MAX_CALENDARS_FREE)],
181 isCalendarsLimitReached: false,
182 isOtherCalendarsLimitReached: true,
188 ...generateOwnedPersonalCalendars(1),
189 ...generateSharedCalendars(1),
190 ...generateSubscribedCalendars(1),
194 isCalendarsLimitReached: true,
195 isOtherCalendarsLimitReached: true,
200 ...generateOwnedPersonalCalendars(1),
201 ...generateSharedCalendars(2),
202 ...generateSubscribedCalendars(3),
206 isCalendarsLimitReached: true,
207 isOtherCalendarsLimitReached: true,
210 ].forEach(({ calendars, isFreeUser, result }, i) => {
211 it(`is limit reached for case ${i + 1}`, () => {
212 expect(getHasUserReachedCalendarsLimit(calendars, isFreeUser)).toEqual(result);
217 describe('informs whether the calendar limits for a paid user have been reached', () => {
221 calendars: generateOwnedPersonalCalendars(MAX_CALENDARS_PAID - 1),
224 isCalendarsLimitReached: false,
225 isOtherCalendarsLimitReached: false,
229 calendars: generateOwnedPersonalCalendars(MAX_CALENDARS_PAID),
232 isCalendarsLimitReached: true,
233 isOtherCalendarsLimitReached: true,
237 calendars: generateOwnedPersonalCalendars(MAX_CALENDARS_PAID + 1),
240 isCalendarsLimitReached: true,
241 isOtherCalendarsLimitReached: true,
246 calendars: generateSharedCalendars(MAX_CALENDARS_PAID - 1),
249 isCalendarsLimitReached: false,
250 isOtherCalendarsLimitReached: true,
254 calendars: generateSharedCalendars(MAX_CALENDARS_PAID),
257 isCalendarsLimitReached: false,
258 isOtherCalendarsLimitReached: true,
262 calendars: generateSharedCalendars(MAX_CALENDARS_PAID + 1),
265 isCalendarsLimitReached: false,
266 isOtherCalendarsLimitReached: true,
269 // subscribed calendars
271 calendars: generateSubscribedCalendars(MAX_CALENDARS_PAID - 1),
274 isCalendarsLimitReached: false,
275 isOtherCalendarsLimitReached: true,
279 calendars: generateSubscribedCalendars(MAX_CALENDARS_PAID),
282 isCalendarsLimitReached: false,
283 isOtherCalendarsLimitReached: true,
287 calendars: generateSubscribedCalendars(MAX_CALENDARS_PAID + 1),
290 isCalendarsLimitReached: false,
291 isOtherCalendarsLimitReached: true,
294 // shared and owned personal
296 calendars: [...generateOwnedPersonalCalendars(1), ...generateSharedCalendars(MAX_CALENDARS_PAID - 1)],
299 isCalendarsLimitReached: true,
300 isOtherCalendarsLimitReached: true,
304 calendars: [...generateOwnedPersonalCalendars(2), ...generateSharedCalendars(MAX_CALENDARS_PAID - 2)],
307 isCalendarsLimitReached: true,
308 isOtherCalendarsLimitReached: true,
312 calendars: [...generateOwnedPersonalCalendars(1), ...generateSharedCalendars(MAX_CALENDARS_PAID)],
315 isCalendarsLimitReached: true,
316 isOtherCalendarsLimitReached: true,
319 // subscribed and owned personal
322 ...generateOwnedPersonalCalendars(1),
323 ...generateSubscribedCalendars(MAX_CALENDARS_PAID - 1),
327 isCalendarsLimitReached: true,
328 isOtherCalendarsLimitReached: true,
333 ...generateOwnedPersonalCalendars(2),
334 ...generateSubscribedCalendars(MAX_CALENDARS_PAID - 2),
338 isCalendarsLimitReached: true,
339 isOtherCalendarsLimitReached: true,
343 calendars: [...generateOwnedPersonalCalendars(1), ...generateSubscribedCalendars(MAX_CALENDARS_PAID)],
346 isCalendarsLimitReached: true,
347 isOtherCalendarsLimitReached: true,
350 // subscribed and shared
352 calendars: [...generateSharedCalendars(1), ...generateSubscribedCalendars(MAX_CALENDARS_PAID - 3)],
355 isCalendarsLimitReached: false,
356 isOtherCalendarsLimitReached: false,
360 calendars: [...generateSharedCalendars(MAX_CALENDARS_PAID - 3), ...generateSubscribedCalendars(1)],
363 isCalendarsLimitReached: false,
364 isOtherCalendarsLimitReached: false,
368 calendars: [...generateSharedCalendars(1), ...generateSubscribedCalendars(MAX_CALENDARS_PAID - 2)],
371 isCalendarsLimitReached: false,
372 isOtherCalendarsLimitReached: true,
376 calendars: [...generateSharedCalendars(MAX_CALENDARS_PAID - 2), ...generateSubscribedCalendars(1)],
379 isCalendarsLimitReached: false,
380 isOtherCalendarsLimitReached: true,
384 calendars: [...generateSubscribedCalendars(2), ...generateSharedCalendars(MAX_CALENDARS_PAID - 2)],
387 isCalendarsLimitReached: false,
388 isOtherCalendarsLimitReached: true,
392 calendars: [...generateSharedCalendars(1), ...generateSubscribedCalendars(MAX_CALENDARS_PAID)],
395 isCalendarsLimitReached: false,
396 isOtherCalendarsLimitReached: true,
402 ...generateOwnedPersonalCalendars(MAX_CALENDARS_PAID - 5),
403 ...generateSharedCalendars(2),
404 ...generateSubscribedCalendars(2),
408 isCalendarsLimitReached: false,
409 isOtherCalendarsLimitReached: false,
414 ...generateOwnedPersonalCalendars(MAX_CALENDARS_PAID - 5),
415 ...generateSharedCalendars(2),
416 ...generateSubscribedCalendars(3),
420 isCalendarsLimitReached: true,
421 isOtherCalendarsLimitReached: true,
425 calendars: [...generateSharedCalendars(MAX_CALENDARS_PAID - 3), ...generateSubscribedCalendars(2)],
428 isCalendarsLimitReached: false,
429 isOtherCalendarsLimitReached: true,
432 ].forEach(({ calendars, isFreeUser, result }, i) => {
433 it(`is limit reached for case ${i + 1}`, () => {
434 expect(getHasUserReachedCalendarsLimit(calendars, isFreeUser)).toEqual(result);
440 describe('willUserReachCalendarsLimit()', () => {
441 describe('informs whether the calendar limits for a free user will be reached from easy switch', () => {
446 calendars: generateOwnedPersonalCalendars(MAX_CALENDARS_FREE - 2),
452 calendars: generateOwnedPersonalCalendars(MAX_CALENDARS_FREE),
458 calendars: generateOwnedPersonalCalendars(MAX_CALENDARS_FREE + 1),
465 calendars: generateSharedCalendars(MAX_CALENDARS_FREE - 1),
471 calendars: generateSharedCalendars(MAX_CALENDARS_FREE),
477 calendars: generateSharedCalendars(MAX_CALENDARS_FREE + 1),
481 // subscribed calendars
484 calendars: generateSubscribedCalendars(MAX_CALENDARS_FREE - 1),
490 calendars: generateSubscribedCalendars(MAX_CALENDARS_FREE),
496 calendars: generateSubscribedCalendars(MAX_CALENDARS_FREE + 1),
500 // shared and owned personal
503 calendars: [...generateOwnedPersonalCalendars(1), ...generateSharedCalendars(MAX_CALENDARS_FREE - 1)],
509 calendars: [...generateOwnedPersonalCalendars(2), ...generateSharedCalendars(MAX_CALENDARS_FREE - 2)],
515 calendars: [...generateOwnedPersonalCalendars(1), ...generateSharedCalendars(MAX_CALENDARS_FREE)],
519 // subscribed and owned personal
523 ...generateOwnedPersonalCalendars(1),
524 ...generateSubscribedCalendars(MAX_CALENDARS_FREE - 1),
532 ...generateOwnedPersonalCalendars(2),
533 ...generateSubscribedCalendars(MAX_CALENDARS_FREE - 2),
540 calendars: [...generateOwnedPersonalCalendars(1), ...generateSubscribedCalendars(MAX_CALENDARS_FREE)],
544 // subscribed and shared
547 calendars: [...generateSharedCalendars(1), ...generateSubscribedCalendars(1)],
553 calendars: [...generateSharedCalendars(1), ...generateSubscribedCalendars(MAX_CALENDARS_FREE - 2)],
559 calendars: [...generateSharedCalendars(MAX_CALENDARS_FREE - 2), ...generateSubscribedCalendars(1)],
565 calendars: [...generateSubscribedCalendars(2), ...generateSharedCalendars(MAX_CALENDARS_FREE - 2)],
571 calendars: [...generateSharedCalendars(1), ...generateSubscribedCalendars(MAX_CALENDARS_FREE)],
579 ...generateOwnedPersonalCalendars(1),
580 ...generateSharedCalendars(1),
581 ...generateSubscribedCalendars(1),
589 ...generateOwnedPersonalCalendars(1),
590 ...generateSharedCalendars(2),
591 ...generateSubscribedCalendars(3),
596 ].forEach(({ calendars, number, isFreeUser, result }, i) => {
597 it(`is limit reached for case ${i + 1}`, () => {
598 expect(willUserReachCalendarsLimit(calendars, number, isFreeUser)).toEqual(result);
603 describe('informs whether the calendar limits for a paid user was reach from easy switch', () => {
608 calendars: generateOwnedPersonalCalendars(MAX_CALENDARS_PAID - 2),
614 calendars: generateOwnedPersonalCalendars(MAX_CALENDARS_PAID),
620 calendars: generateOwnedPersonalCalendars(MAX_CALENDARS_PAID + 1),
627 calendars: generateSharedCalendars(MAX_CALENDARS_PAID - 1),
633 calendars: generateSharedCalendars(MAX_CALENDARS_PAID),
639 calendars: generateSharedCalendars(MAX_CALENDARS_PAID + 1),
643 // subscribed calendars
646 calendars: generateSubscribedCalendars(MAX_CALENDARS_PAID - 1),
652 calendars: generateSubscribedCalendars(MAX_CALENDARS_PAID),
658 calendars: generateSubscribedCalendars(MAX_CALENDARS_PAID + 1),
662 // shared and owned personal
665 calendars: [...generateOwnedPersonalCalendars(1), ...generateSharedCalendars(MAX_CALENDARS_PAID - 1)],
671 calendars: [...generateOwnedPersonalCalendars(2), ...generateSharedCalendars(MAX_CALENDARS_PAID - 2)],
677 calendars: [...generateOwnedPersonalCalendars(1), ...generateSharedCalendars(MAX_CALENDARS_PAID)],
681 // subscribed and owned personal
684 ...generateOwnedPersonalCalendars(1),
685 ...generateSubscribedCalendars(MAX_CALENDARS_PAID - 1),
693 ...generateOwnedPersonalCalendars(2),
694 ...generateSubscribedCalendars(MAX_CALENDARS_PAID - 2),
702 calendars: [...generateOwnedPersonalCalendars(1), ...generateSubscribedCalendars(MAX_CALENDARS_PAID)],
706 // subscribed and shared
709 calendars: [...generateSharedCalendars(1), ...generateSubscribedCalendars(MAX_CALENDARS_PAID - 3)],
715 calendars: [...generateSharedCalendars(MAX_CALENDARS_PAID - 3), ...generateSubscribedCalendars(1)],
721 calendars: [...generateSharedCalendars(1), ...generateSubscribedCalendars(MAX_CALENDARS_PAID - 2)],
727 calendars: [...generateSharedCalendars(MAX_CALENDARS_PAID - 2), ...generateSubscribedCalendars(1)],
733 calendars: [...generateSubscribedCalendars(2), ...generateSharedCalendars(MAX_CALENDARS_PAID - 2)],
739 calendars: [...generateSharedCalendars(1), ...generateSubscribedCalendars(MAX_CALENDARS_PAID)],
746 ...generateOwnedPersonalCalendars(MAX_CALENDARS_PAID - 6),
747 ...generateSharedCalendars(2),
748 ...generateSubscribedCalendars(2),
756 ...generateOwnedPersonalCalendars(MAX_CALENDARS_PAID - 5),
757 ...generateSharedCalendars(2),
758 ...generateSubscribedCalendars(3),
766 calendars: [...generateSharedCalendars(MAX_CALENDARS_PAID - 3), ...generateSubscribedCalendars(2)],
770 ].forEach(({ calendars, number, isFreeUser, result }, i) => {
771 it(`is limit reached for case ${i + 1}`, () => {
772 expect(willUserReachCalendarsLimit(calendars, number, isFreeUser)).toEqual(result);