File size: 2,795 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import { setPlans, setFeaturesByType, setFeatures, setPlanProducts } from '../actions';
import * as MockData from '../mock';
import reducer from '../reducer';
import { buildPlanFeaturesDict } from '../test-utils';

const MOCK_LOCALE = 'test-locale';

describe( 'Plans reducer', () => {
	describe( 'plans', () => {
		it( 'should default to no plans info', () => {
			const { plans } = reducer( undefined, { type: 'NOOP' } );
			expect( plans ).toEqual( {} );
		} );

		it( 'should replace old plans with new plans', () => {
			let state = reducer( undefined, setPlans( [ MockData.STORE_PLAN_FREE ], MOCK_LOCALE ) );

			state = reducer(
				state,
				setPlanProducts( [
					MockData.STORE_PRODUCT_FREE,
					MockData.STORE_PRODUCT_PREMIUM_ANNUALLY,
					MockData.STORE_PRODUCT_PREMIUM_MONTHLY,
				] )
			);

			const newFreePlan = { ...MockData.STORE_PLAN_FREE, title: 'new free' };

			const { plans } = reducer( state, setPlans( [ newFreePlan ], MOCK_LOCALE ) );

			expect( plans[ MOCK_LOCALE ][ 0 ].title ).toBe( newFreePlan.title );
			expect( plans[ MOCK_LOCALE ][ 1 ] ).toBeUndefined();
		} );
	} );

	describe( 'featuresByType', () => {
		it( 'should default to no featuresByType info', () => {
			const { featuresByType } = reducer( undefined, { type: 'NOOP' } );
			expect( featuresByType ).toEqual( {} );
		} );

		it( 'should replace old featuresByType info with new featuresByType info', () => {
			const state = reducer(
				undefined,
				setFeaturesByType(
					[ MockData.API_FEATURES_BY_TYPE_GENERAL, MockData.API_FEATURES_BY_TYPE_COMMERCE ],
					MOCK_LOCALE
				)
			);

			const { featuresByType } = reducer(
				state,
				setFeaturesByType( [ MockData.API_FEATURES_BY_TYPE_MARKETING ], MOCK_LOCALE )
			);

			expect( featuresByType[ MOCK_LOCALE ] ).toEqual( [
				MockData.API_FEATURES_BY_TYPE_MARKETING,
			] );
		} );
	} );

	describe( 'features', () => {
		it( 'should default to no feature info', () => {
			const { features } = reducer( undefined, { type: 'NOOP' } );
			expect( features ).toEqual( {} );
		} );

		it( 'should replace old features with new features', () => {
			const state = reducer(
				undefined,
				setFeatures(
					buildPlanFeaturesDict( [
						MockData.STORE_PLAN_FEATURE_CUSTOM_DOMAIN,
						MockData.STORE_PLAN_FEATURE_LIVE_SUPPORT,
					] ),
					MOCK_LOCALE
				)
			);

			const { features } = reducer(
				state,
				setFeatures(
					buildPlanFeaturesDict( [ MockData.STORE_PLAN_FEATURE_PRIORITY_SUPPORT ] ),
					MOCK_LOCALE
				)
			);

			expect(
				features[ MOCK_LOCALE ][ MockData.STORE_PLAN_FEATURE_PRIORITY_SUPPORT.id ].name
			).toBe( MockData.STORE_SIMPLIFIED_FEATURE_PRIORITY_SUPPORT.name );
			expect(
				features[ MOCK_LOCALE ][ MockData.STORE_PLAN_FEATURE_CUSTOM_DOMAIN.id ]
			).toBeUndefined();
		} );
	} );
} );