File size: 1,902 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import {
	getPlan,
	TERM_ANNUALLY,
	TERM_BIENNIALLY,
	TERM_MONTHLY,
} from '@automattic/calypso-products';
import { getSitePlan } from 'calypso/state/sites/selectors';
import getCurrentPlanTerm from '../get-current-plan-term';

jest.mock( 'calypso/state/sites/selectors', () => ( {
	getSitePlan: jest.fn( () => ( {} ) ),
} ) );

jest.mock( '@automattic/calypso-products', () => ( {
	...jest.requireActual( '@automattic/calypso-products' ),
	getPlan: jest.fn( () => ( {} ) ),
} ) );

describe( 'getCurrentPlanTerm', () => {
	const state = {};

	beforeEach( () => {
		getPlan.mockReset();
		getSitePlan.mockImplementation( () => ( {} ) );
	} );

	test( 'should return 2-year intervalType if current plan is a 2-year plan', () => {
		getPlan.mockImplementation( () => ( {
			term: TERM_BIENNIALLY,
		} ) );
		const result = getCurrentPlanTerm( state, {} );
		expect( result ).toBe( TERM_BIENNIALLY );
	} );

	test( 'should return 1-year intervalType if current plan is a 1-year plan', () => {
		getPlan.mockImplementation( () => ( {
			term: TERM_ANNUALLY,
		} ) );
		const result = getCurrentPlanTerm( state, {} );
		expect( result ).toBe( TERM_ANNUALLY );
	} );

	test( 'should return monthly intervalType if current plan is a monthly plan', () => {
		getPlan.mockImplementation( () => ( {
			term: TERM_MONTHLY,
		} ) );
		const result = getCurrentPlanTerm( state, {} );
		expect( result ).toBe( TERM_MONTHLY );
	} );

	test( 'should return null intervalType if no product can be identified', () => {
		getSitePlan.mockImplementation( () => null );
		const result = getCurrentPlanTerm( state, {} );
		expect( result ).toBeNull();
	} );

	test( 'should return null intervalType if no plan can be identified', () => {
		getSitePlan.mockImplementation( () => ( {} ) );
		getPlan.mockImplementation( () => null );
		const result = getCurrentPlanTerm( state, {} );
		expect( result ).toBeNull();
	} );
} );