1 import { ChargebeeEnabled } from '@proton/shared/lib/interfaces';
3 import { isChargebeeEnabled } from './PaymentSwitcher';
5 describe('isChargebeeEnabled', () => {
6 const mockGetUser = jest.fn();
12 it.each([ChargebeeEnabled.CHARGEBEE_ALLOWED, ChargebeeEnabled.CHARGEBEE_FORCED, ChargebeeEnabled.INHOUSE_FORCED])(
13 'returns chargebeeUser when user is logged in %s',
14 async (ChargebeeUser) => {
15 mockGetUser.mockResolvedValue({ ChargebeeUser });
16 const { result } = await isChargebeeEnabled('UID', mockGetUser, false);
17 expect(result).toEqual(ChargebeeUser);
21 it('returns CHARGEBEE_FORCED when user is not logged in', async () => {
22 const { result } = await isChargebeeEnabled(undefined, mockGetUser, false);
23 expect(result).toEqual(ChargebeeEnabled.CHARGEBEE_FORCED);
26 it('returns CHARGEBEE_FORCED when user is logged in and ChargebeeUser is CHARGEBEE_FORCED', async () => {
27 mockGetUser.mockResolvedValue({ ChargebeeUser: ChargebeeEnabled.CHARGEBEE_FORCED });
28 const { result } = await isChargebeeEnabled('UID', mockGetUser, false);
29 expect(result).toEqual(ChargebeeEnabled.CHARGEBEE_FORCED);
32 it('returns INHOUSE_FORCED when user is logged in and ChargebeeUser is INHOUSE_FORCED', async () => {
33 mockGetUser.mockResolvedValue({ ChargebeeUser: ChargebeeEnabled.INHOUSE_FORCED });
34 const { result } = await isChargebeeEnabled('UID', mockGetUser, false);
35 expect(result).toEqual(ChargebeeEnabled.INHOUSE_FORCED);
38 it('returns INHOUSE_FORCED when user is logged in and isAccountLite is true', async () => {
39 mockGetUser.mockResolvedValue({ ChargebeeUser: ChargebeeEnabled.CHARGEBEE_ALLOWED });
40 const { result } = await isChargebeeEnabled('UID', mockGetUser, true);
41 expect(result).toEqual(ChargebeeEnabled.INHOUSE_FORCED);
43 it('returns CHARGEBEE_FORCED when user is not logged in and isAccountLite is true', async () => {
44 const { result } = await isChargebeeEnabled(undefined, mockGetUser, true);
45 expect(result).toEqual(ChargebeeEnabled.CHARGEBEE_FORCED);
48 it('returns CHARGEBEE_FORCED when user is CHARGEBEE_FORCED and the app is AccountLite', async () => {
49 mockGetUser.mockResolvedValue({ ChargebeeUser: ChargebeeEnabled.CHARGEBEE_FORCED });
50 const { result } = await isChargebeeEnabled('UID', mockGetUser, true);
51 expect(result).toEqual(ChargebeeEnabled.CHARGEBEE_FORCED);