File size: 2,545 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
import { DotcomFeatures, HostingFeatures } from '../../data/constants';
import { hasHostingFeature, hasPlanFeature } from '../site-features';
import type { Site } from '../../data/types';

describe( 'hasPlanFeature', () => {
	it( 'should return false if the site does not have active plan', () => {
		const site = {} as Site;
		expect( hasPlanFeature( site, DotcomFeatures.COPY_SITE ) ).toBe( false );
	} );

	it( 'should return false if the plan does not have the feature', () => {
		const site = {
			plan: {
				features: {
					active: [ DotcomFeatures.SUBSCRIPTION_GIFTING ],
				},
			},
		} as Site;
		expect( hasPlanFeature( site, DotcomFeatures.COPY_SITE ) ).toBe( false );
	} );

	it( 'should return true if the plan has the feature', () => {
		const site = {
			plan: {
				features: {
					active: [ DotcomFeatures.COPY_SITE ],
				},
			},
		} as Site;
		expect( hasPlanFeature( site, DotcomFeatures.COPY_SITE ) ).toBe( true );
	} );
} );

describe( 'hasHostingFeature', () => {
	it( 'should return false if the site does not have active plan', () => {
		const site = {} as Site;
		expect( hasHostingFeature( site, HostingFeatures.BACKUPS ) ).toBe( false );
	} );

	it( 'should return false if the plan does not have the feature', () => {
		const site = {
			plan: {
				features: {
					active: [ HostingFeatures.SCAN ],
				},
			},
		} as Site;
		expect( hasHostingFeature( site, HostingFeatures.BACKUPS ) ).toBe( false );
	} );

	it( 'should return false if the site is hosted on WordPress.com but not Atomic yet, even though the plan has the feature', () => {
		const site = {
			plan: {
				features: {
					active: [ DotcomFeatures.ATOMIC, HostingFeatures.BACKUPS ],
				},
			},
			is_wpcom_atomic: false,
		} as Site;
		expect( hasHostingFeature( site, HostingFeatures.BACKUPS ) ).toBe( false );
	} );

	it( 'should return false if site is hosted on WordPress.com, and already Atomic, and the plan has the feature, but the plan already expired', () => {
		const site = {
			plan: {
				features: {
					active: [ DotcomFeatures.ATOMIC, HostingFeatures.BACKUPS ],
				},
				expired: true,
			},
			is_wpcom_atomic: true,
		} as Site;
		expect( hasHostingFeature( site, HostingFeatures.BACKUPS ) ).toBe( false );
	} );

	it( 'should return true if site is not hosted on WordPress.com, and the plan has the feature', () => {
		const site = {
			plan: {
				features: {
					active: [ HostingFeatures.BACKUPS ],
				},
			},
		} as Site;
		expect( hasHostingFeature( site, HostingFeatures.BACKUPS ) ).toBe( true );
	} );
} );