summaryrefslogtreecommitdiff
path: root/spec/frontend/error_tracking/store/details/actions_spec.js
blob: 623cb82851dde9d126f24d54d424e3bbe0eaaabc (plain)
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
69
70
71
72
73
74
75
76
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 createFlash 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();
    createFlash.mockClear();
    if (mockedRestart) {
      mockedRestart.mockRestore();
      mockedRestart = null;
    }
  });

  describe('startPollingStacktrace', () => {
    const endpoint = '123/stacktrace';
    it('should commit SET_ERROR with received response', (done) => {
      const payload = { error: [1, 2, 3] };
      mockedAdapter.onGet().reply(200, payload);
      testAction(
        actions.startPollingStacktrace,
        { endpoint },
        {},
        [
          { type: types.SET_STACKTRACE_DATA, payload: payload.error },
          { type: types.SET_LOADING_STACKTRACE, payload: false },
        ],
        [],
        () => {
          done();
        },
      );
    });

    it('should show flash on API error', (done) => {
      mockedAdapter.onGet().reply(400);

      testAction(
        actions.startPollingStacktrace,
        { endpoint },
        {},
        [{ type: types.SET_LOADING_STACKTRACE, payload: false }],
        [],
        () => {
          expect(createFlash).toHaveBeenCalledTimes(1);
          done();
        },
      );
    });

    it('should not restart polling when receiving an empty 204 response', (done) => {
      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();
      });
    });
  });
});