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 = {
11 planIDs: { [PLANS.MAIL_BUSINESS]: 1, [ADDON_NAMES.MEMBER_SCRIBE_MAIL_BUSINESS]: 1 },
12 step: SUBSCRIPTION_STEPS.CHECKOUT,
13 disablePlanSelection: true,
14 upsellRef: 'upsellRef',
20 describe('getAssistantUpsellConfig', () => {
21 it('should return undefined if the user is a sub user', () => {
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);
32 it('should return paid config with yearly and monthly cycles if the user is paid with monthly billing', () => {
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({
41 step: SUBSCRIPTION_STEPS.CHECKOUT,
43 maximumCycle: CYCLE.YEARLY,
44 minimumCycle: CYCLE.MONTHLY,
48 it('should return paid config with only yearly cycle if the user is paid with yearly billing', () => {
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({
58 step: SUBSCRIPTION_STEPS.CHECKOUT,
60 maximumCycle: CYCLE.YEARLY,
61 minimumCycle: CYCLE.YEARLY,
65 it('should return paid config with only two years if the user is paid with two years billing', () => {
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({
76 step: SUBSCRIPTION_STEPS.CHECKOUT,
77 cycle: CYCLE.TWO_YEARS,
78 maximumCycle: CYCLE.TWO_YEARS,
79 minimumCycle: CYCLE.TWO_YEARS,
83 it('should return multi config with max members if the user has member but no MaxAI', () => {
86 } as unknown as UserModel;
88 const selectedPlan = new SelectedPlan(
91 [ADDON_NAMES.MEMBER_MAIL_PRO]: 4,
98 const config = getAssistantUpsellConfig('upsellRef', user, true, selectedPlan);
100 expect(config).toEqual({
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,
110 it('should return multi config with max AI if the user has member and MaxAI', () => {
113 } as unknown as UserModel;
115 const selectedPlan = new SelectedPlan(
118 [ADDON_NAMES.MEMBER_MAIL_PRO]: 4,
119 [ADDON_NAMES.MEMBER_SCRIBE_MAIL_PRO]: 2,
126 const config = getAssistantUpsellConfig('upsellRef', user, true, selectedPlan);
128 expect(config).toEqual({
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,
138 it('should return multi config with all existing if the user has member and MaxAI', () => {
141 } as unknown as UserModel;
143 const selectedPlan = new SelectedPlan(
146 [ADDON_NAMES.IP_VPN_BUSINESS]: 2,
147 [ADDON_NAMES.MEMBER_MAIL_PRO]: 4,
148 [ADDON_NAMES.MEMBER_SCRIBE_MAIL_PRO]: 2,
155 const config = getAssistantUpsellConfig('upsellRef', user, true, selectedPlan);
157 expect(config).toEqual({
159 step: SUBSCRIPTION_STEPS.CHECKOUT,
160 cycle: CYCLE.TWO_YEARS,
163 [ADDON_NAMES.MEMBER_MAIL_PRO]: 4,
164 [ADDON_NAMES.IP_VPN_BUSINESS]: 2,
165 [ADDON_NAMES.MEMBER_SCRIBE_MAIL_PRO]: 2,
167 maximumCycle: CYCLE.TWO_YEARS,
168 minimumCycle: CYCLE.TWO_YEARS,