Commit 60b95c95 authored by Jose Ivan Vargas's avatar Jose Ivan Vargas

Merge branch '290014-can-t-dismiss-vulnerability-from-mr-widget' into 'master'

MR-widget: Make vulnerability-dismissal error more descriptive

See merge request gitlab-org/gitlab!66722
parents 92834010 11df1ff9
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import download from '~/lib/utils/downloader'; import download from '~/lib/utils/downloader';
import httpStatusCodes from '~/lib/utils/http_status';
import pollUntilComplete from '~/lib/utils/poll_until_complete'; import pollUntilComplete from '~/lib/utils/poll_until_complete';
import { visitUrl } from '~/lib/utils/url_utility'; import { visitUrl } from '~/lib/utils/url_utility';
import { s__, sprintf } from '~/locale'; import { s__, sprintf } from '~/locale';
...@@ -210,11 +211,16 @@ export const dismissVulnerability = ({ state, dispatch }, comment) => { ...@@ -210,11 +211,16 @@ export const dismissVulnerability = ({ state, dispatch }, comment) => {
dispatch('receiveDismissVulnerability', updatedIssue); dispatch('receiveDismissVulnerability', updatedIssue);
toast(toastMsg); toast(toastMsg);
}) })
.catch(() => { .catch((error) => {
dispatch( const pipelineNoLongerExists =
'receiveDismissVulnerabilityError', error.response?.status === httpStatusCodes.UNPROCESSABLE_ENTITY;
s__('ciReport|There was an error dismissing the vulnerability. Please try again.'), const errorMessage = pipelineNoLongerExists
); ? s__(
'ciReport|Could not dismiss vulnerability because the associated pipeline no longer exists. Refresh the page and try again.',
)
: s__('ciReport|There was an error dismissing the vulnerability. Please try again.');
dispatch('receiveDismissVulnerabilityError', errorMessage);
}); });
}; };
......
...@@ -59,6 +59,7 @@ import * as types from 'ee/vue_shared/security_reports/store/mutation_types'; ...@@ -59,6 +59,7 @@ import * as types from 'ee/vue_shared/security_reports/store/mutation_types';
import state from 'ee/vue_shared/security_reports/store/state'; import state from 'ee/vue_shared/security_reports/store/state';
import testAction from 'helpers/vuex_action_helper'; import testAction from 'helpers/vuex_action_helper';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import httpStatusCodes from '~/lib/utils/http_status';
import toasted from '~/vue_shared/plugins/global_toast'; import toasted from '~/vue_shared/plugins/global_toast';
import { import {
dastFeedbacks, dastFeedbacks,
...@@ -411,10 +412,20 @@ describe('security reports actions', () => { ...@@ -411,10 +412,20 @@ describe('security reports actions', () => {
}); });
}); });
it('with error should dispatch `receiveDismissVulnerabilityError`', (done) => { describe.each`
mock.onPost('dismiss_vulnerability_path').reply(500, {}); httpStatusErrorCode | expectedErrorMessage
mockedState.vulnerabilityFeedbackPath = 'dismiss_vulnerability_path'; ${httpStatusCodes.INTERNAL_SERVER_ERROR} | ${'There was an error dismissing the vulnerability. Please try again.'}
${httpStatusCodes.UNPROCESSABLE_ENTITY} | ${'Could not dismiss vulnerability because the associated pipeline no longer exists. Refresh the page and try again.'}
`('with error "$httpStatusErrorCode"', ({ httpStatusErrorCode, expectedErrorMessage }) => {
beforeEach(() => {
mockedState.createVulnerabilityFeedbackDismissalPath = 'dismiss_vulnerability_path';
mockedState.canReadVulnerabilityFeedback = true; mockedState.canReadVulnerabilityFeedback = true;
});
it('should dispatch `receiveDismissVulnerabilityError` with the correct payload', (done) => {
mock
.onPost(mockedState.createVulnerabilityFeedbackDismissalPath)
.replyOnce(httpStatusErrorCode);
testAction( testAction(
dismissVulnerability, dismissVulnerability,
...@@ -427,13 +438,14 @@ describe('security reports actions', () => { ...@@ -427,13 +438,14 @@ describe('security reports actions', () => {
}, },
{ {
type: 'receiveDismissVulnerabilityError', type: 'receiveDismissVulnerabilityError',
payload: 'There was an error dismissing the vulnerability. Please try again.', payload: expectedErrorMessage,
}, },
], ],
done, done,
); );
}); });
}); });
});
describe('addDismissalComment', () => { describe('addDismissalComment', () => {
const vulnerability = { const vulnerability = {
......
...@@ -38369,6 +38369,9 @@ msgstr "" ...@@ -38369,6 +38369,9 @@ msgstr ""
msgid "ciReport|Container scanning detects known vulnerabilities in your docker images." msgid "ciReport|Container scanning detects known vulnerabilities in your docker images."
msgstr "" msgstr ""
msgid "ciReport|Could not dismiss vulnerability because the associated pipeline no longer exists. Refresh the page and try again."
msgstr ""
msgid "ciReport|Coverage Fuzzing" msgid "ciReport|Coverage Fuzzing"
msgstr "" msgstr ""
......
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