2019-11-11 15:06:42 +00:00
|
|
|
import MockAdapter from 'axios-mock-adapter';
|
|
|
|
import testAction from 'helpers/vuex_action_helper';
|
2019-12-10 09:07:51 +00:00
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2020-08-20 09:09:55 +00:00
|
|
|
import { deprecatedCreateFlash as createFlash } from '~/flash';
|
2019-11-11 15:06:42 +00:00
|
|
|
import * as actions from '~/error_tracking/store/details/actions';
|
|
|
|
import * as types from '~/error_tracking/store/details/mutation_types';
|
2020-01-23 06:08:32 +00:00
|
|
|
import Poll from '~/lib/utils/poll';
|
|
|
|
|
|
|
|
let mockedAdapter;
|
|
|
|
let mockedRestart;
|
2019-11-11 15:06:42 +00:00
|
|
|
|
|
|
|
jest.mock('~/flash.js');
|
2020-01-15 18:08:34 +00:00
|
|
|
jest.mock('~/lib/utils/url_utility');
|
|
|
|
|
2019-11-11 15:06:42 +00:00
|
|
|
describe('Sentry error details store actions', () => {
|
|
|
|
beforeEach(() => {
|
2020-01-23 06:08:32 +00:00
|
|
|
mockedAdapter = new MockAdapter(axios);
|
2019-11-11 15:06:42 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(() => {
|
2020-01-23 06:08:32 +00:00
|
|
|
mockedAdapter.restore();
|
2019-11-11 15:06:42 +00:00
|
|
|
createFlash.mockClear();
|
2020-01-23 06:08:32 +00:00
|
|
|
if (mockedRestart) {
|
|
|
|
mockedRestart.mockRestore();
|
|
|
|
mockedRestart = null;
|
|
|
|
}
|
2019-11-11 15:06:42 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
describe('startPollingStacktrace', () => {
|
|
|
|
const endpoint = '123/stacktrace';
|
2020-12-23 21:10:24 +00:00
|
|
|
it('should commit SET_ERROR with received response', (done) => {
|
2019-11-11 15:06:42 +00:00
|
|
|
const payload = { error: [1, 2, 3] };
|
2020-01-23 06:08:32 +00:00
|
|
|
mockedAdapter.onGet().reply(200, payload);
|
2019-11-11 15:06:42 +00:00
|
|
|
testAction(
|
|
|
|
actions.startPollingStacktrace,
|
|
|
|
{ endpoint },
|
|
|
|
{},
|
|
|
|
[
|
|
|
|
{ type: types.SET_STACKTRACE_DATA, payload: payload.error },
|
|
|
|
{ type: types.SET_LOADING_STACKTRACE, payload: false },
|
|
|
|
],
|
|
|
|
[],
|
|
|
|
() => {
|
|
|
|
done();
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
|
|
|
|
2020-12-23 21:10:24 +00:00
|
|
|
it('should show flash on API error', (done) => {
|
2020-01-23 06:08:32 +00:00
|
|
|
mockedAdapter.onGet().reply(400);
|
2019-11-11 15:06:42 +00:00
|
|
|
|
|
|
|
testAction(
|
|
|
|
actions.startPollingStacktrace,
|
|
|
|
{ endpoint },
|
|
|
|
{},
|
|
|
|
[{ type: types.SET_LOADING_STACKTRACE, payload: false }],
|
|
|
|
[],
|
|
|
|
() => {
|
|
|
|
expect(createFlash).toHaveBeenCalledTimes(1);
|
|
|
|
done();
|
|
|
|
},
|
|
|
|
);
|
|
|
|
});
|
2020-01-23 06:08:32 +00:00
|
|
|
|
2020-12-23 21:10:24 +00:00
|
|
|
it('should not restart polling when receiving an empty 204 response', (done) => {
|
2020-01-23 06:08:32 +00:00
|
|
|
mockedRestart = jest.spyOn(Poll.prototype, 'restart');
|
|
|
|
mockedAdapter.onGet().reply(204);
|
|
|
|
|
|
|
|
testAction(actions.startPollingStacktrace, { endpoint }, {}, [], [], () => {
|
|
|
|
mockedRestart = jest.spyOn(Poll.prototype, 'restart');
|
|
|
|
expect(mockedRestart).toHaveBeenCalledTimes(0);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
2019-11-11 15:06:42 +00:00
|
|
|
});
|
|
|
|
});
|