diff options
Diffstat (limited to 'spec/frontend/diffs/store/actions_spec.js')
-rw-r--r-- | spec/frontend/diffs/store/actions_spec.js | 36 |
1 files changed, 21 insertions, 15 deletions
diff --git a/spec/frontend/diffs/store/actions_spec.js b/spec/frontend/diffs/store/actions_spec.js index 9e0ffbf757f..78765204322 100644 --- a/spec/frontend/diffs/store/actions_spec.js +++ b/spec/frontend/diffs/store/actions_spec.js @@ -16,6 +16,12 @@ import * as treeWorkerUtils from '~/diffs/utils/tree_worker_utils'; import { createAlert } from '~/flash'; import axios from '~/lib/utils/axios_utils'; import * as commonUtils from '~/lib/utils/common_utils'; +import { + HTTP_STATUS_BAD_REQUEST, + HTTP_STATUS_INTERNAL_SERVER_ERROR, + HTTP_STATUS_NOT_FOUND, + HTTP_STATUS_OK, +} from '~/lib/utils/http_status'; import { mergeUrlParams } from '~/lib/utils/url_utility'; import eventHub from '~/notes/event_hub'; import { diffMetadata } from '../mock_data/diff_metadata'; @@ -142,7 +148,7 @@ describe('DiffsStoreActions', () => { endpointBatch, ), ) - .reply(200, res1) + .reply(HTTP_STATUS_OK, res1) .onGet( mergeUrlParams( { @@ -154,7 +160,7 @@ describe('DiffsStoreActions', () => { endpointBatch, ), ) - .reply(200, res2); + .reply(HTTP_STATUS_OK, res2); return testAction( diffActions.fetchDiffFilesBatch, @@ -186,7 +192,7 @@ describe('DiffsStoreActions', () => { }); it('should fetch diff meta information', () => { - mock.onGet(endpointMetadata).reply(200, diffMetadata); + mock.onGet(endpointMetadata).reply(HTTP_STATUS_OK, diffMetadata); return testAction( diffActions.fetchDiffFilesMeta, @@ -208,7 +214,7 @@ describe('DiffsStoreActions', () => { }); it('should show a warning on 404 reponse', async () => { - mock.onGet(endpointMetadata).reply(404); + mock.onGet(endpointMetadata).reply(HTTP_STATUS_NOT_FOUND); await testAction( diffActions.fetchDiffFilesMeta, @@ -228,7 +234,7 @@ describe('DiffsStoreActions', () => { }); it('should show no warning on any other status code', async () => { - mock.onGet(endpointMetadata).reply(500); + mock.onGet(endpointMetadata).reply(HTTP_STATUS_INTERNAL_SERVER_ERROR); await testAction( diffActions.fetchDiffFilesMeta, @@ -248,7 +254,7 @@ describe('DiffsStoreActions', () => { it('should commit SET_COVERAGE_DATA with received response', () => { const data = { files: { 'app.js': { 1: 0, 2: 1 } } }; - mock.onGet(endpointCoverage).reply(200, { data }); + mock.onGet(endpointCoverage).reply(HTTP_STATUS_OK, { data }); return testAction( diffActions.fetchCoverageFiles, @@ -260,7 +266,7 @@ describe('DiffsStoreActions', () => { }); it('should show flash on API error', async () => { - mock.onGet(endpointCoverage).reply(400); + mock.onGet(endpointCoverage).reply(HTTP_STATUS_BAD_REQUEST); await testAction(diffActions.fetchCoverageFiles, {}, { endpointCoverage }, [], []); expect(createAlert).toHaveBeenCalledTimes(1); @@ -545,7 +551,7 @@ describe('DiffsStoreActions', () => { const nextLineNumbers = {}; const options = { endpoint, params, lineNumbers, fileHash, isExpandDown, nextLineNumbers }; const contextLines = { contextLines: [{ lineCode: 6 }] }; - mock.onGet(endpoint).reply(200, contextLines); + mock.onGet(endpoint).reply(HTTP_STATUS_OK, contextLines); return testAction( diffActions.loadMoreLines, @@ -568,7 +574,7 @@ describe('DiffsStoreActions', () => { const file = { hash: 123, load_collapsed_diff_url: '/load/collapsed/diff/url' }; const data = { hash: 123, parallelDiffLines: [{ lineCode: 1 }] }; const commit = jest.fn(); - mock.onGet(file.loadCollapsedDiffUrl).reply(200, data); + mock.onGet(file.loadCollapsedDiffUrl).reply(HTTP_STATUS_OK, data); return diffActions .loadCollapsedDiff({ commit, getters: { commitId: null }, state }, file) @@ -1007,7 +1013,7 @@ describe('DiffsStoreActions', () => { putSpy = jest.spyOn(axios, 'put'); gon = window.gon; - mock.onPut(endpointUpdateUser).reply(200, {}); + mock.onPut(endpointUpdateUser).reply(HTTP_STATUS_OK, {}); jest.spyOn(eventHub, '$emit').mockImplementation(); }); @@ -1084,7 +1090,7 @@ describe('DiffsStoreActions', () => { describe('fetchFullDiff', () => { describe('success', () => { beforeEach(() => { - mock.onGet(`${TEST_HOST}/context`).replyOnce(200, ['test']); + mock.onGet(`${TEST_HOST}/context`).replyOnce(HTTP_STATUS_OK, ['test']); }); it('commits the success and dispatches an action to expand the new lines', () => { @@ -1105,7 +1111,7 @@ describe('DiffsStoreActions', () => { describe('error', () => { beforeEach(() => { - mock.onGet(`${TEST_HOST}/context`).replyOnce(500); + mock.onGet(`${TEST_HOST}/context`).replyOnce(HTTP_STATUS_INTERNAL_SERVER_ERROR); }); it('dispatches receiveFullDiffError', () => { @@ -1169,7 +1175,7 @@ describe('DiffsStoreActions', () => { describe('success', () => { beforeEach(() => { renamedFile = { ...testFile, context_lines_path: SUCCESS_URL }; - mock.onGet(SUCCESS_URL).replyOnce(200, testData); + mock.onGet(SUCCESS_URL).replyOnce(HTTP_STATUS_OK, testData); }); it.each` @@ -1269,7 +1275,7 @@ describe('DiffsStoreActions', () => { describe('setSuggestPopoverDismissed', () => { it('commits SET_SHOW_SUGGEST_POPOVER', async () => { const state = { dismissEndpoint: `${TEST_HOST}/-/user_callouts` }; - mock.onPost(state.dismissEndpoint).reply(200, {}); + mock.onPost(state.dismissEndpoint).reply(HTTP_STATUS_OK, {}); jest.spyOn(axios, 'post'); @@ -1444,7 +1450,7 @@ describe('DiffsStoreActions', () => { beforeEach(() => { putSpy = jest.spyOn(axios, 'put'); - mock.onPut(updateUserEndpoint).reply(200, {}); + mock.onPut(updateUserEndpoint).reply(HTTP_STATUS_OK, {}); }); it.each` |