Cleanup - unused files / unused exports / duplicate exports
[ProtonMail-WebClient.git] / packages / components / containers / payments / helper.test.ts
blobc052f983b1d505b52da8510ee1db59126565befe
1 import type { PlanIDs } from '@proton/payments';
2 import { CYCLE } from '@proton/shared/lib/constants';
3 import { getPlanIDs } from '@proton/shared/lib/helpers/subscription';
4 import { getSubscriptionMock } from '@proton/testing/data';
6 import { isSubscriptionUnchanged } from './helper';
8 describe('isSubscriptionUnchanged', () => {
9     it('returns true when subscription and planIds are deeply equal', () => {
10         const subscription = getSubscriptionMock();
11         const planIds: PlanIDs = getPlanIDs(subscription); // Assuming getPlanIDs is a function that extracts plan IDs from a subscription
13         const result = isSubscriptionUnchanged(subscription, planIds);
14         expect(result).toBe(true);
15     });
17     it('returns false when subscription and planIds are not deeply equal', () => {
18         const subscription = getSubscriptionMock();
19         const planIds: PlanIDs = {
20             mail2022: 1,
21         };
23         const result = isSubscriptionUnchanged(subscription, planIds);
24         expect(result).toBe(false);
25     });
27     it('returns true when both subscription and planIds are empty', () => {
28         const result = isSubscriptionUnchanged(null, {});
29         expect(result).toBe(true);
30     });
32     it('returns false when subscription is null and planIds is not null', () => {
33         const planIds: PlanIDs = {
34             bundle2022: 1,
35         };
37         const result = isSubscriptionUnchanged(null, planIds);
38         expect(result).toBe(false);
39     });
41     it('returns false when subscription is not null and planIds is null', () => {
42         const subscription = getSubscriptionMock();
44         const result = isSubscriptionUnchanged(subscription, null as any);
45         expect(result).toBe(false);
46     });
48     it('should return true when cycle is the same as in the subscription', () => {
49         const subscription = getSubscriptionMock();
50         subscription.Cycle = CYCLE.MONTHLY;
52         const planIds: PlanIDs = getPlanIDs(subscription);
54         const result = isSubscriptionUnchanged(subscription, planIds, CYCLE.MONTHLY);
55         expect(result).toBe(true);
56     });
58     it('should return false when cycle is different from the subscription', () => {
59         const subscription = getSubscriptionMock();
60         subscription.Cycle = CYCLE.MONTHLY;
62         const planIds: PlanIDs = getPlanIDs(subscription);
64         const result = isSubscriptionUnchanged(subscription, planIds, CYCLE.YEARLY);
65         expect(result).toBe(false);
66     });
68     it('should return true if the upcoming subscription unchanged', () => {
69         const subscription = getSubscriptionMock();
70         subscription.Cycle = CYCLE.MONTHLY;
71         subscription.UpcomingSubscription = getSubscriptionMock();
72         subscription.UpcomingSubscription.Cycle = CYCLE.YEARLY;
74         const planIds: PlanIDs = getPlanIDs(subscription);
76         const currentSubscriptionUnchanged = isSubscriptionUnchanged(subscription, planIds, CYCLE.MONTHLY);
77         expect(currentSubscriptionUnchanged).toBe(true);
79         const upcomingSubscriptionUnchanged = isSubscriptionUnchanged(subscription, planIds, CYCLE.YEARLY);
80         expect(upcomingSubscriptionUnchanged).toBe(true);
81     });
83     it('should return false if there is no upcoming subscription', () => {
84         const subscription = getSubscriptionMock();
85         subscription.Cycle = CYCLE.MONTHLY;
87         const planIds: PlanIDs = getPlanIDs(subscription);
89         const currentSubscriptionUnchanged = isSubscriptionUnchanged(subscription, planIds, CYCLE.MONTHLY);
90         expect(currentSubscriptionUnchanged).toBe(true);
92         const upcomingSubscriptionUnchangedYearly = isSubscriptionUnchanged(subscription, planIds, CYCLE.YEARLY);
93         expect(upcomingSubscriptionUnchangedYearly).toBe(false);
95         const upcomingSubscriptionUnchangedTwoYears = isSubscriptionUnchanged(subscription, planIds, CYCLE.TWO_YEARS);
96         expect(upcomingSubscriptionUnchangedTwoYears).toBe(false);
97     });
98 });