Commit 0c9b8090 authored by mfluharty's avatar mfluharty

Render base path error based on report status

Use 'not_found' status to decide whether to render error message
"Base pipeline codequality artifact not found"
instead of using the presence of the path used to download the artifact

Changelog: changed
parent 8e1dbf0a
...@@ -7,11 +7,11 @@ export const setPaths = ({ commit }, paths) => commit(types.SET_PATHS, paths); ...@@ -7,11 +7,11 @@ export const setPaths = ({ commit }, paths) => commit(types.SET_PATHS, paths);
export const fetchReports = ({ state, dispatch, commit }) => { export const fetchReports = ({ state, dispatch, commit }) => {
commit(types.REQUEST_REPORTS); commit(types.REQUEST_REPORTS);
if (!state.basePath) {
return dispatch('receiveReportsError');
}
return pollUntilComplete(state.reportsPath) return pollUntilComplete(state.reportsPath)
.then(({ data }) => { .then(({ data }) => {
if (data.status === 'not_found') {
return dispatch('receiveReportsError', data);
}
return dispatch('receiveReportsSuccess', { return dispatch('receiveReportsSuccess', {
newIssues: parseCodeclimateMetrics(data.new_errors, state.headBlobPath), newIssues: parseCodeclimateMetrics(data.new_errors, state.headBlobPath),
resolvedIssues: parseCodeclimateMetrics(data.resolved_errors, state.baseBlobPath), resolvedIssues: parseCodeclimateMetrics(data.resolved_errors, state.baseBlobPath),
......
import { spriteIcon } from '~/lib/utils/common_utils'; import { spriteIcon } from '~/lib/utils/common_utils';
import { sprintf, __, s__, n__ } from '~/locale'; import { sprintf, __, s__, n__ } from '~/locale';
import { LOADING, ERROR, SUCCESS } from '../../constants'; import { LOADING, ERROR, SUCCESS, STATUS_NOT_FOUND } from '../../constants';
export const hasCodequalityIssues = (state) => export const hasCodequalityIssues = (state) =>
Boolean(state.newIssues?.length || state.resolvedIssues?.length); Boolean(state.newIssues?.length || state.resolvedIssues?.length);
...@@ -42,7 +42,7 @@ export const codequalityText = (state) => { ...@@ -42,7 +42,7 @@ export const codequalityText = (state) => {
}; };
export const codequalityPopover = (state) => { export const codequalityPopover = (state) => {
if (state.headPath && !state.basePath) { if (state.status === STATUS_NOT_FOUND) {
return { return {
title: s__('ciReport|Base pipeline codequality artifact not found'), title: s__('ciReport|Base pipeline codequality artifact not found'),
content: sprintf( content: sprintf(
......
...@@ -14,6 +14,7 @@ export default { ...@@ -14,6 +14,7 @@ export default {
}, },
[types.RECEIVE_REPORTS_SUCCESS](state, data) { [types.RECEIVE_REPORTS_SUCCESS](state, data) {
state.hasError = false; state.hasError = false;
state.status = '';
state.statusReason = ''; state.statusReason = '';
state.isLoading = false; state.isLoading = false;
state.newIssues = data.newIssues; state.newIssues = data.newIssues;
...@@ -22,6 +23,7 @@ export default { ...@@ -22,6 +23,7 @@ export default {
[types.RECEIVE_REPORTS_ERROR](state, error) { [types.RECEIVE_REPORTS_ERROR](state, error) {
state.isLoading = false; state.isLoading = false;
state.hasError = true; state.hasError = true;
state.status = error?.status || '';
state.statusReason = error?.response?.data?.status_reason; state.statusReason = error?.response?.data?.status_reason;
}, },
}; };
...@@ -8,6 +8,7 @@ export default () => ({ ...@@ -8,6 +8,7 @@ export default () => ({
isLoading: false, isLoading: false,
hasError: false, hasError: false,
status: '',
statusReason: '', statusReason: '',
newIssues: [], newIssues: [],
......
...@@ -12,6 +12,7 @@ export const SUCCESS = 'SUCCESS'; ...@@ -12,6 +12,7 @@ export const SUCCESS = 'SUCCESS';
export const STATUS_FAILED = 'failed'; export const STATUS_FAILED = 'failed';
export const STATUS_SUCCESS = 'success'; export const STATUS_SUCCESS = 'success';
export const STATUS_NEUTRAL = 'neutral'; export const STATUS_NEUTRAL = 'neutral';
export const STATUS_NOT_FOUND = 'not_found';
export const ICON_WARNING = 'warning'; export const ICON_WARNING = 'warning';
export const ICON_SUCCESS = 'success'; export const ICON_SUCCESS = 'success';
......
...@@ -127,21 +127,6 @@ describe('Grouped code quality reports app', () => { ...@@ -127,21 +127,6 @@ describe('Grouped code quality reports app', () => {
}); });
}); });
describe('when there is a head report but no base report', () => {
beforeEach(() => {
mockStore.state.basePath = null;
mockStore.state.hasError = true;
});
it('renders error text', () => {
expect(findWidget().text()).toContain('Failed to load codeclimate report');
});
it('renders a help icon with more information', () => {
expect(findWidget().find('[data-testid="question-icon"]').exists()).toBe(true);
});
});
describe('on error', () => { describe('on error', () => {
beforeEach(() => { beforeEach(() => {
mockStore.state.hasError = true; mockStore.state.hasError = true;
...@@ -154,5 +139,15 @@ describe('Grouped code quality reports app', () => { ...@@ -154,5 +139,15 @@ describe('Grouped code quality reports app', () => {
it('does not render a help icon', () => { it('does not render a help icon', () => {
expect(findWidget().find('[data-testid="question-icon"]').exists()).toBe(false); expect(findWidget().find('[data-testid="question-icon"]').exists()).toBe(false);
}); });
describe('when base report was not found', () => {
beforeEach(() => {
mockStore.state.status = 'not_found';
});
it('renders a help icon with more information', () => {
expect(findWidget().find('[data-testid="question-icon"]').exists()).toBe(true);
});
});
}); });
}); });
...@@ -92,16 +92,17 @@ describe('Codequality Reports actions', () => { ...@@ -92,16 +92,17 @@ describe('Codequality Reports actions', () => {
}); });
}); });
describe('with no base path', () => { describe('when base report is not found', () => {
it('commits REQUEST_REPORTS and dispatches receiveReportsError', (done) => { it('commits REQUEST_REPORTS and dispatches receiveReportsError', (done) => {
localState.basePath = null; const data = { status: 'not_found' };
mock.onGet(`${TEST_HOST}/codequality_reports.json`).reply(200, data);
testAction( testAction(
actions.fetchReports, actions.fetchReports,
null, null,
localState, localState,
[{ type: types.REQUEST_REPORTS }], [{ type: types.REQUEST_REPORTS }],
[{ type: 'receiveReportsError' }], [{ type: 'receiveReportsError', payload: data }],
done, done,
); );
}); });
......
...@@ -76,10 +76,9 @@ describe('Codequality reports store getters', () => { ...@@ -76,10 +76,9 @@ describe('Codequality reports store getters', () => {
}); });
describe('codequalityPopover', () => { describe('codequalityPopover', () => {
describe('when head report is available but base report is not', () => { describe('when base report is not available', () => {
it('returns a popover with a documentation link', () => { it('returns a popover with a documentation link', () => {
localState.headPath = 'head.json'; localState.status = 'not_found';
localState.basePath = undefined;
localState.helpPath = 'codequality_help.html'; localState.helpPath = 'codequality_help.html';
expect(getters.codequalityPopover(localState).title).toEqual( expect(getters.codequalityPopover(localState).title).toEqual(
......
...@@ -58,9 +58,10 @@ describe('Codequality Reports mutations', () => { ...@@ -58,9 +58,10 @@ describe('Codequality Reports mutations', () => {
expect(localState.hasError).toEqual(false); expect(localState.hasError).toEqual(false);
}); });
it('clears statusReason', () => { it('clears status and statusReason', () => {
mutations.RECEIVE_REPORTS_SUCCESS(localState, {}); mutations.RECEIVE_REPORTS_SUCCESS(localState, {});
expect(localState.status).toEqual('');
expect(localState.statusReason).toEqual(''); expect(localState.statusReason).toEqual('');
}); });
...@@ -86,6 +87,13 @@ describe('Codequality Reports mutations', () => { ...@@ -86,6 +87,13 @@ describe('Codequality Reports mutations', () => {
expect(localState.hasError).toEqual(true); expect(localState.hasError).toEqual(true);
}); });
it('sets status based on error object', () => {
const error = { status: 'not_found' };
mutations.RECEIVE_REPORTS_ERROR(localState, error);
expect(localState.status).toEqual(error.status);
});
it('sets statusReason to string from error response data', () => { it('sets statusReason to string from error response data', () => {
const data = { status_reason: 'This merge request does not have codequality reports' }; const data = { status_reason: 'This merge request does not have codequality reports' };
const error = { response: { data } }; const error = { response: { data } };
......
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