Commit 1d1e95c8 authored by samdbeckham's avatar samdbeckham

Reverts the changes to the data model on the GSD

Specifically, the vulnerability counts.
parent c8094c7c
......@@ -11,11 +11,15 @@ export default {
VulnerabilityCount,
},
computed: {
...mapGetters('vulnerabilities', ['dashboardCountError', 'dashboardError']),
...mapState('vulnerabilities', ['isLoadingVulnerabilitiesCount', 'vulnerabilitiesCount']),
...mapGetters('vulnerabilities', [
'vulnerabilitiesCountBySeverity',
'dashboardCountError',
'dashboardError',
]),
...mapState('vulnerabilities', ['isLoadingVulnerabilitiesCount']),
counts() {
return SEVERITIES.map(severity => {
const count = this.vulnerabilitiesCount[severity] || 0;
const count = this.vulnerabilitiesCountBySeverity(severity);
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 =>
state.errorLoadingVulnerabilities && state.errorLoadingVulnerabilitiesCount;
export const dashboardListError = state =>
......
......@@ -21,7 +21,11 @@ describe('Vulnerability Count List', () => {
});
it('should fetch the counts for each severity', () => {
expect(vm.counts[0]).toEqual({ severity: 'critical', count: mockData.critical });
const { sast, container_scanning, dependency_scanning, dast } = mockData;
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', () => {
......
{
"sast": {
"critical": 2,
"high": 4,
"low": 7,
"medium": 8,
"unknown": 0
"unknown": 9
},
"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';
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', () => {
it('should return true when both error states exist', () => {
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