1 import { subDays } from 'date-fns';
3 import { APPS } from '@proton/shared/lib/constants';
4 import type { ProtonConfig, UserModel } from '@proton/shared/lib/interfaces';
6 import isEligible from './eligibility';
8 const now = new Date();
9 const fourteenDaysAgo = subDays(now, 14).getTime() / 1000;
10 const ninetyDaysAgo = subDays(now, 90).getTime() / 1000;
11 const oneHundreadEightyDaysAgo = subDays(now, 180).getTime() / 1000;
14 APP_NAME: APPS.PROTONMAIL,
15 } as unknown as ProtonConfig;
17 describe('Subscription reminder eligibility', () => {
18 it('should return false if the user is just created', () => {
22 CreateTime: now.getTime() / 1000,
23 } as unknown as UserModel;
25 expect(isEligible({ user, protonConfig: mailConfig, lastReminderTimestamp: undefined, isVisited: false })).toBe(
30 it('should return true if user is older than 14 days and hasnt seen the offer', () => {
34 CreateTime: fourteenDaysAgo,
35 } as unknown as UserModel;
37 expect(isEligible({ user, protonConfig: mailConfig, lastReminderTimestamp: undefined, isVisited: false })).toBe(
42 it('should return false if user is older than 14 days and has seen the offer', () => {
46 CreateTime: fourteenDaysAgo,
47 } as unknown as UserModel;
49 expect(isEligible({ user, protonConfig: mailConfig, lastReminderTimestamp: undefined, isVisited: true })).toBe(
54 it('should return true if user is older than 180 days and has seen the offer', () => {
58 CreateTime: ninetyDaysAgo,
59 } as unknown as UserModel;
61 expect(isEligible({ user, protonConfig: mailConfig, lastReminderTimestamp: undefined, isVisited: true })).toBe(
66 it('should return true if user is older than 360 days and has seen the offer 180 days ago', () => {
70 CreateTime: oneHundreadEightyDaysAgo,
71 } as unknown as UserModel;
76 protonConfig: mailConfig,
77 lastReminderTimestamp: ninetyDaysAgo,
83 it('should return false if user is older than 180 days but reminder is 14 days old', () => {
87 CreateTime: ninetyDaysAgo,
88 } as unknown as UserModel;
93 protonConfig: mailConfig,
94 lastReminderTimestamp: fourteenDaysAgo,