2019-09-09 03:38:42 +00:00
|
|
|
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';
|
2021-02-14 18:09:20 +00:00
|
|
|
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
|
2019-09-09 03:38:42 +00:00
|
|
|
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);
|
|
|
|
});
|
|
|
|
|
2022-04-18 18:10:36 +00:00
|
|
|
it('dispatches success with received data', () => {
|
|
|
|
return testAction(
|
2019-09-09 03:38:42 +00:00
|
|
|
actions.fetchStatistics,
|
|
|
|
null,
|
|
|
|
state,
|
|
|
|
[],
|
|
|
|
[
|
|
|
|
{ type: 'requestStatistics' },
|
|
|
|
{
|
|
|
|
type: 'receiveStatisticsSuccess',
|
|
|
|
payload: expect.objectContaining(
|
|
|
|
convertObjectPropsToCamelCase(mockStatistics, { deep: true }),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
],
|
2022-04-18 18:10:36 +00:00
|
|
|
);
|
|
|
|
});
|
2019-09-09 03:38:42 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('error', () => {
|
|
|
|
beforeEach(() => {
|
|
|
|
mock.onGet(/api\/(.*)\/application\/statistics/).replyOnce(500);
|
|
|
|
});
|
|
|
|
|
2022-04-18 18:10:36 +00:00
|
|
|
it('dispatches error', () => {
|
|
|
|
return testAction(
|
2019-09-09 03:38:42 +00:00
|
|
|
actions.fetchStatistics,
|
|
|
|
null,
|
|
|
|
state,
|
|
|
|
[],
|
|
|
|
[
|
|
|
|
{
|
|
|
|
type: 'requestStatistics',
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'receiveStatisticsError',
|
|
|
|
payload: new Error('Request failed with status code 500'),
|
|
|
|
},
|
|
|
|
],
|
2022-04-18 18:10:36 +00:00
|
|
|
);
|
|
|
|
});
|
2019-09-09 03:38:42 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('requestStatistic', () => {
|
2022-04-18 18:10:36 +00:00
|
|
|
it('should commit the request mutation', () => {
|
|
|
|
return testAction(
|
2019-09-09 03:38:42 +00:00
|
|
|
actions.requestStatistics,
|
|
|
|
null,
|
|
|
|
state,
|
|
|
|
[{ type: types.REQUEST_STATISTICS }],
|
|
|
|
[],
|
2022-04-18 18:10:36 +00:00
|
|
|
);
|
|
|
|
});
|
2019-09-09 03:38:42 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('receiveStatisticsSuccess', () => {
|
2022-04-18 18:10:36 +00:00
|
|
|
it('should commit received data', () => {
|
|
|
|
return testAction(
|
2019-09-09 03:38:42 +00:00
|
|
|
actions.receiveStatisticsSuccess,
|
|
|
|
mockStatistics,
|
|
|
|
state,
|
|
|
|
[
|
|
|
|
{
|
|
|
|
type: types.RECEIVE_STATISTICS_SUCCESS,
|
|
|
|
payload: mockStatistics,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[],
|
2022-04-18 18:10:36 +00:00
|
|
|
);
|
|
|
|
});
|
2019-09-09 03:38:42 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('receiveStatisticsError', () => {
|
2022-04-18 18:10:36 +00:00
|
|
|
it('should commit error', () => {
|
|
|
|
return testAction(
|
2019-09-09 03:38:42 +00:00
|
|
|
actions.receiveStatisticsError,
|
|
|
|
500,
|
|
|
|
state,
|
|
|
|
[
|
|
|
|
{
|
|
|
|
type: types.RECEIVE_STATISTICS_ERROR,
|
|
|
|
payload: 500,
|
|
|
|
},
|
|
|
|
],
|
|
|
|
[],
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|