Commit 624cd04d authored by Sam Beckham's avatar Sam Beckham Committed by samdbeckham

Updates the FE for counts on the GSD

where FE is frontend and GSD is Group security dashboard

This reverts commit 1d1e95c8
parent d41db350
...@@ -11,15 +11,11 @@ export default { ...@@ -11,15 +11,11 @@ export default {
VulnerabilityCount, VulnerabilityCount,
}, },
computed: { computed: {
...mapGetters('vulnerabilities', [ ...mapGetters('vulnerabilities', ['dashboardCountError', 'dashboardError']),
'vulnerabilitiesCountBySeverity', ...mapState('vulnerabilities', ['isLoadingVulnerabilitiesCount', 'vulnerabilitiesCount']),
'dashboardCountError',
'dashboardError',
]),
...mapState('vulnerabilities', ['isLoadingVulnerabilitiesCount']),
counts() { counts() {
return SEVERITIES.map(severity => { return SEVERITIES.map(severity => {
const count = this.vulnerabilitiesCountBySeverity(severity); const count = this.vulnerabilitiesCount[severity] || 0;
return { severity, count }; return { severity, count };
}); });
}, },
......
import { sum } from '~/lib/utils/number_utils';
export const vulnerabilitiesCountBySeverity = state => severity =>
Object.values(state.vulnerabilitiesCount)
.map(count => count[severity])
.reduce(sum, 0);
export const vulnerabilitiesCountByReportType = state => type => {
const counts = state.vulnerabilitiesCount[type];
return counts ? Object.values(counts).reduce(sum, 0) : 0;
};
export const dashboardError = state => export const dashboardError = state =>
state.errorLoadingVulnerabilities && state.errorLoadingVulnerabilitiesCount; state.errorLoadingVulnerabilities && state.errorLoadingVulnerabilitiesCount;
export const dashboardListError = state => export const dashboardListError = state =>
......
---
title: Changes to the data model for counts on the Group Security Dashboard
merge_request: 9035
author:
type: changed
...@@ -21,11 +21,7 @@ describe('Vulnerability Count List', () => { ...@@ -21,11 +21,7 @@ describe('Vulnerability Count List', () => {
}); });
it('should fetch the counts for each severity', () => { it('should fetch the counts for each severity', () => {
const { sast, container_scanning, dependency_scanning, dast } = mockData; expect(vm.counts[0]).toEqual({ severity: 'critical', count: mockData.critical });
const count =
sast.critical + container_scanning.critical + dependency_scanning.critical + dast.critical;
expect(vm.counts[0]).toEqual({ severity: 'critical', count });
}); });
it('should render a counter for each severity', () => { it('should render a counter for each severity', () => {
......
{ {
"sast": { "critical": 2,
"critical": 2, "high": 4,
"high": 4, "low": 7,
"low": 7, "medium": 8,
"medium": 8, "unknown": 0
"unknown": 9 }
}, \ No newline at end of file
"container_scanning": {
"critical": 3,
"high": 3,
"low": 2,
"medium": 9,
"unknown": 7
},
"dependency_scanning": {
"critical": 2,
"high": 3,
"low": 9,
"medium": 4,
"unknown": 7
},
"dast": {
"critical": 2,
"high": 3,
"low": 9,
"medium": 4,
"unknown": 7
}
}
import State from 'ee/security_dashboard/store/modules/vulnerabilities/state';
import * as getters from 'ee/security_dashboard/store/modules/vulnerabilities/getters'; import * as getters from 'ee/security_dashboard/store/modules/vulnerabilities/getters';
describe('vulnerabilities module getters', () => { describe('vulnerabilities module getters', () => {
const initialState = State();
describe('vulnerabilitiesCountBySeverity', () => {
const sast = { critical: 10 };
const dast = { critical: 66 };
const expectedValue = sast.critical + dast.critical;
const vulnerabilitiesCount = { sast, dast };
const state = { vulnerabilitiesCount };
it('should add up all the counts with `high` severity', () => {
const result = getters.vulnerabilitiesCountBySeverity(state)('critical');
expect(result).toBe(expectedValue);
});
it('should return 0 if no counts match the severity name', () => {
const result = getters.vulnerabilitiesCountBySeverity(state)('medium');
expect(result).toBe(0);
});
it('should return 0 if there are no counts at all', () => {
const result = getters.vulnerabilitiesCountBySeverity(initialState)('critical');
expect(result).toBe(0);
});
});
describe('vulnerabilitiesCountByReportType', () => {
const sast = { critical: 10, medium: 22 };
const dast = { critical: 66 };
const expectedValue = sast.critical + sast.medium;
const vulnerabilitiesCount = { sast, dast };
const state = { vulnerabilitiesCount };
it('should add up all the counts in the sast report', () => {
const result = getters.vulnerabilitiesCountByReportType(state)('sast');
expect(result).toBe(expectedValue);
});
it('should return 0 if there are no reports for a severity type', () => {
const result = getters.vulnerabilitiesCountByReportType(initialState)('sast');
expect(result).toBe(0);
});
});
describe('dashboardError', () => { describe('dashboardError', () => {
it('should return true when both error states exist', () => { it('should return true when both error states exist', () => {
const errorLoadingVulnerabilities = true; const errorLoadingVulnerabilities = true;
......
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