File size: 1,646 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
import {
	activePromotionsReceiveAction,
	activePromotionsRequestFailureAction,
	activePromotionsRequestSuccessAction,
} from 'calypso/state/active-promotions/actions';
import { WPCOM_RESPONSE } from 'calypso/state/active-promotions/test/fixture';
import { http } from 'calypso/state/data-layer/wpcom-http/actions';
import { receiveActivePromotions, receiveError, requestActivePromotions } from '../';

describe( 'wpcom-api', () => {
	describe( 'active promotions request', () => {
		describe( '#requestActivePromotions', () => {
			test( 'should return HTTP request to active-promotions endpoint', () => {
				const action = { type: 'DUMMY' };

				expect( requestActivePromotions( action ) ).toEqual(
					http(
						{
							apiVersion: '1.1',
							method: 'GET',
							path: '/me/active-promotions',
						},
						action
					)
				);
			} );
		} );

		describe( '#receiveActivePromotions', () => {
			test( 'should return active promotions', () => {
				const activePromotions = WPCOM_RESPONSE;
				const action = activePromotionsReceiveAction( activePromotions );

				expect(
					receiveActivePromotions( action, { active_promotions: activePromotions } )
				).toEqual( [
					activePromotionsRequestSuccessAction(),
					activePromotionsReceiveAction( activePromotions ),
				] );
			} );
		} );

		describe( '#receiveError', () => {
			test( 'should return error', () => {
				const error = 'could not find active promotions';
				const action = activePromotionsRequestFailureAction( error );

				expect( receiveError( action, error ) ).toEqual(
					activePromotionsRequestFailureAction( error )
				);
			} );
		} );
	} );
} );