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 axios from 'axios';
import MockAdapter from 'axios-mock-adapter';
import testAction from 'helpers/vuex_action_helper';
import * as actions from '~/admin/statistics_panel/store/actions';
import * as types from '~/admin/statistics_panel/store/mutation_types';
import getInitialState from '~/admin/statistics_panel/store/state';
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
import { HTTP_STATUS_INTERNAL_SERVER_ERROR } from '~/lib/utils/http_status';
import mockStatistics from '../mock_data';
describe('Admin statistics panel actions', () => {
let mock;
let state;
beforeEach(() => {
state = getInitialState();
mock = new MockAdapter(axios);
});
describe('fetchStatistics', () => {
describe('success', () => {
beforeEach(() => {
mock.onGet(/api\/(.*)\/application\/statistics/).replyOnce(200, mockStatistics);
});
it('dispatches success with received data', () => {
return testAction(
actions.fetchStatistics,
null,
state,
[],
[
{ type: 'requestStatistics' },
{
type: 'receiveStatisticsSuccess',
payload: expect.objectContaining(
convertObjectPropsToCamelCase(mockStatistics, { deep: true }),
),
},
],
);
});
});
describe('error', () => {
beforeEach(() => {
mock
.onGet(/api\/(.*)\/application\/statistics/)
.replyOnce(HTTP_STATUS_INTERNAL_SERVER_ERROR);
});
it('dispatches error', () => {
return testAction(
actions.fetchStatistics,
null,
state,
[],
[
{
type: 'requestStatistics',
},
{
type: 'receiveStatisticsError',
payload: new Error('Request failed with status code 500'),
},
],
);
});
});
});
describe('requestStatistic', () => {
it('should commit the request mutation', () => {
return testAction(
actions.requestStatistics,
null,
state,
[{ type: types.REQUEST_STATISTICS }],
[],
);
});
});
describe('receiveStatisticsSuccess', () => {
it('should commit received data', () => {
return testAction(
actions.receiveStatisticsSuccess,
mockStatistics,
state,
[
{
type: types.RECEIVE_STATISTICS_SUCCESS,
payload: mockStatistics,
},
],
[],
);
});
});
describe('receiveStatisticsError', () => {
it('should commit error', () => {
return testAction(
actions.receiveStatisticsError,
HTTP_STATUS_INTERNAL_SERVER_ERROR,
state,
[
{
type: types.RECEIVE_STATISTICS_ERROR,
payload: HTTP_STATUS_INTERNAL_SERVER_ERROR,
},
],
[],
);
});
});
});
|