Merge branch 'feat/inda-383-daily-stat' into 'main'
[ProtonMail-WebClient.git] / packages / components / hooks / assistant / assistantUpsellConfig.test.ts
blob64260f8a835596debc648d5792edb694eb5d202d
1 import { SUBSCRIPTION_STEPS } from '@proton/components/containers/payments/subscription/constants';
2 import { ADDON_NAMES, PLANS, SelectedPlan } from '@proton/payments';
3 import { CYCLE } from '@proton/shared/lib/constants';
4 import type { UserModel } from '@proton/shared/lib/interfaces';
5 import { PLANS_MAP } from '@proton/testing/data';
7 import { getAssistantUpsellConfig } from './assistantUpsellConfig';
9 const baseConfig: any = {
10     mode: 'upsell-modal',
11     planIDs: { [PLANS.MAIL_BUSINESS]: 1, [ADDON_NAMES.MEMBER_SCRIBE_MAIL_BUSINESS]: 1 },
12     step: SUBSCRIPTION_STEPS.CHECKOUT,
13     disablePlanSelection: true,
14     upsellRef: 'upsellRef',
15     metrics: {
16         source: 'upsells',
17     },
20 describe('getAssistantUpsellConfig', () => {
21     it('should return undefined if the user is a sub user', () => {
22         const user = {
23             isSubUser: true,
24         } as unknown as UserModel;
25         const selectedPlan = new SelectedPlan({}, PLANS_MAP, CYCLE.MONTHLY, 'EUR');
27         const config = getAssistantUpsellConfig('upsellRef', user, false, selectedPlan);
29         expect(config).toEqual(undefined);
30     });
32     it('should return paid config with yearly and monthly cycles if the user is paid with monthly billing', () => {
33         const user = {
34             isPaid: true,
35         } as unknown as UserModel;
36         const selectedPlan = new SelectedPlan({ [PLANS.MAIL_BUSINESS]: 1 }, PLANS_MAP, CYCLE.MONTHLY, 'EUR');
37         const config = getAssistantUpsellConfig('upsellRef', user, false, selectedPlan);
39         expect(config).toEqual({
40             ...baseConfig,
41             step: SUBSCRIPTION_STEPS.CHECKOUT,
42             cycle: CYCLE.MONTHLY,
43             maximumCycle: CYCLE.YEARLY,
44             minimumCycle: CYCLE.MONTHLY,
45         });
46     });
48     it('should return paid config with only yearly cycle if the user is paid with yearly billing', () => {
49         const user = {
50             isPaid: true,
51         } as unknown as UserModel;
52         const selectedPlan = new SelectedPlan({ [PLANS.MAIL_BUSINESS]: 1 }, PLANS_MAP, CYCLE.YEARLY, 'EUR');
54         const config = getAssistantUpsellConfig('upsellRef', user, false, selectedPlan);
56         expect(config).toEqual({
57             ...baseConfig,
58             step: SUBSCRIPTION_STEPS.CHECKOUT,
59             cycle: CYCLE.YEARLY,
60             maximumCycle: CYCLE.YEARLY,
61             minimumCycle: CYCLE.YEARLY,
62         });
63     });
65     it('should return paid config with only two years if the user is paid with two years billing', () => {
66         const user = {
67             isPaid: true,
68         } as unknown as UserModel;
70         const selectedPlan = new SelectedPlan({ [PLANS.MAIL_BUSINESS]: 1 }, PLANS_MAP, CYCLE.TWO_YEARS, 'EUR');
72         const config = getAssistantUpsellConfig('upsellRef', user, false, selectedPlan);
74         expect(config).toEqual({
75             ...baseConfig,
76             step: SUBSCRIPTION_STEPS.CHECKOUT,
77             cycle: CYCLE.TWO_YEARS,
78             maximumCycle: CYCLE.TWO_YEARS,
79             minimumCycle: CYCLE.TWO_YEARS,
80         });
81     });
83     it('should return multi config with max members if the user has member but no MaxAI', () => {
84         const user = {
85             isPaid: true,
86         } as unknown as UserModel;
88         const selectedPlan = new SelectedPlan(
89             {
90                 [PLANS.MAIL_PRO]: 1,
91                 [ADDON_NAMES.MEMBER_MAIL_PRO]: 4,
92             },
93             PLANS_MAP,
94             CYCLE.TWO_YEARS,
95             'EUR'
96         );
98         const config = getAssistantUpsellConfig('upsellRef', user, true, selectedPlan);
100         expect(config).toEqual({
101             ...baseConfig,
102             step: SUBSCRIPTION_STEPS.CHECKOUT,
103             cycle: CYCLE.TWO_YEARS,
104             planIDs: { [PLANS.MAIL_PRO]: 1, [ADDON_NAMES.MEMBER_MAIL_PRO]: 4, [ADDON_NAMES.MEMBER_SCRIBE_MAIL_PRO]: 5 },
105             maximumCycle: CYCLE.TWO_YEARS,
106             minimumCycle: CYCLE.TWO_YEARS,
107         });
108     });
110     it('should return multi config with max AI if the user has member and MaxAI', () => {
111         const user = {
112             isPaid: true,
113         } as unknown as UserModel;
115         const selectedPlan = new SelectedPlan(
116             {
117                 [PLANS.MAIL_PRO]: 1,
118                 [ADDON_NAMES.MEMBER_MAIL_PRO]: 4,
119                 [ADDON_NAMES.MEMBER_SCRIBE_MAIL_PRO]: 2,
120             },
121             PLANS_MAP,
122             CYCLE.TWO_YEARS,
123             'EUR'
124         );
126         const config = getAssistantUpsellConfig('upsellRef', user, true, selectedPlan);
128         expect(config).toEqual({
129             ...baseConfig,
130             step: SUBSCRIPTION_STEPS.CHECKOUT,
131             cycle: CYCLE.TWO_YEARS,
132             planIDs: { [PLANS.MAIL_PRO]: 1, [ADDON_NAMES.MEMBER_MAIL_PRO]: 4, [ADDON_NAMES.MEMBER_SCRIBE_MAIL_PRO]: 2 },
133             maximumCycle: CYCLE.TWO_YEARS,
134             minimumCycle: CYCLE.TWO_YEARS,
135         });
136     });
138     it('should return multi config with all existing if the user has member and MaxAI', () => {
139         const user = {
140             isPaid: true,
141         } as unknown as UserModel;
143         const selectedPlan = new SelectedPlan(
144             {
145                 [PLANS.MAIL_PRO]: 1,
146                 [ADDON_NAMES.IP_VPN_BUSINESS]: 2,
147                 [ADDON_NAMES.MEMBER_MAIL_PRO]: 4,
148                 [ADDON_NAMES.MEMBER_SCRIBE_MAIL_PRO]: 2,
149             },
150             PLANS_MAP,
151             CYCLE.TWO_YEARS,
152             'EUR'
153         );
155         const config = getAssistantUpsellConfig('upsellRef', user, true, selectedPlan);
157         expect(config).toEqual({
158             ...baseConfig,
159             step: SUBSCRIPTION_STEPS.CHECKOUT,
160             cycle: CYCLE.TWO_YEARS,
161             planIDs: {
162                 [PLANS.MAIL_PRO]: 1,
163                 [ADDON_NAMES.MEMBER_MAIL_PRO]: 4,
164                 [ADDON_NAMES.IP_VPN_BUSINESS]: 2,
165                 [ADDON_NAMES.MEMBER_SCRIBE_MAIL_PRO]: 2,
166             },
167             maximumCycle: CYCLE.TWO_YEARS,
168             minimumCycle: CYCLE.TWO_YEARS,
169         });
170     });