File size: 1,087 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
import { http } from 'calypso/state/data-layer/wpcom-http/actions';
import { TEAMS_RECEIVE } from 'calypso/state/teams/action-types';
import { handleTeamsRequest, teamRequestFailure, teamRequestReceived } from '../';

const action = { type: 'DUMMY_ACTION' };

test( 'should return an action for an HTTP request to teams endpoint', () => {
	const result = handleTeamsRequest( action );

	expect( result ).toEqual(
		http(
			{
				method: 'GET',
				path: '/read/teams',
				apiVersion: '1.2',
			},
			action
		)
	);
} );

test( 'should return a TEAMS_RECEIVE action with error when request errors', () => {
	const result = teamRequestFailure( action );

	expect( result ).toEqual( {
		type: TEAMS_RECEIVE,
		payload: action,
		error: true,
	} );
} );

test( 'should return a TEAMS_RECEIVE action without error when request succeeds', () => {
	const apiResponse = {
		teams: [
			{
				slug: 'a8c',
				title: 'Automattic',
			},
		],
	};
	const result = teamRequestReceived( action, apiResponse );

	expect( result ).toEqual( {
		type: TEAMS_RECEIVE,
		payload: apiResponse,
	} );
} );