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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
import testAction from 'helpers/vuex_action_helper';
import { userList } from 'jest/feature_flags/mock_data';
import Api from '~/api';
import { stringifyUserIds } from '~/user_lists/store/utils';
import createState from '~/user_lists/store/show/state';
import * as types from '~/user_lists/store/show/mutation_types';
import * as actions from '~/user_lists/store/show/actions';
jest.mock('~/api');
describe('User Lists Show Actions', () => {
let mockState;
beforeEach(() => {
mockState = createState({ projectId: '1', userListIid: '2' });
});
describe('fetchUserList', () => {
it('commits REQUEST_USER_LIST and RECEIVE_USER_LIST_SUCCESS on success', () => {
Api.fetchFeatureFlagUserList.mockResolvedValue({ data: userList });
return testAction(
actions.fetchUserList,
undefined,
mockState,
[
{ type: types.REQUEST_USER_LIST },
{ type: types.RECEIVE_USER_LIST_SUCCESS, payload: userList },
],
[],
() => expect(Api.fetchFeatureFlagUserList).toHaveBeenCalledWith('1', '2'),
);
});
it('commits REQUEST_USER_LIST and RECEIVE_USER_LIST_ERROR on error', () => {
Api.fetchFeatureFlagUserList.mockRejectedValue({ message: 'fail' });
return testAction(
actions.fetchUserList,
undefined,
mockState,
[{ type: types.REQUEST_USER_LIST }, { type: types.RECEIVE_USER_LIST_ERROR }],
[],
);
});
});
describe('dismissErrorAlert', () => {
it('commits DISMISS_ERROR_ALERT', () => {
return testAction(
actions.dismissErrorAlert,
undefined,
mockState,
[{ type: types.DISMISS_ERROR_ALERT }],
[],
);
});
});
describe('addUserIds', () => {
it('adds the given IDs and tries to update the user list', () => {
return testAction(
actions.addUserIds,
'1,2,3',
mockState,
[{ type: types.ADD_USER_IDS, payload: '1,2,3' }],
[{ type: 'updateUserList' }],
);
});
});
describe('removeUserId', () => {
it('removes the given ID and tries to update the user list', () => {
return testAction(
actions.removeUserId,
'user3',
mockState,
[{ type: types.REMOVE_USER_ID, payload: 'user3' }],
[{ type: 'updateUserList' }],
);
});
});
describe('updateUserList', () => {
beforeEach(() => {
mockState.userList = userList;
mockState.userIds = ['user1', 'user2', 'user3'];
});
it('commits REQUEST_USER_LIST and RECEIVE_USER_LIST_SUCCESS on success', () => {
Api.updateFeatureFlagUserList.mockResolvedValue({ data: userList });
return testAction(
actions.updateUserList,
undefined,
mockState,
[
{ type: types.REQUEST_USER_LIST },
{ type: types.RECEIVE_USER_LIST_SUCCESS, payload: userList },
],
[],
() =>
expect(Api.updateFeatureFlagUserList).toHaveBeenCalledWith('1', {
...userList,
user_xids: stringifyUserIds(mockState.userIds),
}),
);
});
it('commits REQUEST_USER_LIST and RECEIVE_USER_LIST_ERROR on error', () => {
Api.updateFeatureFlagUserList.mockRejectedValue({ message: 'fail' });
return testAction(
actions.updateUserList,
undefined,
mockState,
[{ type: types.REQUEST_USER_LIST }, { type: types.RECEIVE_USER_LIST_ERROR }],
[],
);
});
});
});
|