diff options
Diffstat (limited to 'spec/frontend/reports/codequality_report/store/actions_spec.js')
-rw-r--r-- | spec/frontend/reports/codequality_report/store/actions_spec.js | 173 |
1 files changed, 116 insertions, 57 deletions
diff --git a/spec/frontend/reports/codequality_report/store/actions_spec.js b/spec/frontend/reports/codequality_report/store/actions_spec.js index 321785cb85a..a2b256448ef 100644 --- a/spec/frontend/reports/codequality_report/store/actions_spec.js +++ b/spec/frontend/reports/codequality_report/store/actions_spec.js @@ -1,11 +1,18 @@ import MockAdapter from 'axios-mock-adapter'; -import { TEST_HOST } from 'spec/test_constants'; import testAction from 'helpers/vuex_action_helper'; +import { TEST_HOST } from 'spec/test_constants'; import axios from '~/lib/utils/axios_utils'; +import createStore from '~/reports/codequality_report/store'; import * as actions from '~/reports/codequality_report/store/actions'; import * as types from '~/reports/codequality_report/store/mutation_types'; -import createStore from '~/reports/codequality_report/store'; -import { headIssues, baseIssues, mockParsedHeadIssues, mockParsedBaseIssues } from '../mock_data'; +import { + headIssues, + baseIssues, + mockParsedHeadIssues, + mockParsedBaseIssues, + reportIssues, + parsedReportIssues, +} from '../mock_data'; // mock codequality comparison worker jest.mock('~/reports/codequality_report/workers/codequality_comparison_worker', () => @@ -39,6 +46,7 @@ describe('Codequality Reports actions', () => { headPath: 'headPath', baseBlobPath: 'baseBlobPath', headBlobPath: 'headBlobPath', + reportsPath: 'reportsPath', helpPath: 'codequalityHelpPath', }; @@ -55,68 +63,119 @@ describe('Codequality Reports actions', () => { describe('fetchReports', () => { let mock; + let diffFeatureFlagEnabled; - beforeEach(() => { - localState.headPath = `${TEST_HOST}/head.json`; - localState.basePath = `${TEST_HOST}/base.json`; - mock = new MockAdapter(axios); - }); + describe('with codequalityBackendComparison feature flag enabled', () => { + beforeEach(() => { + diffFeatureFlagEnabled = true; + localState.reportsPath = `${TEST_HOST}/codequality_reports.json`; + mock = new MockAdapter(axios); + }); - afterEach(() => { - mock.restore(); - }); + afterEach(() => { + mock.restore(); + }); - describe('on success', () => { - it('commits REQUEST_REPORTS and dispatches receiveReportsSuccess', (done) => { - mock.onGet(`${TEST_HOST}/head.json`).reply(200, headIssues); - mock.onGet(`${TEST_HOST}/base.json`).reply(200, baseIssues); - - testAction( - actions.fetchReports, - null, - localState, - [{ type: types.REQUEST_REPORTS }], - [ - { - payload: { - newIssues: [mockParsedHeadIssues[0]], - resolvedIssues: [mockParsedBaseIssues[0]], + describe('on success', () => { + it('commits REQUEST_REPORTS and dispatches receiveReportsSuccess', (done) => { + mock.onGet(`${TEST_HOST}/codequality_reports.json`).reply(200, reportIssues); + + testAction( + actions.fetchReports, + diffFeatureFlagEnabled, + localState, + [{ type: types.REQUEST_REPORTS }], + [ + { + payload: parsedReportIssues, + type: 'receiveReportsSuccess', }, - type: 'receiveReportsSuccess', - }, - ], - done, - ); + ], + done, + ); + }); }); - }); - describe('on error', () => { - it('commits REQUEST_REPORTS and dispatches receiveReportsError', (done) => { - mock.onGet(`${TEST_HOST}/head.json`).reply(500); - - testAction( - actions.fetchReports, - null, - localState, - [{ type: types.REQUEST_REPORTS }], - [{ type: 'receiveReportsError' }], - done, - ); + describe('on error', () => { + it('commits REQUEST_REPORTS and dispatches receiveReportsError', (done) => { + mock.onGet(`${TEST_HOST}/codequality_reports.json`).reply(500); + + testAction( + actions.fetchReports, + diffFeatureFlagEnabled, + localState, + [{ type: types.REQUEST_REPORTS }], + [{ type: 'receiveReportsError', payload: expect.any(Error) }], + done, + ); + }); }); }); - describe('with no base path', () => { - it('commits REQUEST_REPORTS and dispatches receiveReportsError', (done) => { - localState.basePath = null; - - testAction( - actions.fetchReports, - null, - localState, - [{ type: types.REQUEST_REPORTS }], - [{ type: 'receiveReportsError' }], - done, - ); + describe('with codequalityBackendComparison feature flag disabled', () => { + beforeEach(() => { + diffFeatureFlagEnabled = false; + localState.headPath = `${TEST_HOST}/head.json`; + localState.basePath = `${TEST_HOST}/base.json`; + mock = new MockAdapter(axios); + }); + + afterEach(() => { + mock.restore(); + }); + + describe('on success', () => { + it('commits REQUEST_REPORTS and dispatches receiveReportsSuccess', (done) => { + mock.onGet(`${TEST_HOST}/head.json`).reply(200, headIssues); + mock.onGet(`${TEST_HOST}/base.json`).reply(200, baseIssues); + + testAction( + actions.fetchReports, + diffFeatureFlagEnabled, + localState, + [{ type: types.REQUEST_REPORTS }], + [ + { + payload: { + newIssues: [mockParsedHeadIssues[0]], + resolvedIssues: [mockParsedBaseIssues[0]], + }, + type: 'receiveReportsSuccess', + }, + ], + done, + ); + }); + }); + + describe('on error', () => { + it('commits REQUEST_REPORTS and dispatches receiveReportsError', (done) => { + mock.onGet(`${TEST_HOST}/head.json`).reply(500); + + testAction( + actions.fetchReports, + diffFeatureFlagEnabled, + localState, + [{ type: types.REQUEST_REPORTS }], + [{ type: 'receiveReportsError', payload: expect.any(Error) }], + done, + ); + }); + }); + + describe('with no base path', () => { + it('commits REQUEST_REPORTS and dispatches receiveReportsError', (done) => { + localState.basePath = null; + + testAction( + actions.fetchReports, + diffFeatureFlagEnabled, + localState, + [{ type: types.REQUEST_REPORTS }], + [{ type: 'receiveReportsError' }], + done, + ); + }); }); }); }); @@ -142,7 +201,7 @@ describe('Codequality Reports actions', () => { actions.receiveReportsError, null, localState, - [{ type: types.RECEIVE_REPORTS_ERROR }], + [{ type: types.RECEIVE_REPORTS_ERROR, payload: null }], [], done, ); |