Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
bbf0d8cb
Commit
bbf0d8cb
authored
Apr 21, 2021
by
Savas Vedova
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add unit test for vulnerability severities count query
parent
95638a05
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
68 additions
and
17 deletions
+68
-17
ee/app/assets/javascripts/security_dashboard/components/vulnerability_count_list.vue
...ecurity_dashboard/components/vulnerability_count_list.vue
+1
-0
ee/spec/frontend/security_dashboard/components/vulnerability_count_list_spec.js
...ity_dashboard/components/vulnerability_count_list_spec.js
+48
-17
ee/spec/frontend/security_dashboard/mock_data/index.js
ee/spec/frontend/security_dashboard/mock_data/index.js
+19
-0
No files found.
ee/app/assets/javascripts/security_dashboard/components/vulnerability_count_list.vue
View file @
bbf0d8cb
...
...
@@ -42,6 +42,7 @@ export default {
query
:
vulnerabilitySeveritiesCountQuery
,
variables
()
{
const
{
dashboardType
,
fullPath
}
=
this
;
return
{
fullPath
,
isInstance
:
dashboardType
===
DASHBOARD_TYPES
.
INSTANCE
,
...
...
ee/spec/frontend/security_dashboard/components/vulnerability_count_list_spec.js
View file @
bbf0d8cb
...
...
@@ -6,6 +6,7 @@ import countQuery from 'ee/security_dashboard/graphql/queries/vulnerability_seve
import
{
DASHBOARD_TYPES
}
from
'
ee/security_dashboard/store/constants
'
;
import
eventHub
from
'
ee/security_dashboard/utils/event_hub
'
;
import
createMockApollo
from
'
helpers/mock_apollo_helper
'
;
import
{
mockVulnerabilitySeveritiesGraphQLResponse
}
from
'
../mock_data
'
;
const
localVue
=
createLocalVue
();
localVue
.
use
(
VueApollo
);
...
...
@@ -14,7 +15,7 @@ describe('Vulnerabilities count list component', () => {
let
wrapper
;
let
refetchSpy
;
const
findVulnerabilityLayout
=
()
=>
wrapper
.
find
(
VulnerabilityCountListLayout
);
const
findVulnerabilityLayout
=
()
=>
wrapper
.
find
Component
(
VulnerabilityCountListLayout
);
const
createWrapper
=
({
query
=
{
isLoading
:
false
},
provide
,
data
=
{}
}
=
{})
=>
{
refetchSpy
=
jest
.
fn
();
...
...
@@ -28,6 +29,16 @@ describe('Vulnerabilities count list component', () => {
});
};
const
createWrapperWithApollo
=
({
query
,
provide
,
propsData
,
stubs
})
=>
{
wrapper
=
shallowMount
(
VulnerabilityCountList
,
{
localVue
,
apolloProvider
:
createMockApollo
([[
countQuery
,
query
]]),
provide
,
propsData
,
stubs
,
});
};
afterEach
(()
=>
{
wrapper
.
destroy
();
});
...
...
@@ -76,15 +87,25 @@ describe('Vulnerabilities count list component', () => {
});
describe
.
each
`
dashboardType | expectedContainedQueryVariables
${
DASHBOARD_TYPES
.
INSTANCE
}
|
${{
isInstance
:
true
,
isGroup
:
false
,
isProject
:
false
}
}
${
DASHBOARD_TYPES
.
GROUP
}
|
${{
isInstance
:
false
,
isGroup
:
true
,
isProject
:
false
}
}
${
DASHBOARD_TYPES
.
PROJECT
}
|
${{
isInstance
:
false
,
isGroup
:
false
,
isProject
:
true
}
}
dashboardType |
fullPath |
expectedContainedQueryVariables
${
DASHBOARD_TYPES
.
INSTANCE
}
|
${
undefined
}
|
${
{
isInstance
:
true
,
isGroup
:
false
,
isProject
:
false
}
}
${
DASHBOARD_TYPES
.
GROUP
}
|
${
'
group/path
'
}
|
${
{
isInstance
:
false
,
isGroup
:
true
,
isProject
:
false
}
}
${
DASHBOARD_TYPES
.
PROJECT
}
|
${
'
project/path
'
}
|
${
{
isInstance
:
false
,
isGroup
:
false
,
isProject
:
true
}
}
`
(
'
when the dashboard type is $dashboardType
'
,
({
dashboardType
,
expectedContainedQueryVariables
})
=>
{
({
dashboardType
,
fullPath
,
expectedContainedQueryVariables
})
=>
{
beforeEach
(()
=>
{
wrapper
=
createWrapper
({
provide
:
{
dashboardType
}
});
const
mockResponse
=
jest
.
fn
()
.
mockResolvedValue
(
mockVulnerabilitySeveritiesGraphQLResponse
({
dashboardType
}));
createWrapperWithApollo
({
provide
:
{
dashboardType
},
propsData
:
{
fullPath
,
filters
:
{
someFilter
:
1
}
},
query
:
mockResponse
,
stubs
:
{
VulnerabilityCountListLayout
},
});
return
wrapper
.
vm
.
$nextTick
();
});
...
...
@@ -93,6 +114,17 @@ describe('Vulnerabilities count list component', () => {
wrapper
.
vm
.
$options
.
apollo
.
vulnerabilitiesCount
.
variables
.
call
(
wrapper
.
vm
),
).
toMatchObject
(
expectedContainedQueryVariables
);
});
it
(
'
should set the data properly
'
,
()
=>
{
expect
(
findVulnerabilityLayout
().
props
(
'
vulnerabilitiesCount
'
)).
toEqual
({
critical
:
0
,
high
:
0
,
info
:
0
,
low
:
0
,
medium
:
4
,
unknown
:
2
,
});
});
},
);
...
...
@@ -109,23 +141,22 @@ describe('Vulnerabilities count list component', () => {
describe
(
'
filters prop
'
,
()
=>
{
const
mockQuery
=
jest
.
fn
().
mockResolvedValue
(
null
);
const
createWrapperWithApollo
=
({
query
,
filters
}
)
=>
{
wrapper
=
shallowMount
(
VulnerabilityCountList
,
{
localVue
,
apolloProvider
:
createMockApollo
([[
countQuery
,
query
]])
,
it
(
'
does not run the query when filters is null
'
,
(
)
=>
{
createWrapperWithApollo
(
{
query
:
mockQuery
,
propsData
:
{
filters
:
null
}
,
provide
:
{
dashboardType
:
DASHBOARD_TYPES
.
PROJECT
},
propsData
:
{
filters
},
});
};
it
(
'
does not run the query when filters is null
'
,
()
=>
{
createWrapperWithApollo
({
query
:
mockQuery
,
filters
:
null
});
expect
(
mockQuery
).
not
.
toHaveBeenCalled
();
});
it
(
'
runs query when filters is an object
'
,
()
=>
{
createWrapperWithApollo
({
query
:
mockQuery
,
filters
:
{}
});
createWrapperWithApollo
({
query
:
mockQuery
,
propsData
:
{
filters
:
{}
},
provide
:
{
dashboardType
:
DASHBOARD_TYPES
.
PROJECT
},
});
expect
(
mockQuery
).
toHaveBeenCalled
();
});
...
...
ee/spec/frontend/security_dashboard/mock_data/index.js
View file @
bbf0d8cb
...
...
@@ -223,3 +223,22 @@ export const mockVulnerableProjectsGroup = () => ({
},
},
});
export
const
mockVulnerabilitySeveritiesGraphQLResponse
=
({
dashboardType
})
=>
({
data
:
{
[
dashboardType
]:
{
vulnerabilitySeveritiesCount
:
{
__typename
:
'
VulnerabilitySeveritiesCount
'
,
critical
:
0
,
high
:
0
,
info
:
0
,
low
:
0
,
medium
:
4
,
unknown
:
2
,
},
},
__typename
:
{
project
:
'
Project
'
,
instance
:
'
InstanceSecurityDashboard
'
,
group
:
'
Group
'
}[
dashboardType
],
},
});
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment