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 {
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 = {
detected: {
action: 'revert',
......
import { getIdFromGraphQLId } from '~/graphql_shared/utils';
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.
export const getFormattedIssue = (issue) => ({
......@@ -53,7 +53,7 @@ export const normalizeGraphQLVulnerability = (vulnerability) => {
const newVulnerability = { ...vulnerability };
if (vulnerability.id) {
newVulnerability.id = vulnerability.id.replace(gidPrefix, '');
newVulnerability.id = getIdFromGraphQLId(vulnerability.id);
}
if (vulnerability.state) {
......@@ -62,7 +62,7 @@ export const normalizeGraphQLVulnerability = (vulnerability) => {
['confirmed', 'resolved', 'dismissed'].forEach((state) => {
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`];
}
});
......
......@@ -57,11 +57,11 @@ describe('Vulnerabilities helpers', () => {
id: 'gid://gitlab/Vulnerability/54',
}),
).toEqual({
confirmedById: '16',
resolvedById: '16',
dismissedById: '16',
confirmedById: 16,
resolvedById: 16,
dismissedById: 16,
state: 'dismissed',
id: '54',
id: 54,
});
});
});
......
......@@ -137,7 +137,7 @@ describe('Vulnerability', () => {
expect(refreshVulnerability).toHaveBeenCalledTimes(1);
await waitForPromises();
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