File size: 1,729 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
// @ts-nocheck - TODO: Fix TypeScript issues
import isJetpackBundle from '../is-jetpack-bundle';
import type { APIProductFamilyProduct } from 'calypso/state/partner-portal/types';

const createFakeApiProduct = ( slug: string, family_slug: string ): APIProductFamilyProduct => ( {
	name: '',
	slug,
	product_id: 0,
	currency: '',
	amount: 0,
	price_interval: '',
	family_slug,
} );

describe( 'isJetpackBundle', () => {
	describe( 'string argument', () => {
		it.each( [
			[ 'jetpack-complete' ],
			[ 'jetpack-security-t1' ],
			[ 'jetpack-security-t2' ],
			[ 'jetpack-starter' ],
		] )( 'returns true if value matches a bundle product slug', ( input ) => {
			expect( isJetpackBundle( input ) ).toBe( true );
		} );

		it.each( [
			[ 'jetpack-backup-t1' ],
			[ 'a-random-string' ],
			[ 'jetpack-social-advanced' ],
			[ 'wpcom-business' ],
			[ 'jetpack-complet' ],
		] )( 'returns false if value does not match any bundle product slug', ( input ) => {
			expect( isJetpackBundle( input ) ).toBe( false );
		} );
	} );

	describe( 'APIProductFamilyProduct argument', () => {
		it.each( [
			[ createFakeApiProduct( 'jetpack-complete', 'jetpack-packs' ) ],
			[ createFakeApiProduct( 'literally-any-other-slug', 'jetpack-packs' ) ],
		] )( 'returns true if `family_slug` property is jetpack-packs', ( input ) => {
			expect( isJetpackBundle( input ) ).toBe( true );
		} );

		it.each( [
			[ createFakeApiProduct( 'jetpack-complete', 'literally-any-other-family-slug' ) ],
			[ createFakeApiProduct( 'literally-any-other-slug', 'literally-any-other-family-slug' ) ],
		] )( 'returns false if `family_slug` property is not jetpack-packs', ( input ) => {
			expect( isJetpackBundle( input ) ).toBe( false );
		} );
	} );
} );