Commit 24233a3c authored by Phil Hughes's avatar Phil Hughes

Merge branch 'vulnerability-training-check-providers' into 'master'

Show vulnerability training for enable providers

See merge request gitlab-org/gitlab!80974
parents f925cd58 1e5d0cb7
......@@ -67,10 +67,13 @@ export default {
showVulnerabilityTraining() {
return (
this.glFeatures.secureVulnerabilityTraining &&
this.securityTrainingProviders?.length &&
this.enabledSecurityTrainingProviders?.length &&
this.identifiers?.length
);
},
enabledSecurityTrainingProviders() {
return this.securityTrainingProviders?.filter((provider) => provider.isEnabled);
},
supportedIdentifier() {
return this.identifiers?.find(
({ externalType }) => externalType?.toLowerCase() === SUPPORTED_IDENTIFIER_TYPES.cwe,
......
......@@ -8,7 +8,7 @@ export default (el) => {
return null;
}
const { falsePositiveDocUrl, canViewFalsePositive } = el.dataset;
const { falsePositiveDocUrl, canViewFalsePositive, projectFullPath } = el.dataset;
const vulnerability = convertObjectPropsToCamelCase(JSON.parse(el.dataset.vulnerability), {
deep: true,
......@@ -22,7 +22,6 @@ export default (el) => {
newIssueUrl: vulnerability.newIssueUrl,
commitPathTemplate: el.dataset.commitPathTemplate,
projectFingerprint: vulnerability.projectFingerprint,
projectFullPath: vulnerability.project?.fullPath,
vulnerabilityId: vulnerability.id,
issueTrackingHelpPath: vulnerability.issueTrackingHelpPath,
permissionsHelpPath: vulnerability.permissionsHelpPath,
......@@ -32,6 +31,7 @@ export default (el) => {
jiraIntegrationSettingsPath: vulnerability.jiraIntegrationSettingsPath,
falsePositiveDocUrl,
canViewFalsePositive: parseBoolean(canViewFalsePositive),
projectFullPath,
},
render: (h) =>
h(App, {
......
......@@ -8,4 +8,5 @@
#js-vulnerability-main{ data: { vulnerability: vulnerability_details_json(@vulnerability, @pipeline),
false_positive_doc_url: help_page_path('user/application_security/vulnerabilities/index'),
can_view_false_positive: @project.licensed_feature_available?(:sast_fp_reduction).to_s,
commit_path_template: commit_path_template(@project) } }
commit_path_template: commit_path_template(@project),
project_full_path: @project.full_path } }
......@@ -17,7 +17,10 @@ import { SUPPORTED_IDENTIFIER_TYPES } from 'ee/vulnerabilities/constants';
import { TRACK_CLICK_TRAINING_LINK } from '~/security_configuration/constants';
import createMockApollo from 'helpers/mock_apollo_helper';
import waitForPromises from 'helpers/wait_for_promises';
import { securityTrainingProvidersResponse } from 'jest/security_configuration/mock_data';
import {
securityTrainingProvidersResponse,
disabledSecurityTrainingProvidersResponse,
} from 'jest/security_configuration/mock_data';
const defaultProps = {
identifiers: [
......@@ -84,24 +87,27 @@ describe('VulnerabilityTraining component', () => {
const findTrainingItemLinkIcon = () => wrapper.findComponent(GlIcon);
describe('with the query being successful', () => {
beforeEach(() => {
createApolloProvider();
});
describe('basic structure', () => {
it('displays the description', async () => {
createApolloProvider();
createComponent();
await waitForQueryToBeLoaded();
expect(findDescription().text()).toBe(i18n.trainingDescription);
});
it('does not render component when there are no identifiers', () => {
createApolloProvider();
createComponent({ identifiers: [] });
expect(wrapper.html()).toBeFalsy();
});
it('does not render component when there are no securityTrainingProviders', () => {
it('does not render component when there are no enabled securityTrainingProviders', async () => {
createApolloProvider({
queryHandler: jest.fn().mockResolvedValue(disabledSecurityTrainingProvidersResponse),
});
createComponent();
await waitForQueryToBeLoaded();
expect(wrapper.html()).toBeFalsy();
});
});
......
......@@ -30,6 +30,15 @@ export const securityTrainingProvidersResponse = {
},
};
export const disabledSecurityTrainingProvidersResponse = {
data: {
project: {
id: 1,
securityTrainingProviders: [securityTrainingProviders[0]],
},
},
};
export const dismissUserCalloutResponse = {
data: {
userCalloutCreate: {
......
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