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
|
import MockAdapter from 'axios-mock-adapter';
import testAction from 'helpers/vuex_action_helper';
import * as actions from '~/error_tracking/store/details/actions';
import * as types from '~/error_tracking/store/details/mutation_types';
import { createAlert } from '~/flash';
import axios from '~/lib/utils/axios_utils';
import Poll from '~/lib/utils/poll';
let mockedAdapter;
let mockedRestart;
jest.mock('~/flash.js');
jest.mock('~/lib/utils/url_utility');
describe('Sentry error details store actions', () => {
beforeEach(() => {
mockedAdapter = new MockAdapter(axios);
});
afterEach(() => {
mockedAdapter.restore();
createAlert.mockClear();
if (mockedRestart) {
mockedRestart.mockRestore();
mockedRestart = null;
}
});
describe('startPollingStacktrace', () => {
const endpoint = '123/stacktrace';
it('should commit SET_ERROR with received response', () => {
const payload = { error: [1, 2, 3] };
mockedAdapter.onGet().reply(200, payload);
return testAction(
actions.startPollingStacktrace,
{ endpoint },
{},
[
{ type: types.SET_STACKTRACE_DATA, payload: payload.error },
{ type: types.SET_LOADING_STACKTRACE, payload: false },
],
[],
);
});
it('should show flash on API error', async () => {
mockedAdapter.onGet().reply(400);
await testAction(
actions.startPollingStacktrace,
{ endpoint },
{},
[{ type: types.SET_LOADING_STACKTRACE, payload: false }],
[],
);
expect(createAlert).toHaveBeenCalledTimes(1);
});
it('should not restart polling when receiving an empty 204 response', async () => {
mockedRestart = jest.spyOn(Poll.prototype, 'restart');
mockedAdapter.onGet().reply(204);
await testAction(actions.startPollingStacktrace, { endpoint }, {}, [], []);
mockedRestart = jest.spyOn(Poll.prototype, 'restart');
expect(mockedRestart).toHaveBeenCalledTimes(0);
});
});
});
|