Commit 851d64e3 authored by mfluharty's avatar mfluharty

Changes from feedback

Simplify feature flag in actions spec
Use getCodeQualityViolations for query name in actions spec
Optionally chain nested data when dispatching success action
Use try/catch and async/await in fetchReport action
Move issue severity case conversion to computed
Don't capitalize query name in query file
parent 307def3c
...@@ -33,20 +33,20 @@ export default { ...@@ -33,20 +33,20 @@ export default {
issueName() { issueName() {
return `${this.severityLabel} - ${this.issue.name}`; return `${this.severityLabel} - ${this.issue.name}`;
}, },
issueSeverity() {
return this.issue.severity.toLowerCase();
},
isStatusSuccess() { isStatusSuccess() {
return this.status === STATUS_SUCCESS; return this.status === STATUS_SUCCESS;
}, },
severityClass() { severityClass() {
return SEVERITY_CLASSES[this.issue.severity.toLowerCase()] || SEVERITY_CLASSES.unknown; return SEVERITY_CLASSES[this.issueSeverity] || SEVERITY_CLASSES.unknown;
}, },
severityIcon() { severityIcon() {
return SEVERITY_ICONS[this.issue.severity.toLowerCase()] || SEVERITY_ICONS.unknown; return SEVERITY_ICONS[this.issueSeverity] || SEVERITY_ICONS.unknown;
}, },
severityLabel() { severityLabel() {
return ( return this.$options.severityText[this.issueSeverity] || this.$options.severityText.unknown;
this.$options.severityText[this.issue.severity.toLowerCase()] ||
this.$options.severityText.unknown
);
}, },
}, },
severityText: { severityText: {
......
query GetCodeQualityViolations($projectPath: ID!, $iid: ID!, $first: Int, $after: String) { query getCodeQualityViolations($projectPath: ID!, $iid: ID!, $first: Int, $after: String) {
project(fullPath: $projectPath) { project(fullPath: $projectPath) {
pipeline(iid: $iid) { pipeline(iid: $iid) {
codeQualityReports(first: $first, after: $after) { codeQualityReports(first: $first, after: $after) {
......
...@@ -47,44 +47,37 @@ export const receiveReportSuccess = ({ state, commit }, data) => { ...@@ -47,44 +47,37 @@ export const receiveReportSuccess = ({ state, commit }, data) => {
}; };
export const receiveReportError = ({ commit }, error) => commit(types.RECEIVE_REPORT_ERROR, error); export const receiveReportError = ({ commit }, error) => commit(types.RECEIVE_REPORT_ERROR, error);
export const fetchReport = ({ state, dispatch }) => { export const fetchReport = async ({ state, dispatch }) => {
dispatch('requestReport'); try {
dispatch('requestReport');
if (!state.blobPath) throw new Error();
if (gon.features?.graphqlCodeQualityFullReport) { if (gon.features?.graphqlCodeQualityFullReport) {
const { projectPath, pipelineIid, pageInfo } = state; const { projectPath, pipelineIid, pageInfo } = state;
const variables = { const variables = {
projectPath, projectPath,
iid: pipelineIid, iid: pipelineIid,
first: pageInfo.first, first: pageInfo.first,
after: pageInfo.after, after: pageInfo.after,
}; };
return gqClient await gqClient
.query({ .query({
query: getCodeQualityViolations, query: getCodeQualityViolations,
variables, variables,
}) })
.then(({ data }) => { .then(({ data }) => {
if (!state.blobPath) throw new Error(); dispatch('receiveReportSuccess', data.project?.pipeline?.codeQualityReports);
dispatch('receiveReportSuccess', data.project.pipeline.codeQualityReports);
})
.catch((error) => {
dispatch('receiveReportError', error);
createFlash({
message: s__('ciReport|There was an error fetching the codequality report.'),
}); });
} else {
await axios.get(state.endpoint).then(({ data }) => {
dispatch('receiveReportSuccess', data);
}); });
} }
return axios } catch (error) {
.get(state.endpoint) dispatch('receiveReportError', error);
.then(({ data }) => { createFlash({
if (!state.blobPath) throw new Error(); message: s__('ciReport|There was an error fetching the codequality report.'),
dispatch('receiveReportSuccess', data);
})
.catch((error) => {
dispatch('receiveReportError', error);
createFlash({
message: s__('ciReport|There was an error fetching the codequality report.'),
});
}); });
}
}; };
import MockAdapter from 'axios-mock-adapter'; import MockAdapter from 'axios-mock-adapter';
import codeQualityQuery from 'ee/codequality_report/graphql/queries/get_code_quality_violations.query.graphql'; import getCodeQualityViolations from 'ee/codequality_report/graphql/queries/get_code_quality_violations.query.graphql';
import * as actions from 'ee/codequality_report/store/actions'; import * as actions from 'ee/codequality_report/store/actions';
import { VIEW_EVENT_NAME } from 'ee/codequality_report/store/constants'; import { VIEW_EVENT_NAME } from 'ee/codequality_report/store/constants';
import * as types from 'ee/codequality_report/store/mutation_types'; import * as types from 'ee/codequality_report/store/mutation_types';
...@@ -33,6 +33,7 @@ describe('Codequality report actions', () => { ...@@ -33,6 +33,7 @@ describe('Codequality report actions', () => {
beforeEach(() => { beforeEach(() => {
mock = new MockAdapter(axios); mock = new MockAdapter(axios);
state = defaultState; state = defaultState;
window.gon = { features: { graphqlCodeQualityFullReport: false } };
}); });
afterEach(() => { afterEach(() => {
...@@ -41,9 +42,6 @@ describe('Codequality report actions', () => { ...@@ -41,9 +42,6 @@ describe('Codequality report actions', () => {
describe('setPage', () => { describe('setPage', () => {
it('sets the page number with feature flag disabled', (done) => { it('sets the page number with feature flag disabled', (done) => {
const origGon = window.gon;
window.gon = { features: { graphqlCodeQualityFullReport: false } };
return testAction( return testAction(
actions.setPage, actions.setPage,
12, 12,
...@@ -51,13 +49,10 @@ describe('Codequality report actions', () => { ...@@ -51,13 +49,10 @@ describe('Codequality report actions', () => {
[{ type: types.SET_PAGE, payload: { page: 12 } }], [{ type: types.SET_PAGE, payload: { page: 12 } }],
[], [],
done, done,
).then(() => { );
window.gon = origGon;
});
}); });
it('sets the page number with feature flag enabled', (done) => { it('sets the page number with feature flag enabled', (done) => {
const origGon = window.gon;
window.gon = { features: { graphqlCodeQualityFullReport: true } }; window.gon = { features: { graphqlCodeQualityFullReport: true } };
return testAction( return testAction(
...@@ -67,9 +62,7 @@ describe('Codequality report actions', () => { ...@@ -67,9 +62,7 @@ describe('Codequality report actions', () => {
[{ type: types.SET_PAGE, payload: { after: '', currentPage: 12 } }], [{ type: types.SET_PAGE, payload: { after: '', currentPage: 12 } }],
[{ type: 'fetchReport' }], [{ type: 'fetchReport' }],
done, done,
).then(() => { );
window.gon = origGon;
});
}); });
}); });
...@@ -87,9 +80,6 @@ describe('Codequality report actions', () => { ...@@ -87,9 +80,6 @@ describe('Codequality report actions', () => {
describe('receiveReportSuccess', () => { describe('receiveReportSuccess', () => {
it('parses the list of issues from the report with feature flag disabled', (done) => { it('parses the list of issues from the report with feature flag disabled', (done) => {
const origGon = window.gon;
window.gon = { features: { graphqlCodeQualityFullReport: false } };
return testAction( return testAction(
actions.receiveReportSuccess, actions.receiveReportSuccess,
unparsedIssues, unparsedIssues,
...@@ -97,13 +87,10 @@ describe('Codequality report actions', () => { ...@@ -97,13 +87,10 @@ describe('Codequality report actions', () => {
[{ type: types.RECEIVE_REPORT_SUCCESS, payload: parsedIssues }], [{ type: types.RECEIVE_REPORT_SUCCESS, payload: parsedIssues }],
[], [],
done, done,
).then(() => { );
window.gon = origGon;
});
}); });
it('parses the list of issues from the report with feature flag enabled', (done) => { it('parses the list of issues from the report with feature flag enabled', (done) => {
const origGon = window.gon;
window.gon = { features: { graphqlCodeQualityFullReport: true } }; window.gon = { features: { graphqlCodeQualityFullReport: true } };
const data = { const data = {
...@@ -119,9 +106,7 @@ describe('Codequality report actions', () => { ...@@ -119,9 +106,7 @@ describe('Codequality report actions', () => {
[{ type: types.RECEIVE_REPORT_SUCCESS_GRAPHQL, payload: { data, parsedIssues } }], [{ type: types.RECEIVE_REPORT_SUCCESS_GRAPHQL, payload: { data, parsedIssues } }],
[], [],
done, done,
).then(() => { );
window.gon = origGon;
});
}); });
}); });
...@@ -145,9 +130,6 @@ describe('Codequality report actions', () => { ...@@ -145,9 +130,6 @@ describe('Codequality report actions', () => {
}); });
it('fetches the report', (done) => { it('fetches the report', (done) => {
const origGon = window.gon;
window.gon = { features: { graphqlCodeQualityFullReport: false } };
return testAction( return testAction(
actions.fetchReport, actions.fetchReport,
null, null,
...@@ -155,9 +137,7 @@ describe('Codequality report actions', () => { ...@@ -155,9 +137,7 @@ describe('Codequality report actions', () => {
[], [],
[{ type: 'requestReport' }, { type: 'receiveReportSuccess', payload: unparsedIssues }], [{ type: 'requestReport' }, { type: 'receiveReportSuccess', payload: unparsedIssues }],
done, done,
).then(() => { );
window.gon = origGon;
});
}); });
it('shows a flash message when there is an error', (done) => { it('shows a flash message when there is an error', (done) => {
...@@ -197,12 +177,10 @@ describe('Codequality report actions', () => { ...@@ -197,12 +177,10 @@ describe('Codequality report actions', () => {
beforeEach(() => { beforeEach(() => {
jest.spyOn(gqClient, 'query').mockResolvedValue(mockGraphqlResponse); jest.spyOn(gqClient, 'query').mockResolvedValue(mockGraphqlResponse);
state.paginationData = mockGraphqlPagination; state.paginationData = mockGraphqlPagination;
window.gon = { features: { graphqlCodeQualityFullReport: true } };
}); });
it('fetches the report', () => { it('fetches the report', () => {
const origGon = window.gon;
window.gon = { features: { graphqlCodeQualityFullReport: true } };
return testAction( return testAction(
actions.fetchReport, actions.fetchReport,
null, null,
...@@ -217,13 +195,11 @@ describe('Codequality report actions', () => { ...@@ -217,13 +195,11 @@ describe('Codequality report actions', () => {
], ],
() => { () => {
expect(gqClient.query).toHaveBeenCalledWith({ expect(gqClient.query).toHaveBeenCalledWith({
query: codeQualityQuery, query: getCodeQualityViolations,
variables: { after: '', first: 25, iid: null, projectPath: null }, variables: { after: '', first: 25, iid: null, projectPath: null },
}); });
}, },
).then(() => { );
window.gon = origGon;
});
}); });
}); });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment