Commit de909f0a authored by Kushal Pandya's avatar Kushal Pandya

Merge branch '297206-follow-up-from-migrate-refreshvulnerability-to-graphql' into 'master'

Vulnerability helper: use util to get GraphQL-id

See merge request gitlab-org/gitlab!72078
parents 4114f576 efbe0455
...@@ -6,9 +6,6 @@ import { ...@@ -6,9 +6,6 @@ import {
const falsePositiveMessage = s__('VulnerabilityManagement|Will not fix or a false-positive'); const falsePositiveMessage = s__('VulnerabilityManagement|Will not fix or a false-positive');
export const gidPrefix = 'gid://gitlab/Vulnerability/';
export const uidPrefix = 'gid://gitlab/User/';
export const VULNERABILITY_STATE_OBJECTS = { export const VULNERABILITY_STATE_OBJECTS = {
detected: { detected: {
action: 'revert', action: 'revert',
......
import { getIdFromGraphQLId } from '~/graphql_shared/utils'; import { getIdFromGraphQLId } from '~/graphql_shared/utils';
import { isAbsolute, isSafeURL } from '~/lib/utils/url_utility'; import { isAbsolute, isSafeURL } from '~/lib/utils/url_utility';
import { REGEXES, gidPrefix, uidPrefix } from './constants'; import { REGEXES } from './constants';
// Get the issue in the format expected by the descendant components of related_issues_block.vue. // Get the issue in the format expected by the descendant components of related_issues_block.vue.
export const getFormattedIssue = (issue) => ({ export const getFormattedIssue = (issue) => ({
...@@ -53,7 +53,7 @@ export const normalizeGraphQLVulnerability = (vulnerability) => { ...@@ -53,7 +53,7 @@ export const normalizeGraphQLVulnerability = (vulnerability) => {
const newVulnerability = { ...vulnerability }; const newVulnerability = { ...vulnerability };
if (vulnerability.id) { if (vulnerability.id) {
newVulnerability.id = vulnerability.id.replace(gidPrefix, ''); newVulnerability.id = getIdFromGraphQLId(vulnerability.id);
} }
if (vulnerability.state) { if (vulnerability.state) {
...@@ -62,7 +62,7 @@ export const normalizeGraphQLVulnerability = (vulnerability) => { ...@@ -62,7 +62,7 @@ export const normalizeGraphQLVulnerability = (vulnerability) => {
['confirmed', 'resolved', 'dismissed'].forEach((state) => { ['confirmed', 'resolved', 'dismissed'].forEach((state) => {
if (vulnerability[`${state}By`]?.id) { if (vulnerability[`${state}By`]?.id) {
newVulnerability[`${state}ById`] = vulnerability[`${state}By`].id.replace(uidPrefix, ''); newVulnerability[`${state}ById`] = getIdFromGraphQLId(vulnerability[`${state}By`].id);
delete newVulnerability[`${state}By`]; delete newVulnerability[`${state}By`];
} }
}); });
......
...@@ -57,11 +57,11 @@ describe('Vulnerabilities helpers', () => { ...@@ -57,11 +57,11 @@ describe('Vulnerabilities helpers', () => {
id: 'gid://gitlab/Vulnerability/54', id: 'gid://gitlab/Vulnerability/54',
}), }),
).toEqual({ ).toEqual({
confirmedById: '16', confirmedById: 16,
resolvedById: '16', resolvedById: 16,
dismissedById: '16', dismissedById: 16,
state: 'dismissed', state: 'dismissed',
id: '54', id: 54,
}); });
}); });
}); });
......
...@@ -137,7 +137,7 @@ describe('Vulnerability', () => { ...@@ -137,7 +137,7 @@ describe('Vulnerability', () => {
expect(refreshVulnerability).toHaveBeenCalledTimes(1); expect(refreshVulnerability).toHaveBeenCalledTimes(1);
await waitForPromises(); await waitForPromises();
expect(findHeader().props('vulnerability')).toEqual( expect(findHeader().props('vulnerability')).toEqual(
getVulnerability({ id: '54', state: 'resolved', resolvedAt: '2020-09-16T11:13:26Z' }), getVulnerability({ id: 54, state: 'resolved', resolvedAt: '2020-09-16T11:13:26Z' }),
); );
}); });
}); });
......
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