File size: 1,151 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
import { getApiPath } from '../get-api';

const config = {
	isEnabled: jest.fn(),
};

describe( 'getApiPath for jetpack/atomic sites', () => {
	beforeAll( () => {
		config.isEnabled.mockReturnValue( true );
	} );
	afterAll( () => {
		jest.clearAllMocks();
	} );
	it( 'should return the passed in jetpackPath', () => {
		config.isEnabled.mockReturnValue( true );
		const jetpackPath = '/jetpack-api';
		const params = { siteId: 123 };

		const result = getApiPath( jetpackPath, params );

		expect( result ).toBe( jetpackPath );
	} );
} );

describe( 'getApiPath for simple sites', () => {
	beforeAll( () => {
		config.isEnabled.mockReturnValue( false );
	} );
	afterAll( () => {
		jest.clearAllMocks();
	} );
	it( '/site/purchases', () => {
		const jetpackPath = '/site/purchases';
		const params = { siteId: 123 };

		const result = getApiPath( jetpackPath, params );

		expect( result ).toBe( `/sites/${ params.siteId }/purchases` );
	} );

	it( '/site', () => {
		const jetpackPath = '/site';
		const params = { siteId: 123 };

		const result = getApiPath( jetpackPath, params );

		expect( result ).toBe( `/sites/${ params.siteId }` );
	} );
} );