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 { GlEmptyState } from '@gitlab/ui';
import { shallowMount, createLocalVue } from '@vue/test-utils'; import { shallowMount, createLocalVue } from '@vue/test-utils';
import { nextTick } from 'vue';
import Vuex from 'vuex'; 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 PipelineSecurityDashboard from 'ee/security_dashboard/components/pipeline/pipeline_security_dashboard.vue';
import ScanErrorsAlert from 'ee/security_dashboard/components/pipeline/scan_errors_alert.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 SecurityDashboard from 'ee/security_dashboard/components/pipeline/security_dashboard_vuex.vue';
import SecurityReportsSummary from 'ee/security_dashboard/components/pipeline/security_reports_summary.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 VulnerabilityReport from 'ee/security_dashboard/components/shared/vulnerability_report.vue';
import {
pipelineSecurityReportSummary,
pipelineSecurityReportSummaryWithErrors,
scansWithErrors,
pipelineSecurityReportSummaryEmpty,
} from './mock_data';
const localVue = createLocalVue(); const localVue = createLocalVue();
localVue.use(Vuex); localVue.use(Vuex);
...@@ -31,7 +41,7 @@ describe('Pipeline Security Dashboard component', () => { ...@@ -31,7 +41,7 @@ describe('Pipeline Security Dashboard component', () => {
const findVulnerabilityReport = () => wrapper.findComponent(VulnerabilityReport); const findVulnerabilityReport = () => wrapper.findComponent(VulnerabilityReport);
const findScanErrorsAlert = () => wrapper.findComponent(ScanErrorsAlert); const findScanErrorsAlert = () => wrapper.findComponent(ScanErrorsAlert);
const factory = ({ data, stubs, provide } = {}) => { const factory = ({ stubs, provide, apolloProvider } = {}) => {
store = new Vuex.Store({ store = new Vuex.Store({
modules: { modules: {
vulnerabilities: { vulnerabilities: {
...@@ -53,6 +63,7 @@ describe('Pipeline Security Dashboard component', () => { ...@@ -53,6 +63,7 @@ describe('Pipeline Security Dashboard component', () => {
wrapper = shallowMount(PipelineSecurityDashboard, { wrapper = shallowMount(PipelineSecurityDashboard, {
localVue, localVue,
apolloProvider,
store, store,
provide: { provide: {
projectId, projectId,
...@@ -70,15 +81,15 @@ describe('Pipeline Security Dashboard component', () => { ...@@ -70,15 +81,15 @@ describe('Pipeline Security Dashboard component', () => {
...provide, ...provide,
}, },
stubs, stubs,
data() {
return {
securityReportSummary: {},
...data,
};
},
}); });
}; };
const factoryWithApollo = ({ requestHandlers }) => {
localVue.use(VueApollo);
factory({ apolloProvider: createMockApollo(requestHandlers) });
};
afterEach(() => { afterEach(() => {
wrapper.destroy(); wrapper.destroy();
}); });
...@@ -150,43 +161,14 @@ describe('Pipeline Security Dashboard component', () => { ...@@ -150,43 +161,14 @@ describe('Pipeline Security Dashboard component', () => {
describe('scans error alert', () => { describe('scans error alert', () => {
describe('with errors', () => { 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(() => { beforeEach(() => {
factory({ factoryWithApollo({
data: { requestHandlers: [
securityReportSummary, [
}, pipelineSecurityReportSummaryQuery,
jest.fn().mockResolvedValueOnce(pipelineSecurityReportSummaryWithErrors),
],
],
}); });
}); });
...@@ -196,26 +178,14 @@ describe('Pipeline Security Dashboard component', () => { ...@@ -196,26 +178,14 @@ describe('Pipeline Security Dashboard component', () => {
}); });
describe('without errors', () => { describe('without errors', () => {
const reportSummary = {
dast: {
scans: [
{
name: 'dast',
errors: [],
},
],
},
};
const securityReportSummary = {
reports: reportSummary,
};
beforeEach(() => { beforeEach(() => {
factory({ factoryWithApollo({
data: { requestHandlers: [
securityReportSummary, [
}, pipelineSecurityReportSummaryQuery,
jest.fn().mockResolvedValueOnce(pipelineSecurityReportSummary),
],
],
}); });
}); });
...@@ -226,32 +196,25 @@ describe('Pipeline Security Dashboard component', () => { ...@@ -226,32 +196,25 @@ describe('Pipeline Security Dashboard component', () => {
}); });
describe('security reports summary', () => { describe('security reports summary', () => {
const reportSummary = { it.each`
dast: { response | shouldShowReportSummary
vulnerabilitiesCount: 123, ${pipelineSecurityReportSummary} | ${true}
}, ${pipelineSecurityReportSummaryEmpty} | ${false}
}; `(
'shows the summary is "$shouldShowReportSummary"',
const securityReportSummary = { async ({ response, shouldShowReportSummary }) => {
reports: reportSummary, factoryWithApollo({
}; requestHandlers: [
[pipelineSecurityReportSummaryQuery, jest.fn().mockResolvedValueOnce(response)],
],
});
it('shows the summary if it is non-empty', () => { await nextTick();
factory({
data: {
securityReportSummary,
},
});
expect(wrapper.findComponent(SecurityReportsSummary).exists()).toBe(true);
});
it('does not show the summary if it is empty', () => { expect(wrapper.findComponent(SecurityReportsSummary).exists()).toBe(
factory({ shouldShowReportSummary,
data: { );
securityReportSummary: null, },
}, );
});
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