Commit 0dd9d2ef authored by Dave Pisek's avatar Dave Pisek

Use mockApollo for pipeline security specs

This commit adds a "mockApollo" setup to the specs for the
pipeline-security-dashboard and uses it in place of passing
the data directly into the component-setup.
parent 3ca39cfb
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,11 @@ describe('Pipeline Security Dashboard component', () => {
const findVulnerabilityReport = () => wrapper.findComponent(VulnerabilityReport);
const findScanErrorsAlert = () => wrapper.findComponent(ScanErrorsAlert);
const factory = ({ data, stubs, provide } = {}) => {
const factory = ({ stubs, provide, requestHandlers } = {}) => {
if (requestHandlers) {
localVue.use(VueApollo);
}
store = new Vuex.Store({
modules: {
vulnerabilities: {
......@@ -53,6 +67,7 @@ describe('Pipeline Security Dashboard component', () => {
wrapper = shallowMount(PipelineSecurityDashboard, {
localVue,
...(requestHandlers && { apolloProvider: createMockApollo(requestHandlers) }),
store,
provide: {
projectId,
......@@ -70,12 +85,6 @@ describe('Pipeline Security Dashboard component', () => {
...provide,
},
stubs,
data() {
return {
securityReportSummary: {},
...data,
};
},
});
};
......@@ -150,43 +159,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,
},
requestHandlers: [
[
pipelineSecurityReportSummaryQuery,
jest.fn().mockResolvedValueOnce(pipelineSecurityReportSummaryWithErrors),
],
],
});
});
......@@ -196,26 +176,14 @@ describe('Pipeline Security Dashboard component', () => {
});
describe('without errors', () => {
const reportSummary = {
dast: {
scans: [
{
name: 'dast',
errors: [],
},
],
},
};
const securityReportSummary = {
reports: reportSummary,
};
beforeEach(() => {
factory({
data: {
securityReportSummary,
},
requestHandlers: [
[
pipelineSecurityReportSummaryQuery,
jest.fn().mockResolvedValueOnce(pipelineSecurityReportSummary),
],
],
});
});
......@@ -226,32 +194,25 @@ describe('Pipeline Security Dashboard component', () => {
});
describe('security reports summary', () => {
const reportSummary = {
dast: {
vulnerabilitiesCount: 123,
},
};
it.each`
response | shouldShowReportSummary
${pipelineSecurityReportSummary} | ${true}
${pipelineSecurityReportSummaryEmpty} | ${false}
`(
'shows the summary is "$shouldShowReportSummary"',
async ({ response, shouldShowReportSummary }) => {
factory({
requestHandlers: [
[pipelineSecurityReportSummaryQuery, jest.fn().mockResolvedValueOnce(response)],
],
});
const securityReportSummary = {
reports: reportSummary,
};
await nextTick();
it('shows the summary if it is non-empty', () => {
factory({
data: {
securityReportSummary,
},
});
expect(wrapper.findComponent(SecurityReportsSummary).exists()).toBe(true);
});
it('does not show the summary if it is empty', () => {
factory({
data: {
securityReportSummary: null,
},
});
expect(wrapper.findComponent(SecurityReportsSummary).exists()).toBe(false);
});
expect(wrapper.findComponent(SecurityReportsSummary).exists()).toBe(
shouldShowReportSummary,
);
},
);
});
});
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