Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/frontend/reports/codequality_report/store')
-rw-r--r--spec/frontend/reports/codequality_report/store/actions_spec.js183
-rw-r--r--spec/frontend/reports/codequality_report/store/mutations_spec.js12
-rw-r--r--spec/frontend/reports/codequality_report/store/utils/codequality_comparison_spec.js153
-rw-r--r--spec/frontend/reports/codequality_report/store/utils/codequality_parser_spec.js74
4 files changed, 128 insertions, 294 deletions
diff --git a/spec/frontend/reports/codequality_report/store/actions_spec.js b/spec/frontend/reports/codequality_report/store/actions_spec.js
index a2b256448ef..1b83d071d17 100644
--- a/spec/frontend/reports/codequality_report/store/actions_spec.js
+++ b/spec/frontend/reports/codequality_report/store/actions_spec.js
@@ -5,30 +5,7 @@ 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 {
- headIssues,
- baseIssues,
- mockParsedHeadIssues,
- mockParsedBaseIssues,
- reportIssues,
- parsedReportIssues,
-} from '../mock_data';
-
-// mock codequality comparison worker
-jest.mock('~/reports/codequality_report/workers/codequality_comparison_worker', () =>
- jest.fn().mockImplementation(() => {
- return {
- addEventListener: (eventName, callback) => {
- callback({
- data: {
- newIssues: [mockParsedHeadIssues[0]],
- resolvedIssues: [mockParsedBaseIssues[0]],
- },
- });
- },
- };
- }),
-);
+import { reportIssues, parsedReportIssues } from '../mock_data';
describe('Codequality Reports actions', () => {
let localState;
@@ -43,9 +20,6 @@ describe('Codequality Reports actions', () => {
it('should commit SET_PATHS mutation', (done) => {
const paths = {
basePath: 'basePath',
- headPath: 'headPath',
- baseBlobPath: 'baseBlobPath',
- headBlobPath: 'headBlobPath',
reportsPath: 'reportsPath',
helpPath: 'codequalityHelpPath',
};
@@ -63,119 +37,64 @@ describe('Codequality Reports actions', () => {
describe('fetchReports', () => {
let mock;
- let diffFeatureFlagEnabled;
- describe('with codequalityBackendComparison feature flag enabled', () => {
- beforeEach(() => {
- diffFeatureFlagEnabled = true;
- localState.reportsPath = `${TEST_HOST}/codequality_reports.json`;
- mock = new MockAdapter(axios);
- });
-
- afterEach(() => {
- mock.restore();
- });
-
- 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',
- },
- ],
- 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,
- );
- });
- });
+ beforeEach(() => {
+ localState.reportsPath = `${TEST_HOST}/codequality_reports.json`;
+ localState.basePath = '/base/path';
+ mock = new MockAdapter(axios);
});
- 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();
- });
+ 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 success', () => {
+ it('commits REQUEST_REPORTS and dispatches receiveReportsSuccess', (done) => {
+ mock.onGet(`${TEST_HOST}/codequality_reports.json`).reply(200, reportIssues);
+
+ testAction(
+ actions.fetchReports,
+ null,
+ localState,
+ [{ type: types.REQUEST_REPORTS }],
+ [
+ {
+ payload: parsedReportIssues,
+ 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('on error', () => {
+ it('commits REQUEST_REPORTS and dispatches receiveReportsError', (done) => {
+ mock.onGet(`${TEST_HOST}/codequality_reports.json`).reply(500);
+
+ testAction(
+ actions.fetchReports,
+ null,
+ 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,
- );
- });
+ 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,
+ );
});
});
});
diff --git a/spec/frontend/reports/codequality_report/store/mutations_spec.js b/spec/frontend/reports/codequality_report/store/mutations_spec.js
index 05a16cd6f82..9d4c05afd36 100644
--- a/spec/frontend/reports/codequality_report/store/mutations_spec.js
+++ b/spec/frontend/reports/codequality_report/store/mutations_spec.js
@@ -13,23 +13,17 @@ describe('Codequality Reports mutations', () => {
describe('SET_PATHS', () => {
it('sets paths to given values', () => {
const basePath = 'base.json';
- const headPath = 'head.json';
- const baseBlobPath = 'base/blob/path/';
- const headBlobPath = 'head/blob/path/';
+ const reportsPath = 'reports.json';
const helpPath = 'help.html';
mutations.SET_PATHS(localState, {
basePath,
- headPath,
- baseBlobPath,
- headBlobPath,
+ reportsPath,
helpPath,
});
expect(localState.basePath).toEqual(basePath);
- expect(localState.headPath).toEqual(headPath);
- expect(localState.baseBlobPath).toEqual(baseBlobPath);
- expect(localState.headBlobPath).toEqual(headBlobPath);
+ expect(localState.reportsPath).toEqual(reportsPath);
expect(localState.helpPath).toEqual(helpPath);
});
});
diff --git a/spec/frontend/reports/codequality_report/store/utils/codequality_comparison_spec.js b/spec/frontend/reports/codequality_report/store/utils/codequality_comparison_spec.js
deleted file mode 100644
index 389e9b4a1f6..00000000000
--- a/spec/frontend/reports/codequality_report/store/utils/codequality_comparison_spec.js
+++ /dev/null
@@ -1,153 +0,0 @@
-import {
- parseCodeclimateMetrics,
- doCodeClimateComparison,
-} from '~/reports/codequality_report/store/utils/codequality_comparison';
-import {
- baseIssues,
- mockParsedHeadIssues,
- mockParsedBaseIssues,
- reportIssues,
- parsedReportIssues,
-} from '../../mock_data';
-
-jest.mock('~/reports/codequality_report/workers/codequality_comparison_worker', () => {
- let mockPostMessageCallback;
- return jest.fn().mockImplementation(() => {
- return {
- addEventListener: (_, callback) => {
- mockPostMessageCallback = callback;
- },
- postMessage: (data) => {
- if (!data.headIssues) return mockPostMessageCallback({ data: {} });
- if (!data.baseIssues) throw new Error();
- const key = 'fingerprint';
- return mockPostMessageCallback({
- data: {
- newIssues: data.headIssues.filter(
- (item) => !data.baseIssues.find((el) => el[key] === item[key]),
- ),
- resolvedIssues: data.baseIssues.filter(
- (item) => !data.headIssues.find((el) => el[key] === item[key]),
- ),
- },
- });
- },
- };
- });
-});
-
-describe('Codequality report store utils', () => {
- let result;
-
- describe('parseCodeclimateMetrics', () => {
- it('should parse the issues from codeclimate artifacts', () => {
- [result] = parseCodeclimateMetrics(baseIssues, 'path');
-
- expect(result.name).toEqual(baseIssues[0].check_name);
- expect(result.path).toEqual(baseIssues[0].location.path);
- expect(result.line).toEqual(baseIssues[0].location.lines.begin);
- });
-
- it('should parse the issues from backend codequality diff', () => {
- [result] = parseCodeclimateMetrics(reportIssues.new_errors, 'path');
-
- expect(result.name).toEqual(parsedReportIssues.newIssues[0].name);
- expect(result.path).toEqual(parsedReportIssues.newIssues[0].path);
- expect(result.line).toEqual(parsedReportIssues.newIssues[0].line);
- });
-
- describe('when an issue has no location or path', () => {
- const issue = { description: 'Insecure Dependency' };
-
- beforeEach(() => {
- [result] = parseCodeclimateMetrics([issue], 'path');
- });
-
- it('is parsed', () => {
- expect(result.name).toEqual(issue.description);
- });
- });
-
- describe('when an issue has a path but no line', () => {
- const issue = { description: 'Insecure Dependency', location: { path: 'Gemfile.lock' } };
-
- beforeEach(() => {
- [result] = parseCodeclimateMetrics([issue], 'path');
- });
-
- it('is parsed', () => {
- expect(result.name).toEqual(issue.description);
- expect(result.path).toEqual(issue.location.path);
- expect(result.urlPath).toEqual(`path/${issue.location.path}`);
- });
- });
-
- describe('when an issue has a line nested in positions', () => {
- const issue = {
- description: 'Insecure Dependency',
- location: {
- path: 'Gemfile.lock',
- positions: { begin: { line: 84 } },
- },
- };
-
- beforeEach(() => {
- [result] = parseCodeclimateMetrics([issue], 'path');
- });
-
- it('is parsed', () => {
- expect(result.name).toEqual(issue.description);
- expect(result.path).toEqual(issue.location.path);
- expect(result.urlPath).toEqual(
- `path/${issue.location.path}#L${issue.location.positions.begin.line}`,
- );
- });
- });
-
- describe('with an empty issue array', () => {
- beforeEach(() => {
- result = parseCodeclimateMetrics([], 'path');
- });
-
- it('returns an empty array', () => {
- expect(result).toEqual([]);
- });
- });
- });
-
- describe('doCodeClimateComparison', () => {
- describe('when the comparison worker finds changed issues', () => {
- beforeEach(async () => {
- result = await doCodeClimateComparison(mockParsedHeadIssues, mockParsedBaseIssues);
- });
-
- it('returns the new and resolved issues', () => {
- expect(result.resolvedIssues[0]).toEqual(mockParsedBaseIssues[0]);
- expect(result.newIssues[0]).toEqual(mockParsedHeadIssues[0]);
- });
- });
-
- describe('when the comparison worker finds no changed issues', () => {
- beforeEach(async () => {
- result = await doCodeClimateComparison([], []);
- });
-
- it('returns the empty issue arrays', () => {
- expect(result.newIssues).toEqual([]);
- expect(result.resolvedIssues).toEqual([]);
- });
- });
-
- describe('when the comparison worker is given malformed data', () => {
- it('rejects the promise', () => {
- return expect(doCodeClimateComparison(null)).rejects.toEqual({});
- });
- });
-
- describe('when the comparison worker encounters an error', () => {
- it('rejects the promise and throws an error', () => {
- return expect(doCodeClimateComparison([], null)).rejects.toThrow();
- });
- });
- });
-});
diff --git a/spec/frontend/reports/codequality_report/store/utils/codequality_parser_spec.js b/spec/frontend/reports/codequality_report/store/utils/codequality_parser_spec.js
new file mode 100644
index 00000000000..ba95294ab0a
--- /dev/null
+++ b/spec/frontend/reports/codequality_report/store/utils/codequality_parser_spec.js
@@ -0,0 +1,74 @@
+import { reportIssues, parsedReportIssues } from 'jest/reports/codequality_report/mock_data';
+import { parseCodeclimateMetrics } from '~/reports/codequality_report/store/utils/codequality_parser';
+
+describe('Codequality report store utils', () => {
+ let result;
+
+ describe('parseCodeclimateMetrics', () => {
+ it('should parse the issues from backend codequality diff', () => {
+ [result] = parseCodeclimateMetrics(reportIssues.new_errors, 'path');
+
+ expect(result.name).toEqual(parsedReportIssues.newIssues[0].name);
+ expect(result.path).toEqual(parsedReportIssues.newIssues[0].path);
+ expect(result.line).toEqual(parsedReportIssues.newIssues[0].line);
+ });
+
+ describe('when an issue has no location or path', () => {
+ const issue = { description: 'Insecure Dependency' };
+
+ beforeEach(() => {
+ [result] = parseCodeclimateMetrics([issue], 'path');
+ });
+
+ it('is parsed', () => {
+ expect(result.name).toEqual(issue.description);
+ });
+ });
+
+ describe('when an issue has a path but no line', () => {
+ const issue = { description: 'Insecure Dependency', location: { path: 'Gemfile.lock' } };
+
+ beforeEach(() => {
+ [result] = parseCodeclimateMetrics([issue], 'path');
+ });
+
+ it('is parsed', () => {
+ expect(result.name).toEqual(issue.description);
+ expect(result.path).toEqual(issue.location.path);
+ expect(result.urlPath).toEqual(`path/${issue.location.path}`);
+ });
+ });
+
+ describe('when an issue has a line nested in positions', () => {
+ const issue = {
+ description: 'Insecure Dependency',
+ location: {
+ path: 'Gemfile.lock',
+ positions: { begin: { line: 84 } },
+ },
+ };
+
+ beforeEach(() => {
+ [result] = parseCodeclimateMetrics([issue], 'path');
+ });
+
+ it('is parsed', () => {
+ expect(result.name).toEqual(issue.description);
+ expect(result.path).toEqual(issue.location.path);
+ expect(result.urlPath).toEqual(
+ `path/${issue.location.path}#L${issue.location.positions.begin.line}`,
+ );
+ });
+ });
+
+ describe('with an empty issue array', () => {
+ beforeEach(() => {
+ result = parseCodeclimateMetrics([], 'path');
+ });
+
+ it('returns an empty array', () => {
+ expect(result).toEqual([]);
+ });
+ });
+ });
+});