Commit 72155f8f authored by Ezekiel Kigbo's avatar Ezekiel Kigbo

Merge branch...

Merge branch '333357-use-mock-apollo-client-within-the-pipeline-security-dashboard-specs' into 'master'

Resolve "Use mock-apollo-client within the pipeline security dashboard specs"

See merge request gitlab-org/gitlab!70763
parents 81bfb7cd 877a700e
import { merge } from 'lodash';
export const pipelineSecurityReportSummary = {
data: {
project: {
pipeline: {
id: 'gid://gitlab/Ci::Pipeline/99',
securityReportSummary: {
dast: {
vulnerabilitiesCount: 5,
scannedResourcesCsvPath:
'/security/security-reports/-/security/scanned_resources.csv?pipeline_id=99',
scans: {
nodes: [{ name: 'dast', errors: [] }],
},
},
sast: {
vulnerabilitiesCount: 67,
scans: {
nodes: [{ name: 'sast', errors: [] }],
},
},
containerScanning: {
vulnerabilitiesCount: 2,
scans: {
nodes: [
{
name: 'container-scanning',
errors: [],
},
],
},
},
dependencyScanning: {
vulnerabilitiesCount: 66,
scans: {
nodes: [
{
name: 'dependency-scanning',
errors: [],
},
],
},
},
apiFuzzing: {
vulnerabilitiesCount: 6,
scans: {
nodes: [{ name: 'api-fuzzing', errors: [] }],
},
},
coverageFuzzing: {
vulnerabilitiesCount: 1,
scans: {
nodes: [{ name: 'coverage-fuzzing', errors: [] }],
},
},
clusterImageScanning: {
vulnerabilitiesCount: 2,
scans: {
nodes: [
{
name: 'cluster-image-scanning',
errors: [],
},
],
},
},
},
jobs: {
nodes: [
{
name: 'api_fuzzing',
artifacts: {
nodes: [
{
downloadPath:
'/security/security-reports/-/jobs/1038/artifacts/download?file_type=trace',
fileType: 'TRACE',
},
{
downloadPath:
'/security/security-reports/-/jobs/1038/artifacts/download?file_type=api_fuzzing',
fileType: 'API_FUZZING',
},
],
},
},
{
name: 'coverage_fuzzing',
artifacts: {
nodes: [
{
downloadPath:
'/security/security-reports/-/jobs/1037/artifacts/download?file_type=trace',
fileType: 'TRACE',
},
{
downloadPath:
'/security/security-reports/-/jobs/1037/artifacts/download?file_type=coverage_fuzzing',
fileType: 'COVERAGE_FUZZING',
},
],
},
},
{
name: 'sast-tslint',
artifacts: {
nodes: [
{
downloadPath:
'/security/security-reports/-/jobs/1036/artifacts/download?file_type=trace',
fileType: 'TRACE',
},
{
downloadPath:
'/security/security-reports/-/jobs/1036/artifacts/download?file_type=sast',
fileType: 'SAST',
},
],
},
},
{
name: 'sast-spotbugs',
artifacts: {
nodes: [
{
downloadPath:
'/security/security-reports/-/jobs/1035/artifacts/download?file_type=trace',
fileType: 'TRACE',
},
{
downloadPath:
'/security/security-reports/-/jobs/1035/artifacts/download?file_type=sast',
fileType: 'SAST',
},
],
},
},
{
name: 'sast-sobelow',
artifacts: {
nodes: [
{
downloadPath:
'/security/security-reports/-/jobs/1034/artifacts/download?file_type=trace',
fileType: 'TRACE',
},
{
downloadPath:
'/security/security-reports/-/jobs/1034/artifacts/download?file_type=sast',
fileType: 'SAST',
},
],
},
},
{
name: 'sast-pmd-apex',
artifacts: {
nodes: [
{
downloadPath:
'/security/security-reports/-/jobs/1033/artifacts/download?file_type=trace',
fileType: 'TRACE',
},
{
downloadPath:
'/security/security-reports/-/jobs/1033/artifacts/download?file_type=sast',
fileType: 'SAST',
},
],
},
},
{
name: 'sast-eslint',
artifacts: {
nodes: [
{
downloadPath:
'/security/security-reports/-/jobs/1032/artifacts/download?file_type=trace',
fileType: 'TRACE',
},
{
downloadPath:
'/security/security-reports/-/jobs/1032/artifacts/download?file_type=sast',
fileType: 'SAST',
},
],
},
},
{
name: 'secrets',
artifacts: {
nodes: [
{
downloadPath:
'/security/security-reports/-/jobs/1031/artifacts/download?file_type=trace',
fileType: 'TRACE',
},
{
downloadPath:
'/security/security-reports/-/jobs/1031/artifacts/download?file_type=secret_detection',
fileType: 'SECRET_DETECTION',
},
],
},
},
],
},
},
},
},
};
export const scansWithErrors = [{ errors: ['error description'], name: 'scan-name' }];
export const pipelineSecurityReportSummaryWithErrors = merge({}, pipelineSecurityReportSummary, {
data: {
project: {
pipeline: {
securityReportSummary: {
dast: {
scans: {
nodes: scansWithErrors,
},
},
},
},
},
},
});
export const pipelineSecurityReportSummaryEmpty = merge({}, pipelineSecurityReportSummary, {
data: {
project: {
pipeline: {
securityReportSummary: null,
},
},
},
});
import { GlEmptyState } from '@gitlab/ui';
import { shallowMount, createLocalVue } from '@vue/test-utils';
import { nextTick } from 'vue';
import Vuex from 'vuex';
import VueApollo from 'vue-apollo';
import createMockApollo from 'helpers/mock_apollo_helper';
import pipelineSecurityReportSummaryQuery from 'ee/security_dashboard/graphql/queries/pipeline_security_report_summary.query.graphql';
import PipelineSecurityDashboard from 'ee/security_dashboard/components/pipeline/pipeline_security_dashboard.vue';
import ScanErrorsAlert from 'ee/security_dashboard/components/pipeline/scan_errors_alert.vue';
import SecurityDashboard from 'ee/security_dashboard/components/pipeline/security_dashboard_vuex.vue';
import SecurityReportsSummary from 'ee/security_dashboard/components/pipeline/security_reports_summary.vue';
import VulnerabilityReport from 'ee/security_dashboard/components/shared/vulnerability_report.vue';
import {
pipelineSecurityReportSummary,
pipelineSecurityReportSummaryWithErrors,
scansWithErrors,
pipelineSecurityReportSummaryEmpty,
} from './mock_data';
const localVue = createLocalVue();
localVue.use(Vuex);
......@@ -31,7 +41,7 @@ describe('Pipeline Security Dashboard component', () => {
const findVulnerabilityReport = () => wrapper.findComponent(VulnerabilityReport);
const findScanErrorsAlert = () => wrapper.findComponent(ScanErrorsAlert);
const factory = ({ data, stubs, provide } = {}) => {
const factory = ({ stubs, provide, apolloProvider } = {}) => {
store = new Vuex.Store({
modules: {
vulnerabilities: {
......@@ -53,6 +63,7 @@ describe('Pipeline Security Dashboard component', () => {
wrapper = shallowMount(PipelineSecurityDashboard, {
localVue,
apolloProvider,
store,
provide: {
projectId,
......@@ -70,15 +81,15 @@ describe('Pipeline Security Dashboard component', () => {
...provide,
},
stubs,
data() {
return {
securityReportSummary: {},
...data,
};
},
});
};
const factoryWithApollo = ({ requestHandlers }) => {
localVue.use(VueApollo);
factory({ apolloProvider: createMockApollo(requestHandlers) });
};
afterEach(() => {
wrapper.destroy();
});
......@@ -150,43 +161,14 @@ describe('Pipeline Security Dashboard component', () => {
describe('scans error alert', () => {
describe('with errors', () => {
const reportSummary = {
scanner_1: {
// this scan contains errors
scans: {
nodes: [
{ errors: ['scanner 1 - error 1', 'scanner 1 - error 2'], name: 'foo' },
{ errors: ['scanner 1 - error 3', 'scanner 1 - error 4'], name: 'bar' },
],
},
},
scanner_2: null,
scanner_3: {
// this scan contains errors
scans: {
nodes: [{ errors: ['scanner 3 - error 1', 'scanner 3 - error 2'], name: 'baz' }],
},
},
scanner_4: {
scans: {
nodes: [{ errors: [], name: 'quz' }],
},
},
};
const scansWithErrors = [
...reportSummary.scanner_1.scans.nodes,
...reportSummary.scanner_3.scans.nodes,
];
const securityReportSummary = {
reports: reportSummary,
};
beforeEach(() => {
factory({
data: {
securityReportSummary,
},
factoryWithApollo({
requestHandlers: [
[
pipelineSecurityReportSummaryQuery,
jest.fn().mockResolvedValueOnce(pipelineSecurityReportSummaryWithErrors),
],
],
});
});
......@@ -196,26 +178,14 @@ describe('Pipeline Security Dashboard component', () => {
});
describe('without errors', () => {
const reportSummary = {
dast: {
scans: [
{
name: 'dast',
errors: [],
},
],
},
};
const securityReportSummary = {
reports: reportSummary,
};
beforeEach(() => {
factory({
data: {
securityReportSummary,
},
factoryWithApollo({
requestHandlers: [
[
pipelineSecurityReportSummaryQuery,
jest.fn().mockResolvedValueOnce(pipelineSecurityReportSummary),
],
],
});
});
......@@ -226,32 +196,25 @@ describe('Pipeline Security Dashboard component', () => {
});
describe('security reports summary', () => {
const reportSummary = {
dast: {
vulnerabilitiesCount: 123,
},
};
const securityReportSummary = {
reports: reportSummary,
};
it('shows the summary if it is non-empty', () => {
factory({
data: {
securityReportSummary,
},
});
expect(wrapper.findComponent(SecurityReportsSummary).exists()).toBe(true);
it.each`
response | shouldShowReportSummary
${pipelineSecurityReportSummary} | ${true}
${pipelineSecurityReportSummaryEmpty} | ${false}
`(
'shows the summary is "$shouldShowReportSummary"',
async ({ response, shouldShowReportSummary }) => {
factoryWithApollo({
requestHandlers: [
[pipelineSecurityReportSummaryQuery, jest.fn().mockResolvedValueOnce(response)],
],
});
it('does not show the summary if it is empty', () => {
factory({
data: {
securityReportSummary: null,
await nextTick();
expect(wrapper.findComponent(SecurityReportsSummary).exists()).toBe(
shouldShowReportSummary,
);
},
});
expect(wrapper.findComponent(SecurityReportsSummary).exists()).toBe(false);
});
);
});
});
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