2020-04-22 19:07:51 +05:30
|
|
|
import axios from 'axios';
|
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
|
|
|
import testAction from 'helpers/vuex_action_helper';
|
2023-05-27 22:25:52 +05:30
|
|
|
import { createAlert } from '~/alert';
|
2023-04-23 21:23:45 +05:30
|
|
|
import { HTTP_STATUS_INTERNAL_SERVER_ERROR, HTTP_STATUS_OK } from '~/lib/utils/http_status';
|
2020-04-22 19:07:51 +05:30
|
|
|
import actions from '~/projects/commits/store/actions';
|
2021-03-11 19:13:27 +05:30
|
|
|
import * as types from '~/projects/commits/store/mutation_types';
|
2020-04-22 19:07:51 +05:30
|
|
|
import createState from '~/projects/commits/store/state';
|
|
|
|
|
2023-05-27 22:25:52 +05:30
|
|
|
jest.mock('~/alert');
|
2020-04-22 19:07:51 +05:30
|
|
|
|
|
|
|
describe('Project commits actions', () => {
|
|
|
|
let state;
|
|
|
|
let mock;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
state = createState();
|
|
|
|
mock = new MockAdapter(axios);
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
|
|
|
mock.restore();
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('setInitialData', () => {
|
|
|
|
it(`commits ${types.SET_INITIAL_DATA}`, () =>
|
|
|
|
testAction(actions.setInitialData, undefined, state, [{ type: types.SET_INITIAL_DATA }]));
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('receiveAuthorsSuccess', () => {
|
|
|
|
it(`commits ${types.COMMITS_AUTHORS}`, () =>
|
|
|
|
testAction(actions.receiveAuthorsSuccess, undefined, state, [
|
|
|
|
{ type: types.COMMITS_AUTHORS },
|
|
|
|
]));
|
|
|
|
});
|
|
|
|
|
2023-06-20 00:43:36 +05:30
|
|
|
describe('shows an alert when there is an error', () => {
|
2023-05-27 22:25:52 +05:30
|
|
|
it('creates an alert', () => {
|
2020-04-22 19:07:51 +05:30
|
|
|
const mockDispatchContext = { dispatch: () => {}, commit: () => {}, state };
|
|
|
|
actions.receiveAuthorsError(mockDispatchContext);
|
|
|
|
|
2022-11-25 23:54:43 +05:30
|
|
|
expect(createAlert).toHaveBeenCalledTimes(1);
|
|
|
|
expect(createAlert).toHaveBeenCalledWith({
|
2021-09-04 01:27:46 +05:30
|
|
|
message: 'An error occurred fetching the project authors.',
|
|
|
|
});
|
2020-04-22 19:07:51 +05:30
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
describe('fetchAuthors', () => {
|
|
|
|
it('dispatches request/receive', () => {
|
2020-07-28 23:09:34 +05:30
|
|
|
const path = '/-/autocomplete/users.json';
|
2020-04-22 19:07:51 +05:30
|
|
|
state.projectId = '8';
|
|
|
|
const data = [{ id: 1 }];
|
|
|
|
|
2023-04-23 21:23:45 +05:30
|
|
|
mock.onGet(path).replyOnce(HTTP_STATUS_OK, data);
|
2020-04-22 19:07:51 +05:30
|
|
|
testAction(
|
|
|
|
actions.fetchAuthors,
|
|
|
|
null,
|
|
|
|
state,
|
|
|
|
[],
|
|
|
|
[{ type: 'receiveAuthorsSuccess', payload: data }],
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('dispatches request/receive on error', () => {
|
2020-07-28 23:09:34 +05:30
|
|
|
const path = '/-/autocomplete/users.json';
|
2023-04-23 21:23:45 +05:30
|
|
|
mock.onGet(path).replyOnce(HTTP_STATUS_INTERNAL_SERVER_ERROR);
|
2020-04-22 19:07:51 +05:30
|
|
|
|
|
|
|
testAction(actions.fetchAuthors, null, state, [], [{ type: 'receiveAuthorsError' }]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|