2019-07-07 11:18:12 +05:30
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
2019-09-30 21:07:59 +05:30
|
|
|
import { TEST_HOST } from 'helpers/test_constants';
|
2021-03-11 19:13:27 +05:30
|
|
|
import testAction from 'helpers/vuex_action_helper';
|
2019-09-30 21:07:59 +05:30
|
|
|
import * as actions from '~/error_tracking_settings/store/actions';
|
2019-07-07 11:18:12 +05:30
|
|
|
import * as types from '~/error_tracking_settings/store/mutation_types';
|
|
|
|
import defaultState from '~/error_tracking_settings/store/state';
|
2021-03-11 19:13:27 +05:30
|
|
|
import axios from '~/lib/utils/axios_utils';
|
|
|
|
import { convertObjectPropsToCamelCase } from '~/lib/utils/common_utils';
|
|
|
|
import { refreshCurrentPage } from '~/lib/utils/url_utility';
|
2019-07-07 11:18:12 +05:30
|
|
|
import { projectList } from '../mock';
|
|
|
|
|
2019-09-30 21:07:59 +05:30
|
|
|
jest.mock('~/lib/utils/url_utility');
|
|
|
|
|
2019-07-07 11:18:12 +05:30
|
|
|
describe('error tracking settings actions', () => {
|
|
|
|
let state;
|
|
|
|
|
|
|
|
describe('project list actions', () => {
|
|
|
|
let mock;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
mock = new MockAdapter(axios);
|
|
|
|
state = { ...defaultState(), listProjectsEndpoint: TEST_HOST };
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
mock.restore();
|
2019-09-30 21:07:59 +05:30
|
|
|
refreshCurrentPage.mockClear();
|
2019-07-07 11:18:12 +05:30
|
|
|
});
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
it('should request and transform the project list', (done) => {
|
2020-03-13 15:44:24 +05:30
|
|
|
mock.onGet(TEST_HOST).reply(() => [200, { projects: projectList }]);
|
2019-07-07 11:18:12 +05:30
|
|
|
testAction(
|
|
|
|
actions.fetchProjects,
|
|
|
|
null,
|
|
|
|
state,
|
|
|
|
[],
|
|
|
|
[
|
|
|
|
{ type: 'requestProjects' },
|
|
|
|
{
|
|
|
|
type: 'receiveProjectsSuccess',
|
|
|
|
payload: projectList.map(convertObjectPropsToCamelCase),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
() => {
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(mock.history.get.length).toBe(1);
|
2019-07-07 11:18:12 +05:30
|
|
|
done();
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
it('should handle a server error', (done) => {
|
2020-03-13 15:44:24 +05:30
|
|
|
mock.onGet(`${TEST_HOST}.json`).reply(() => [400]);
|
2019-07-07 11:18:12 +05:30
|
|
|
testAction(
|
|
|
|
actions.fetchProjects,
|
|
|
|
null,
|
|
|
|
state,
|
|
|
|
[],
|
|
|
|
[
|
|
|
|
{ type: 'requestProjects' },
|
|
|
|
{
|
|
|
|
type: 'receiveProjectsError',
|
|
|
|
},
|
|
|
|
],
|
|
|
|
() => {
|
2020-03-13 15:44:24 +05:30
|
|
|
expect(mock.history.get.length).toBe(1);
|
2019-07-07 11:18:12 +05:30
|
|
|
done();
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
it('should request projects correctly', (done) => {
|
2019-12-26 22:10:19 +05:30
|
|
|
testAction(
|
|
|
|
actions.requestProjects,
|
|
|
|
null,
|
|
|
|
state,
|
|
|
|
[{ type: types.SET_PROJECTS_LOADING, payload: true }, { type: types.RESET_CONNECT }],
|
|
|
|
[],
|
|
|
|
done,
|
|
|
|
);
|
2019-07-07 11:18:12 +05:30
|
|
|
});
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
it('should receive projects correctly', (done) => {
|
2019-07-07 11:18:12 +05:30
|
|
|
const testPayload = [];
|
|
|
|
testAction(
|
|
|
|
actions.receiveProjectsSuccess,
|
|
|
|
testPayload,
|
|
|
|
state,
|
|
|
|
[
|
|
|
|
{ type: types.UPDATE_CONNECT_SUCCESS },
|
|
|
|
{ type: types.RECEIVE_PROJECTS, payload: testPayload },
|
2019-12-26 22:10:19 +05:30
|
|
|
{ type: types.SET_PROJECTS_LOADING, payload: false },
|
2019-07-07 11:18:12 +05:30
|
|
|
],
|
|
|
|
[],
|
|
|
|
done,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
it('should handle errors when receiving projects', (done) => {
|
2019-07-07 11:18:12 +05:30
|
|
|
const testPayload = [];
|
|
|
|
testAction(
|
|
|
|
actions.receiveProjectsError,
|
|
|
|
testPayload,
|
|
|
|
state,
|
2019-12-26 22:10:19 +05:30
|
|
|
[
|
|
|
|
{ type: types.UPDATE_CONNECT_ERROR },
|
|
|
|
{ type: types.CLEAR_PROJECTS },
|
|
|
|
{ type: types.SET_PROJECTS_LOADING, payload: false },
|
|
|
|
],
|
2019-07-07 11:18:12 +05:30
|
|
|
[],
|
|
|
|
done,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('save changes actions', () => {
|
|
|
|
let mock;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
mock = new MockAdapter(axios);
|
|
|
|
state = {
|
|
|
|
operationsSettingsEndpoint: TEST_HOST,
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
mock.restore();
|
|
|
|
});
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
it('should save the page', (done) => {
|
2019-07-07 11:18:12 +05:30
|
|
|
mock.onPatch(TEST_HOST).reply(200);
|
|
|
|
testAction(actions.updateSettings, null, state, [], [{ type: 'requestSettings' }], () => {
|
|
|
|
expect(mock.history.patch.length).toBe(1);
|
|
|
|
expect(refreshCurrentPage).toHaveBeenCalled();
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
it('should handle a server error', (done) => {
|
2019-07-07 11:18:12 +05:30
|
|
|
mock.onPatch(TEST_HOST).reply(400);
|
|
|
|
testAction(
|
|
|
|
actions.updateSettings,
|
|
|
|
null,
|
|
|
|
state,
|
|
|
|
[],
|
|
|
|
[
|
|
|
|
{ type: 'requestSettings' },
|
|
|
|
{
|
|
|
|
type: 'receiveSettingsError',
|
|
|
|
payload: new Error('Request failed with status code 400'),
|
|
|
|
},
|
|
|
|
],
|
|
|
|
() => {
|
|
|
|
expect(mock.history.patch.length).toBe(1);
|
|
|
|
done();
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
it('should request to save the page', (done) => {
|
2019-07-07 11:18:12 +05:30
|
|
|
testAction(
|
|
|
|
actions.requestSettings,
|
|
|
|
null,
|
|
|
|
state,
|
|
|
|
[{ type: types.UPDATE_SETTINGS_LOADING, payload: true }],
|
|
|
|
[],
|
|
|
|
done,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
it('should handle errors when requesting to save the page', (done) => {
|
2019-07-07 11:18:12 +05:30
|
|
|
testAction(
|
|
|
|
actions.receiveSettingsError,
|
|
|
|
{},
|
|
|
|
state,
|
|
|
|
[{ type: types.UPDATE_SETTINGS_LOADING, payload: false }],
|
|
|
|
[],
|
|
|
|
done,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('generic actions to update the store', () => {
|
|
|
|
const testData = 'test';
|
2021-03-08 18:12:59 +05:30
|
|
|
it('should reset the `connect success` flag when updating the api host', (done) => {
|
2019-07-07 11:18:12 +05:30
|
|
|
testAction(
|
|
|
|
actions.updateApiHost,
|
|
|
|
testData,
|
|
|
|
state,
|
|
|
|
[{ type: types.UPDATE_API_HOST, payload: testData }, { type: types.RESET_CONNECT }],
|
|
|
|
[],
|
|
|
|
done,
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2021-03-08 18:12:59 +05:30
|
|
|
it('should reset the `connect success` flag when updating the token', (done) => {
|
2019-07-07 11:18:12 +05:30
|
|
|
testAction(
|
|
|
|
actions.updateToken,
|
|
|
|
testData,
|
|
|
|
state,
|
|
|
|
[{ type: types.UPDATE_TOKEN, payload: testData }, { type: types.RESET_CONNECT }],
|
|
|
|
[],
|
|
|
|
done,
|
|
|
|
);
|
|
|
|
});
|
2021-11-11 11:23:49 +05:30
|
|
|
|
|
|
|
it.each([true, false])('should set the `integrated` flag to `%s`', async (payload) => {
|
|
|
|
await testAction(actions.updateIntegrated, payload, state, [
|
|
|
|
{ type: types.UPDATE_INTEGRATED, payload },
|
|
|
|
]);
|
|
|
|
});
|
2019-07-07 11:18:12 +05:30
|
|
|
});
|
|
|
|
});
|