diff --git a/ee/spec/frontend/analytics/contribution_analytics/group_members_spec.js b/ee/spec/frontend/analytics/contribution_analytics/group_members_spec.js index 6efa3811b927c0456c83be9f0e0910246ab82af7..60b4d8fd191e06408102c08692ad62303ce8927a 100644 --- a/ee/spec/frontend/analytics/contribution_analytics/group_members_spec.js +++ b/ee/spec/frontend/analytics/contribution_analytics/group_members_spec.js @@ -3,7 +3,7 @@ import { TABLE_COLUMNS } from 'ee/analytics/contribution_analytics/constants'; import GroupMembers from 'ee/analytics/contribution_analytics/group_members'; import { createAlert } from '~/flash'; import axios from '~/lib/utils/axios_utils'; -import { HTTP_STATUS_OK } from '~/lib/utils/http_status'; +import { HTTP_STATUS_INTERNAL_SERVER_ERROR, HTTP_STATUS_OK } from '~/lib/utils/http_status'; import waitForPromises from 'helpers/wait_for_promises'; import { MOCK_MEMBERS, CONTRIBUTIONS_PATH } from './mock_data'; @@ -87,7 +87,7 @@ describe('GroupMembers', () => { }); it('calls service.getContributedMembers and sets `isLoading` to false and shows flash message if request failed', async () => { - mock.onGet(CONTRIBUTIONS_PATH).reply(500, {}); + mock.onGet(CONTRIBUTIONS_PATH).reply(HTTP_STATUS_INTERNAL_SERVER_ERROR, {}); await expect(store.fetchContributedMembers()).rejects.toEqual( new Error('Request failed with status code 500'), diff --git a/ee/spec/frontend/dependencies/store/modules/list/actions_spec.js b/ee/spec/frontend/dependencies/store/modules/list/actions_spec.js index be7e970dc0ba9952a7f7ba6350c2decd369a6a0b..a110261a78ea1976bafd584d6d0b3b794efd83ab 100644 --- a/ee/spec/frontend/dependencies/store/modules/list/actions_spec.js +++ b/ee/spec/frontend/dependencies/store/modules/list/actions_spec.js @@ -15,7 +15,12 @@ import { TEST_HOST } from 'helpers/test_constants'; import testAction from 'helpers/vuex_action_helper'; import { createAlert } from '~/flash'; import download from '~/lib/utils/downloader'; -import { HTTP_STATUS_CREATED, HTTP_STATUS_NOT_FOUND } from '~/lib/utils/http_status'; +import { + HTTP_STATUS_CREATED, + HTTP_STATUS_INTERNAL_SERVER_ERROR, + HTTP_STATUS_NOT_FOUND, + HTTP_STATUS_OK, +} from '~/lib/utils/http_status'; import mockDependenciesResponse from './data/mock_dependencies.json'; @@ -199,7 +204,7 @@ describe('Dependencies actions', () => { mock .onGet(state.endpoint, { params: paramsDefault }) - .replyOnce(200, mockDependenciesResponse, headers); + .replyOnce(HTTP_STATUS_OK, mockDependenciesResponse, headers); }); it('uses default sorting params from state', () => @@ -231,7 +236,7 @@ describe('Dependencies actions', () => { beforeEach(() => { mock .onGet(state.endpoint, { params: paramsGiven }) - .replyOnce(200, dependenciesPackagerDescending, headers); + .replyOnce(HTTP_STATUS_OK, dependenciesPackagerDescending, headers); }); it('overrides default params', () => @@ -255,8 +260,8 @@ describe('Dependencies actions', () => { describe.each` responseType | responseDetails - ${'an invalid response'} | ${[200, { foo: 'bar' }]} - ${'a response error'} | ${[500]} + ${'an invalid response'} | ${[HTTP_STATUS_OK, { foo: 'bar' }]} + ${'a response error'} | ${[HTTP_STATUS_INTERNAL_SERVER_ERROR]} `('given $responseType', ({ responseDetails }) => { beforeEach(() => { mock.onGet(state.endpoint).replyOnce(...responseDetails); @@ -337,7 +342,7 @@ describe('Dependencies actions', () => { describe('on success with status other than created (201)', () => { beforeEach(() => { - mock.onPost(state.exportEndpoint).replyOnce(200, mockResponseExportEndpoint); + mock.onPost(state.exportEndpoint).replyOnce(HTTP_STATUS_OK, mockResponseExportEndpoint); }); it('does not dispatch downloadExport', () => @@ -402,7 +407,9 @@ describe('Dependencies actions', () => { describe('on success', () => { beforeEach(() => { - mock.onGet(mockResponseExportEndpoint.self).replyOnce(200, mockResponseExportEndpoint); + mock + .onGet(mockResponseExportEndpoint.self) + .replyOnce(HTTP_STATUS_OK, mockResponseExportEndpoint); }); it('sets SET_FETCHING_IN_PROGRESS and calls download', () => diff --git a/ee/spec/frontend/external_issues_list/graphql/resolver_spec.js b/ee/spec/frontend/external_issues_list/graphql/resolver_spec.js index 1ca70bd272860cb94a2d54a737487bd5c2356571..28ea89aff0260c1471dea0ddd07fa423fea0e433 100644 --- a/ee/spec/frontend/external_issues_list/graphql/resolver_spec.js +++ b/ee/spec/frontend/external_issues_list/graphql/resolver_spec.js @@ -5,7 +5,7 @@ import { externalIssuesResolverFactory } from 'ee/external_issues_list/graphql/r import { DEFAULT_PAGE_SIZE } from '~/vue_shared/issuable/list/constants'; import { i18n } from '~/issues/list/constants'; import axios from '~/lib/utils/axios_utils'; -import { HTTP_STATUS_OK } from '~/lib/utils/http_status'; +import { HTTP_STATUS_BAD_REQUEST, HTTP_STATUS_OK } from '~/lib/utils/http_status'; import { mockExternalIssues } from '../mock_data'; const DEFAULT_ISSUES_FETCH_PATH = '/test/issues/fetch'; @@ -105,7 +105,7 @@ describe('ee/external_issues_list/graphql/resolvers', () => { ${'when api request fails with unknown erorr'} | ${{}} | ${[i18n.errorFetchingIssues]} `('$desc', ({ errorResponse, expectedErrors }) => { beforeEach(() => { - issuesApiSpy.mockReturnValue([400, errorResponse]); + issuesApiSpy.mockReturnValue([HTTP_STATUS_BAD_REQUEST, errorResponse]); }); it('returns error data', async () => { diff --git a/ee/spec/frontend/geo_node_form/store/actions_spec.js b/ee/spec/frontend/geo_node_form/store/actions_spec.js index 853fc32080fe731dc774572becadca4834ae8a4f..5078e9278bf47b3d838593c459d1b3d7dfb928ee 100644 --- a/ee/spec/frontend/geo_node_form/store/actions_spec.js +++ b/ee/spec/frontend/geo_node_form/store/actions_spec.js @@ -5,6 +5,7 @@ import createState from 'ee/geo_node_form/store/state'; import testAction from 'helpers/vuex_action_helper'; import { createAlert } from '~/flash'; import axios from '~/lib/utils/axios_utils'; +import { HTTP_STATUS_INTERNAL_SERVER_ERROR, HTTP_STATUS_OK } from '~/lib/utils/http_status'; import { visitUrl } from '~/lib/utils/url_utility'; import { MOCK_SYNC_NAMESPACES, MOCK_NODE, MOCK_ERROR_MESSAGE, MOCK_NODES_PATH } from '../mock_data'; @@ -55,13 +56,13 @@ describe('GeoNodeForm Store Actions', () => { }); describe.each` - action | axiosMock | data | type | actionCalls - ${actions.fetchSyncNamespaces} | ${{ method: 'onGet', code: 200, res: MOCK_SYNC_NAMESPACES }} | ${null} | ${'success'} | ${[{ type: 'requestSyncNamespaces' }, { type: 'receiveSyncNamespacesSuccess', payload: MOCK_SYNC_NAMESPACES }]} - ${actions.fetchSyncNamespaces} | ${{ method: 'onGet', code: 500, res: null }} | ${null} | ${'error'} | ${[{ type: 'requestSyncNamespaces' }, { type: 'receiveSyncNamespacesError' }]} - ${actions.saveGeoNode} | ${{ method: 'onPost', code: 200, res: { ...MOCK_NODE, id: null } }} | ${{ ...MOCK_NODE, id: null }} | ${'success'} | ${[{ type: 'requestSaveGeoNode' }, { type: 'receiveSaveGeoNodeSuccess' }]} - ${actions.saveGeoNode} | ${{ method: 'onPost', code: 500, res: { message: MOCK_ERROR_MESSAGE } }} | ${{ ...MOCK_NODE, id: null }} | ${'error'} | ${[{ type: 'requestSaveGeoNode' }, { type: 'receiveSaveGeoNodeError', payload: { message: MOCK_ERROR_MESSAGE } }]} - ${actions.saveGeoNode} | ${{ method: 'onPut', code: 200, res: MOCK_NODE }} | ${MOCK_NODE} | ${'success'} | ${[{ type: 'requestSaveGeoNode' }, { type: 'receiveSaveGeoNodeSuccess' }]} - ${actions.saveGeoNode} | ${{ method: 'onPut', code: 500, res: { message: MOCK_ERROR_MESSAGE } }} | ${MOCK_NODE} | ${'error'} | ${[{ type: 'requestSaveGeoNode' }, { type: 'receiveSaveGeoNodeError', payload: { message: MOCK_ERROR_MESSAGE } }]} + action | axiosMock | data | type | actionCalls + ${actions.fetchSyncNamespaces} | ${{ method: 'onGet', code: HTTP_STATUS_OK, res: MOCK_SYNC_NAMESPACES }} | ${null} | ${'success'} | ${[{ type: 'requestSyncNamespaces' }, { type: 'receiveSyncNamespacesSuccess', payload: MOCK_SYNC_NAMESPACES }]} + ${actions.fetchSyncNamespaces} | ${{ method: 'onGet', code: HTTP_STATUS_INTERNAL_SERVER_ERROR, res: null }} | ${null} | ${'error'} | ${[{ type: 'requestSyncNamespaces' }, { type: 'receiveSyncNamespacesError' }]} + ${actions.saveGeoNode} | ${{ method: 'onPost', code: HTTP_STATUS_OK, res: { ...MOCK_NODE, id: null } }} | ${{ ...MOCK_NODE, id: null }} | ${'success'} | ${[{ type: 'requestSaveGeoNode' }, { type: 'receiveSaveGeoNodeSuccess' }]} + ${actions.saveGeoNode} | ${{ method: 'onPost', code: HTTP_STATUS_INTERNAL_SERVER_ERROR, res: { message: MOCK_ERROR_MESSAGE } }} | ${{ ...MOCK_NODE, id: null }} | ${'error'} | ${[{ type: 'requestSaveGeoNode' }, { type: 'receiveSaveGeoNodeError', payload: { message: MOCK_ERROR_MESSAGE } }]} + ${actions.saveGeoNode} | ${{ method: 'onPut', code: HTTP_STATUS_OK, res: MOCK_NODE }} | ${MOCK_NODE} | ${'success'} | ${[{ type: 'requestSaveGeoNode' }, { type: 'receiveSaveGeoNodeSuccess' }]} + ${actions.saveGeoNode} | ${{ method: 'onPut', code: HTTP_STATUS_INTERNAL_SERVER_ERROR, res: { message: MOCK_ERROR_MESSAGE } }} | ${MOCK_NODE} | ${'error'} | ${[{ type: 'requestSaveGeoNode' }, { type: 'receiveSaveGeoNodeError', payload: { message: MOCK_ERROR_MESSAGE } }]} `(`axios calls`, ({ action, axiosMock, data, type, actionCalls }) => { describe(action.name, () => { describe(`on ${type}`, () => { diff --git a/ee/spec/frontend/geo_settings/store/actions_spec.js b/ee/spec/frontend/geo_settings/store/actions_spec.js index 7cdf74e4daebe198a0b03153abd3500dc59a9061..4e71ba59079d1c2f50ac152f10a9c21854dda079 100644 --- a/ee/spec/frontend/geo_settings/store/actions_spec.js +++ b/ee/spec/frontend/geo_settings/store/actions_spec.js @@ -5,6 +5,7 @@ import state from 'ee/geo_settings/store/state'; import testAction from 'helpers/vuex_action_helper'; import { createAlert } from '~/flash'; import axios from '~/lib/utils/axios_utils'; +import { HTTP_STATUS_INTERNAL_SERVER_ERROR, HTTP_STATUS_OK } from '~/lib/utils/http_status'; import { MOCK_BASIC_SETTINGS_DATA, MOCK_APPLICATION_SETTINGS_FETCH_RESPONSE } from '../mock_data'; jest.mock('~/flash'); @@ -40,11 +41,11 @@ describe('GeoSettings Store Actions', () => { }); describe.each` - action | axiosMock | type | mutationCalls | callback - ${actions.fetchGeoSettings} | ${{ method: 'onGet', code: 200, res: MOCK_APPLICATION_SETTINGS_FETCH_RESPONSE }} | ${'success'} | ${[{ type: types.REQUEST_GEO_SETTINGS }, { type: types.RECEIVE_GEO_SETTINGS_SUCCESS, payload: MOCK_BASIC_SETTINGS_DATA }]} | ${noCallback} - ${actions.fetchGeoSettings} | ${{ method: 'onGet', code: 500, res: null }} | ${'error'} | ${[{ type: types.REQUEST_GEO_SETTINGS }, { type: types.RECEIVE_GEO_SETTINGS_ERROR }]} | ${flashCallback} - ${actions.updateGeoSettings} | ${{ method: 'onPut', code: 200, res: MOCK_APPLICATION_SETTINGS_FETCH_RESPONSE }} | ${'success'} | ${[{ type: types.REQUEST_UPDATE_GEO_SETTINGS }, { type: types.RECEIVE_UPDATE_GEO_SETTINGS_SUCCESS, payload: MOCK_BASIC_SETTINGS_DATA }]} | ${noCallback} - ${actions.updateGeoSettings} | ${{ method: 'onPut', code: 500, res: null }} | ${'error'} | ${[{ type: types.REQUEST_UPDATE_GEO_SETTINGS }, { type: types.RECEIVE_UPDATE_GEO_SETTINGS_ERROR }]} | ${flashCallback} + action | axiosMock | type | mutationCalls | callback + ${actions.fetchGeoSettings} | ${{ method: 'onGet', code: HTTP_STATUS_OK, res: MOCK_APPLICATION_SETTINGS_FETCH_RESPONSE }} | ${'success'} | ${[{ type: types.REQUEST_GEO_SETTINGS }, { type: types.RECEIVE_GEO_SETTINGS_SUCCESS, payload: MOCK_BASIC_SETTINGS_DATA }]} | ${noCallback} + ${actions.fetchGeoSettings} | ${{ method: 'onGet', code: HTTP_STATUS_INTERNAL_SERVER_ERROR, res: null }} | ${'error'} | ${[{ type: types.REQUEST_GEO_SETTINGS }, { type: types.RECEIVE_GEO_SETTINGS_ERROR }]} | ${flashCallback} + ${actions.updateGeoSettings} | ${{ method: 'onPut', code: HTTP_STATUS_OK, res: MOCK_APPLICATION_SETTINGS_FETCH_RESPONSE }} | ${'success'} | ${[{ type: types.REQUEST_UPDATE_GEO_SETTINGS }, { type: types.RECEIVE_UPDATE_GEO_SETTINGS_SUCCESS, payload: MOCK_BASIC_SETTINGS_DATA }]} | ${noCallback} + ${actions.updateGeoSettings} | ${{ method: 'onPut', code: HTTP_STATUS_INTERNAL_SERVER_ERROR, res: null }} | ${'error'} | ${[{ type: types.REQUEST_UPDATE_GEO_SETTINGS }, { type: types.RECEIVE_UPDATE_GEO_SETTINGS_ERROR }]} | ${flashCallback} `(`axios calls`, ({ action, axiosMock, type, mutationCalls, callback }) => { describe(action.name, () => { describe(`on ${type}`, () => { diff --git a/ee/spec/frontend/security_dashboard/store/modules/projects/actions_spec.js b/ee/spec/frontend/security_dashboard/store/modules/projects/actions_spec.js index c75c352617a2bfd6b8214dfb050575941442768e..8d11347003ffcf518dc25cf7e449dd7b52faf795 100644 --- a/ee/spec/frontend/security_dashboard/store/modules/projects/actions_spec.js +++ b/ee/spec/frontend/security_dashboard/store/modules/projects/actions_spec.js @@ -6,7 +6,11 @@ import testAction from 'helpers/vuex_action_helper'; import { TEST_HOST } from 'spec/test_constants'; import axios from '~/lib/utils/axios_utils'; -import { HTTP_STATUS_NOT_FOUND } from '~/lib/utils/http_status'; +import { + HTTP_STATUS_BAD_REQUEST, + HTTP_STATUS_NOT_FOUND, + HTTP_STATUS_OK, +} from '~/lib/utils/http_status'; import mockData from './data/mock_data.json'; describe('projects actions', () => { @@ -39,7 +43,7 @@ describe('projects actions', () => { (param) => config.params[param] === expectedParams[param], ); - return hasExpectedParams ? [200, data] : [400]; + return hasExpectedParams ? [HTTP_STATUS_OK, data] : [HTTP_STATUS_BAD_REQUEST]; }); }); @@ -64,9 +68,9 @@ describe('projects actions', () => { beforeEach(() => { mock .onGet(state.projectsEndpoint, { page: '1' }) - .replyOnce(200, [1], { 'x-next-page': '2' }); + .replyOnce(HTTP_STATUS_OK, [1], { 'x-next-page': '2' }); - mock.onGet(state.projectsEndpoint, { page: '2' }).replyOnce(200, [2]); + mock.onGet(state.projectsEndpoint, { page: '2' }).replyOnce(HTTP_STATUS_OK, [2]); }); it('should dispatch the request and success actions', async () => { diff --git a/spec/frontend/api/groups_api_spec.js b/spec/frontend/api/groups_api_spec.js index abd627dab100b3f06ca4636a2799267694b2bd73..0315db02cf2df9a14efa26de1c4ee1237779fca5 100644 --- a/spec/frontend/api/groups_api_spec.js +++ b/spec/frontend/api/groups_api_spec.js @@ -75,7 +75,7 @@ describe('GroupsApi', () => { const response = [{ id: 0, username: 'root' }]; - mock.onGet(expectedUrl).replyOnce(200, response); + mock.onGet(expectedUrl).replyOnce(HTTP_STATUS_OK, response); await expect(getGroupMembers(mockGroupId)).resolves.toMatchObject({ data: response, @@ -87,7 +87,7 @@ describe('GroupsApi', () => { const response = [{ id: 0, username: 'root' }]; - mock.onGet(expectedUrl).replyOnce(200, response); + mock.onGet(expectedUrl).replyOnce(HTTP_STATUS_OK, response); await expect(getGroupMembers(mockGroupId, true)).resolves.toMatchObject({ data: response, diff --git a/spec/frontend/api/projects_api_spec.js b/spec/frontend/api/projects_api_spec.js index a6ae8b14ea91b36664425f0553800a81eeabf5bf..2d4ed39dad01884910491f8ec6b0f973de3fc2cd 100644 --- a/spec/frontend/api/projects_api_spec.js +++ b/spec/frontend/api/projects_api_spec.js @@ -132,7 +132,7 @@ describe('~/api/projects_api.js', () => { const response = [{ id: 0, username: 'root' }]; - mock.onGet(expectedUrl).replyOnce(200, response); + mock.onGet(expectedUrl).replyOnce(HTTP_STATUS_OK, response); await expect(projectsApi.getProjectMembers(projectId)).resolves.toMatchObject({ data: response, @@ -144,7 +144,7 @@ describe('~/api/projects_api.js', () => { const response = [{ id: 0, username: 'root' }]; - mock.onGet(expectedUrl).replyOnce(200, response); + mock.onGet(expectedUrl).replyOnce(HTTP_STATUS_OK, response); await expect(projectsApi.getProjectMembers(projectId, true)).resolves.toMatchObject({ data: response, diff --git a/spec/frontend/environments/edit_environment_spec.js b/spec/frontend/environments/edit_environment_spec.js index 57545c565b4d40061d7627a38b7cb6bd8249d402..fb1a8b8c00ad637b663a2b978a3c725bfd683608 100644 --- a/spec/frontend/environments/edit_environment_spec.js +++ b/spec/frontend/environments/edit_environment_spec.js @@ -5,7 +5,7 @@ import waitForPromises from 'helpers/wait_for_promises'; import EditEnvironment from '~/environments/components/edit_environment.vue'; import { createAlert } from '~/flash'; import axios from '~/lib/utils/axios_utils'; -import { HTTP_STATUS_OK } from '~/lib/utils/http_status'; +import { HTTP_STATUS_BAD_REQUEST, HTTP_STATUS_OK } from '~/lib/utils/http_status'; import { visitUrl } from '~/lib/utils/url_utility'; jest.mock('~/lib/utils/url_utility'); @@ -85,7 +85,7 @@ describe('~/environments/components/edit.vue', () => { it('shows errors on error', async () => { const expected = { url: 'https://google.ca' }; - await submitForm(expected, [400, { message: ['uh oh!'] }]); + await submitForm(expected, [HTTP_STATUS_BAD_REQUEST, { message: ['uh oh!'] }]); expect(createAlert).toHaveBeenCalledWith({ message: 'uh oh!' }); expect(showsLoading()).toBe(false); diff --git a/spec/frontend/environments/environments_folder_view_spec.js b/spec/frontend/environments/environments_folder_view_spec.js index 72a7449f24e962652369a09ffced0abeedc8f385..a87060f83d87d2401db7cb747da7d5916a541db2 100644 --- a/spec/frontend/environments/environments_folder_view_spec.js +++ b/spec/frontend/environments/environments_folder_view_spec.js @@ -2,6 +2,7 @@ import { mount } from '@vue/test-utils'; import MockAdapter from 'axios-mock-adapter'; import EnvironmentsFolderViewComponent from '~/environments/folder/environments_folder_view.vue'; import axios from '~/lib/utils/axios_utils'; +import { HTTP_STATUS_OK } from '~/lib/utils/http_status'; import { environmentsList } from './mock_data'; describe('Environments Folder View', () => { @@ -29,7 +30,7 @@ describe('Environments Folder View', () => { describe('successful request', () => { beforeEach(() => { mock.onGet(mockData.endpoint).reply( - 200, + HTTP_STATUS_OK, { environments: environmentsList, stopped_count: 1, diff --git a/spec/frontend/environments/folder/environments_folder_view_spec.js b/spec/frontend/environments/folder/environments_folder_view_spec.js index 9c1f463ec3f968e3060acea512e159f853ce7838..ac9d857e6bdbef4f2d8bf85d750040be35dbc78a 100644 --- a/spec/frontend/environments/folder/environments_folder_view_spec.js +++ b/spec/frontend/environments/folder/environments_folder_view_spec.js @@ -5,7 +5,7 @@ import { removeBreakLine, removeWhitespace } from 'helpers/text_helper'; import EnvironmentTable from '~/environments/components/environments_table.vue'; import EnvironmentsFolderViewComponent from '~/environments/folder/environments_folder_view.vue'; import axios from '~/lib/utils/axios_utils'; -import { HTTP_STATUS_INTERNAL_SERVER_ERROR } from '~/lib/utils/http_status'; +import { HTTP_STATUS_INTERNAL_SERVER_ERROR, HTTP_STATUS_OK } from '~/lib/utils/http_status'; import { environmentsList } from '../mock_data'; describe('Environments Folder View', () => { @@ -23,7 +23,7 @@ describe('Environments Folder View', () => { const mockEnvironments = (environmentList) => { mock.onGet(mockData.endpoint).reply( - 200, + HTTP_STATUS_OK, { environments: environmentList, stopped_count: 1, diff --git a/spec/frontend/environments/new_environment_spec.js b/spec/frontend/environments/new_environment_spec.js index 016d957109423b4702c7ff57af5ec96b4cb8381a..a8cc05b297b9e8fc73606f7fc2361a3fabdc5102 100644 --- a/spec/frontend/environments/new_environment_spec.js +++ b/spec/frontend/environments/new_environment_spec.js @@ -5,7 +5,7 @@ import waitForPromises from 'helpers/wait_for_promises'; import NewEnvironment from '~/environments/components/new_environment.vue'; import { createAlert } from '~/flash'; import axios from '~/lib/utils/axios_utils'; -import { HTTP_STATUS_OK } from '~/lib/utils/http_status'; +import { HTTP_STATUS_BAD_REQUEST, HTTP_STATUS_OK } from '~/lib/utils/http_status'; import { visitUrl } from '~/lib/utils/url_utility'; jest.mock('~/lib/utils/url_utility'); @@ -96,7 +96,7 @@ describe('~/environments/components/new.vue', () => { it('shows errors on error', async () => { const expected = { name: 'test', url: 'https://google.ca' }; - await submitForm(expected, [400, { message: ['name taken'] }]); + await submitForm(expected, [HTTP_STATUS_BAD_REQUEST, { message: ['name taken'] }]); expect(createAlert).toHaveBeenCalledWith({ message: 'name taken' }); expect(showsLoading()).toBe(false); diff --git a/spec/frontend/error_tracking_settings/store/actions_spec.js b/spec/frontend/error_tracking_settings/store/actions_spec.js index bad2bdfaa1ae19d097f55b71a33979e4661d20ea..d8f61be6df7159226b9edf1f833658e466f0322b 100644 --- a/spec/frontend/error_tracking_settings/store/actions_spec.js +++ b/spec/frontend/error_tracking_settings/store/actions_spec.js @@ -47,7 +47,7 @@ describe('error tracking settings actions', () => { }); it('should handle a server error', async () => { - mock.onGet(`${TEST_HOST}.json`).reply(() => [400]); + mock.onGet(`${TEST_HOST}.json`).reply(() => [HTTP_STATUS_BAD_REQUEST]); await testAction( actions.fetchProjects, null, diff --git a/spec/frontend/gfm_auto_complete_spec.js b/spec/frontend/gfm_auto_complete_spec.js index cc2dc084e4705bbaa4974a776be4102ba8fa9786..e4fd8649263944c1aa03641640678a85b1332a82 100644 --- a/spec/frontend/gfm_auto_complete_spec.js +++ b/spec/frontend/gfm_auto_complete_spec.js @@ -17,6 +17,7 @@ import { TEST_HOST } from 'helpers/test_constants'; import waitForPromises from 'helpers/wait_for_promises'; import AjaxCache from '~/lib/utils/ajax_cache'; import axios from '~/lib/utils/axios_utils'; +import { HTTP_STATUS_INTERNAL_SERVER_ERROR, HTTP_STATUS_OK } from '~/lib/utils/http_status'; import { eventlistenersMockDefaultMap, crmContactsMock, @@ -184,17 +185,20 @@ describe('GfmAutoComplete', () => { }); }); - it.each([200, 500])('should set the loading state', async (responseStatus) => { - mock.onGet('vulnerabilities_autocomplete_url').replyOnce(responseStatus); + it.each([HTTP_STATUS_OK, HTTP_STATUS_INTERNAL_SERVER_ERROR])( + 'should set the loading state', + async (responseStatus) => { + mock.onGet('vulnerabilities_autocomplete_url').replyOnce(responseStatus); - fetchData.call(context, {}, '[vulnerability:', 'query'); + fetchData.call(context, {}, '[vulnerability:', 'query'); - expect(context.isLoadingData['[vulnerability:']).toBe(true); + expect(context.isLoadingData['[vulnerability:']).toBe(true); - await waitForPromises(); + await waitForPromises(); - expect(context.isLoadingData['[vulnerability:']).toBe(false); - }); + expect(context.isLoadingData['[vulnerability:']).toBe(false); + }, + ); }); describe('data is in cache', () => { diff --git a/spec/frontend/header_search/store/actions_spec.js b/spec/frontend/header_search/store/actions_spec.js index 1ae149128ca836d93f29ac767bc77f493adac656..bd93b0edadf15ebe9f6819c59d5c5ed2cd66b9a5 100644 --- a/spec/frontend/header_search/store/actions_spec.js +++ b/spec/frontend/header_search/store/actions_spec.js @@ -4,6 +4,7 @@ import * as actions from '~/header_search/store/actions'; import * as types from '~/header_search/store/mutation_types'; import initState from '~/header_search/store/state'; import axios from '~/lib/utils/axios_utils'; +import { HTTP_STATUS_INTERNAL_SERVER_ERROR, HTTP_STATUS_OK } from '~/lib/utils/http_status'; import { MOCK_SEARCH, MOCK_AUTOCOMPLETE_OPTIONS_RES, @@ -37,9 +38,9 @@ describe('Header Search Store Actions', () => { }); describe.each` - axiosMock | type | expectedMutations - ${{ method: 'onGet', code: 200, res: MOCK_AUTOCOMPLETE_OPTIONS_RES }} | ${'success'} | ${[{ type: types.REQUEST_AUTOCOMPLETE }, { type: types.RECEIVE_AUTOCOMPLETE_SUCCESS, payload: MOCK_AUTOCOMPLETE_OPTIONS_RES }, { type: types.RECEIVE_AUTOCOMPLETE_SUCCESS, payload: MOCK_AUTOCOMPLETE_OPTIONS_RES }]} - ${{ method: 'onGet', code: 500, res: null }} | ${'error'} | ${[{ type: types.REQUEST_AUTOCOMPLETE }, { type: types.RECEIVE_AUTOCOMPLETE_ERROR }, { type: types.RECEIVE_AUTOCOMPLETE_ERROR }]} + axiosMock | type | expectedMutations + ${{ method: 'onGet', code: HTTP_STATUS_OK, res: MOCK_AUTOCOMPLETE_OPTIONS_RES }} | ${'success'} | ${[{ type: types.REQUEST_AUTOCOMPLETE }, { type: types.RECEIVE_AUTOCOMPLETE_SUCCESS, payload: MOCK_AUTOCOMPLETE_OPTIONS_RES }, { type: types.RECEIVE_AUTOCOMPLETE_SUCCESS, payload: MOCK_AUTOCOMPLETE_OPTIONS_RES }]} + ${{ method: 'onGet', code: HTTP_STATUS_INTERNAL_SERVER_ERROR, res: null }} | ${'error'} | ${[{ type: types.REQUEST_AUTOCOMPLETE }, { type: types.RECEIVE_AUTOCOMPLETE_ERROR }, { type: types.RECEIVE_AUTOCOMPLETE_ERROR }]} `('fetchAutocompleteOptions', ({ axiosMock, type, expectedMutations }) => { describe(`on ${type}`, () => { beforeEach(() => { diff --git a/spec/frontend/performance_bar/index_spec.js b/spec/frontend/performance_bar/index_spec.js index 2da176dbfe49bad7e9d2d8b297e63ede112f6187..f09b0cc3df818b7cdbf8ea24b557e51a930bc8be 100644 --- a/spec/frontend/performance_bar/index_spec.js +++ b/spec/frontend/performance_bar/index_spec.js @@ -1,6 +1,7 @@ import MockAdapter from 'axios-mock-adapter'; import { setHTMLFixture, resetHTMLFixture } from 'helpers/fixtures'; import axios from '~/lib/utils/axios_utils'; +import { HTTP_STATUS_OK } from '~/lib/utils/http_status'; import '~/performance_bar/components/performance_bar_app.vue'; import performanceBar from '~/performance_bar'; import PerformanceBarService from '~/performance_bar/services/performance_bar_service'; @@ -26,7 +27,7 @@ describe('performance bar wrapper', () => { mock = new MockAdapter(axios); mock.onGet('/-/peek/results').reply( - 200, + HTTP_STATUS_OK, { data: { gc: { diff --git a/spec/frontend/profile/account/components/update_username_spec.js b/spec/frontend/profile/account/components/update_username_spec.js index bb9ae01963e4303d10103780547a32c6b0742def..fa0e86a7b05cea17348859f1cd441dc1cdd5213f 100644 --- a/spec/frontend/profile/account/components/update_username_spec.js +++ b/spec/frontend/profile/account/components/update_username_spec.js @@ -5,7 +5,7 @@ import { nextTick } from 'vue'; import { TEST_HOST } from 'helpers/test_constants'; import { createAlert } from '~/flash'; import axios from '~/lib/utils/axios_utils'; -import { HTTP_STATUS_OK } from '~/lib/utils/http_status'; +import { HTTP_STATUS_BAD_REQUEST, HTTP_STATUS_OK } from '~/lib/utils/http_status'; import UpdateUsername from '~/profile/account/components/update_username.vue'; jest.mock('~/flash'); @@ -133,7 +133,7 @@ describe('UpdateUsername component', () => { expect(openModalBtn.props('disabled')).toBe(false); expect(openModalBtn.props('loading')).toBe(true); - return [400, { message: 'Invalid username' }]; + return [HTTP_STATUS_BAD_REQUEST, { message: 'Invalid username' }]; }); await expect(wrapper.vm.onConfirm()).rejects.toThrow(); @@ -144,7 +144,7 @@ describe('UpdateUsername component', () => { it('shows an error message if the error response has a `message` property', async () => { axiosMock.onPut(actionUrl).replyOnce(() => { - return [400, { message: 'Invalid username' }]; + return [HTTP_STATUS_BAD_REQUEST, { message: 'Invalid username' }]; }); await expect(wrapper.vm.onConfirm()).rejects.toThrow(); @@ -156,7 +156,7 @@ describe('UpdateUsername component', () => { it("shows a fallback error message if the error response doesn't have a `message` property", async () => { axiosMock.onPut(actionUrl).replyOnce(() => { - return [400]; + return [HTTP_STATUS_BAD_REQUEST]; }); await expect(wrapper.vm.onConfirm()).rejects.toThrow(); diff --git a/spec/frontend/projects/project_find_file_spec.js b/spec/frontend/projects/project_find_file_spec.js index eec54dd04bc29f4020eba08eee110d405f000075..efc9d411a982c5a60f3e77ae4c0f97975d00a979 100644 --- a/spec/frontend/projects/project_find_file_spec.js +++ b/spec/frontend/projects/project_find_file_spec.js @@ -4,6 +4,7 @@ import { TEST_HOST } from 'helpers/test_constants'; import waitForPromises from 'helpers/wait_for_promises'; import { sanitize } from '~/lib/dompurify'; import axios from '~/lib/utils/axios_utils'; +import { HTTP_STATUS_OK } from '~/lib/utils/http_status'; import ProjectFindFile from '~/projects/project_find_file'; jest.mock('~/lib/dompurify', () => ({ @@ -60,7 +61,7 @@ describe('ProjectFindFile', () => { element = $(TEMPLATE); mock.onGet(FILE_FIND_URL).replyOnce( - 200, + HTTP_STATUS_OK, files.map((x) => x.path), ); getProjectFindFileInstance(); // This triggers a load / axios call + subsequent render in the constructor diff --git a/spec/frontend/search/store/actions_spec.js b/spec/frontend/search/store/actions_spec.js index 041679e913952e9ed9ab6425c2d11499625d4346..2f87802dfe6258d01e791c522ab2983667f90fb0 100644 --- a/spec/frontend/search/store/actions_spec.js +++ b/spec/frontend/search/store/actions_spec.js @@ -4,6 +4,7 @@ import Api from '~/api'; import { createAlert } from '~/flash'; import * as logger from '~/lib/logger'; import axios from '~/lib/utils/axios_utils'; +import { HTTP_STATUS_INTERNAL_SERVER_ERROR, HTTP_STATUS_OK } from '~/lib/utils/http_status'; import * as urlUtils from '~/lib/utils/url_utility'; import * as actions from '~/search/store/actions'; import { @@ -62,11 +63,11 @@ describe('Global Search Store Actions', () => { }); describe.each` - action | axiosMock | type | expectedMutations | flashCallCount - ${actions.fetchGroups} | ${{ method: 'onGet', code: 200, res: MOCK_GROUPS }} | ${'success'} | ${[{ type: types.REQUEST_GROUPS }, { type: types.RECEIVE_GROUPS_SUCCESS, payload: MOCK_GROUPS }]} | ${0} - ${actions.fetchGroups} | ${{ method: 'onGet', code: 500, res: null }} | ${'error'} | ${[{ type: types.REQUEST_GROUPS }, { type: types.RECEIVE_GROUPS_ERROR }]} | ${1} - ${actions.fetchProjects} | ${{ method: 'onGet', code: 200, res: MOCK_PROJECTS }} | ${'success'} | ${[{ type: types.REQUEST_PROJECTS }, { type: types.RECEIVE_PROJECTS_SUCCESS, payload: MOCK_PROJECTS }]} | ${0} - ${actions.fetchProjects} | ${{ method: 'onGet', code: 500, res: null }} | ${'error'} | ${[{ type: types.REQUEST_PROJECTS }, { type: types.RECEIVE_PROJECTS_ERROR }]} | ${1} + action | axiosMock | type | expectedMutations | flashCallCount + ${actions.fetchGroups} | ${{ method: 'onGet', code: HTTP_STATUS_OK, res: MOCK_GROUPS }} | ${'success'} | ${[{ type: types.REQUEST_GROUPS }, { type: types.RECEIVE_GROUPS_SUCCESS, payload: MOCK_GROUPS }]} | ${0} + ${actions.fetchGroups} | ${{ method: 'onGet', code: HTTP_STATUS_INTERNAL_SERVER_ERROR, res: null }} | ${'error'} | ${[{ type: types.REQUEST_GROUPS }, { type: types.RECEIVE_GROUPS_ERROR }]} | ${1} + ${actions.fetchProjects} | ${{ method: 'onGet', code: HTTP_STATUS_OK, res: MOCK_PROJECTS }} | ${'success'} | ${[{ type: types.REQUEST_PROJECTS }, { type: types.RECEIVE_PROJECTS_SUCCESS, payload: MOCK_PROJECTS }]} | ${0} + ${actions.fetchProjects} | ${{ method: 'onGet', code: HTTP_STATUS_INTERNAL_SERVER_ERROR, res: null }} | ${'error'} | ${[{ type: types.REQUEST_PROJECTS }, { type: types.RECEIVE_PROJECTS_ERROR }]} | ${1} `(`axios calls`, ({ action, axiosMock, type, expectedMutations, flashCallCount }) => { describe(action.name, () => { describe(`on ${type}`, () => { @@ -83,11 +84,11 @@ describe('Global Search Store Actions', () => { }); describe.each` - action | axiosMock | type | expectedMutations | flashCallCount - ${actions.loadFrequentGroups} | ${{ method: 'onGet', code: 200 }} | ${'success'} | ${[PROMISE_ALL_EXPECTED_MUTATIONS.resGroups]} | ${0} - ${actions.loadFrequentGroups} | ${{ method: 'onGet', code: 500 }} | ${'error'} | ${[]} | ${1} - ${actions.loadFrequentProjects} | ${{ method: 'onGet', code: 200 }} | ${'success'} | ${[PROMISE_ALL_EXPECTED_MUTATIONS.resProjects]} | ${0} - ${actions.loadFrequentProjects} | ${{ method: 'onGet', code: 500 }} | ${'error'} | ${[]} | ${1} + action | axiosMock | type | expectedMutations | flashCallCount + ${actions.loadFrequentGroups} | ${{ method: 'onGet', code: HTTP_STATUS_OK }} | ${'success'} | ${[PROMISE_ALL_EXPECTED_MUTATIONS.resGroups]} | ${0} + ${actions.loadFrequentGroups} | ${{ method: 'onGet', code: HTTP_STATUS_INTERNAL_SERVER_ERROR }} | ${'error'} | ${[]} | ${1} + ${actions.loadFrequentProjects} | ${{ method: 'onGet', code: HTTP_STATUS_OK }} | ${'success'} | ${[PROMISE_ALL_EXPECTED_MUTATIONS.resProjects]} | ${0} + ${actions.loadFrequentProjects} | ${{ method: 'onGet', code: HTTP_STATUS_INTERNAL_SERVER_ERROR }} | ${'error'} | ${[]} | ${1} `('Promise.all calls', ({ action, axiosMock, type, expectedMutations, flashCallCount }) => { describe(action.name, () => { describe(`on ${type}`, () => { @@ -272,10 +273,10 @@ describe('Global Search Store Actions', () => { }); describe.each` - action | axiosMock | type | scope | expectedMutations | errorLogs - ${actions.fetchSidebarCount} | ${{ method: 'onGet', code: 200 }} | ${'success'} | ${'issues'} | ${[MOCK_NAVIGATION_ACTION_MUTATION]} | ${0} - ${actions.fetchSidebarCount} | ${{ method: null, code: 0 }} | ${'success'} | ${'projects'} | ${[]} | ${0} - ${actions.fetchSidebarCount} | ${{ method: 'onGet', code: 500 }} | ${'error'} | ${'issues'} | ${[]} | ${1} + action | axiosMock | type | scope | expectedMutations | errorLogs + ${actions.fetchSidebarCount} | ${{ method: 'onGet', code: HTTP_STATUS_OK }} | ${'success'} | ${'issues'} | ${[MOCK_NAVIGATION_ACTION_MUTATION]} | ${0} + ${actions.fetchSidebarCount} | ${{ method: null, code: 0 }} | ${'success'} | ${'projects'} | ${[]} | ${0} + ${actions.fetchSidebarCount} | ${{ method: 'onGet', code: HTTP_STATUS_INTERNAL_SERVER_ERROR }} | ${'error'} | ${'issues'} | ${[]} | ${1} `('fetchSidebarCount', ({ action, axiosMock, type, expectedMutations, scope, errorLogs }) => { describe(`on ${type}`, () => { beforeEach(() => { @@ -300,17 +301,17 @@ describe('Global Search Store Actions', () => { }); describe.each` - action | axiosMock | type | expectedMutations | errorLogs - ${actions.fetchLanguageAggregation} | ${{ method: 'onGet', code: 200 }} | ${'success'} | ${MOCK_RECEIVE_AGGREGATIONS_SUCCESS_MUTATION} | ${0} - ${actions.fetchLanguageAggregation} | ${{ method: 'onPut', code: 0 }} | ${'error'} | ${MOCK_RECEIVE_AGGREGATIONS_ERROR_MUTATION} | ${1} - ${actions.fetchLanguageAggregation} | ${{ method: 'onGet', code: 500 }} | ${'error'} | ${MOCK_RECEIVE_AGGREGATIONS_ERROR_MUTATION} | ${1} + action | axiosMock | type | expectedMutations | errorLogs + ${actions.fetchLanguageAggregation} | ${{ method: 'onGet', code: HTTP_STATUS_OK }} | ${'success'} | ${MOCK_RECEIVE_AGGREGATIONS_SUCCESS_MUTATION} | ${0} + ${actions.fetchLanguageAggregation} | ${{ method: 'onPut', code: 0 }} | ${'error'} | ${MOCK_RECEIVE_AGGREGATIONS_ERROR_MUTATION} | ${1} + ${actions.fetchLanguageAggregation} | ${{ method: 'onGet', code: HTTP_STATUS_INTERNAL_SERVER_ERROR }} | ${'error'} | ${MOCK_RECEIVE_AGGREGATIONS_ERROR_MUTATION} | ${1} `('fetchLanguageAggregation', ({ action, axiosMock, type, expectedMutations, errorLogs }) => { describe(`on ${type}`, () => { beforeEach(() => { if (axiosMock.method) { mock[axiosMock.method]().reply( axiosMock.code, - axiosMock.code === 200 ? MOCK_AGGREGATIONS : [], + axiosMock.code === HTTP_STATUS_OK ? MOCK_AGGREGATIONS : [], ); } }); diff --git a/spec/frontend/vue_shared/components/markdown_drawer/utils/fetch_spec.js b/spec/frontend/vue_shared/components/markdown_drawer/utils/fetch_spec.js index adcf57b76a44ee9f4231be3ec55a0a258c8f383b..c1e61f6e43d2bf4c8733075c723dd5fb3bcd8d87 100644 --- a/spec/frontend/vue_shared/components/markdown_drawer/utils/fetch_spec.js +++ b/spec/frontend/vue_shared/components/markdown_drawer/utils/fetch_spec.js @@ -4,6 +4,7 @@ import { splitDocument, } from '~/vue_shared/components/markdown_drawer/utils/fetch'; import axios from '~/lib/utils/axios_utils'; +import { HTTP_STATUS_INTERNAL_SERVER_ERROR, HTTP_STATUS_OK } from '~/lib/utils/http_status'; import { MOCK_HTML, MOCK_DRAWER_DATA, @@ -20,9 +21,9 @@ describe('utils/fetch', () => { }); describe.each` - axiosMock | type | toExpect - ${{ code: 200, res: MOCK_HTML }} | ${'success'} | ${MOCK_DRAWER_DATA} - ${{ code: 500, res: null }} | ${'error'} | ${MOCK_DRAWER_DATA_ERROR} + axiosMock | type | toExpect + ${{ code: HTTP_STATUS_OK, res: MOCK_HTML }} | ${'success'} | ${MOCK_DRAWER_DATA} + ${{ code: HTTP_STATUS_INTERNAL_SERVER_ERROR, res: null }} | ${'error'} | ${MOCK_DRAWER_DATA_ERROR} `('process markdown data', ({ axiosMock, type, toExpect }) => { describe(`if api fetch responds with ${type}`, () => { beforeEach(() => {