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
e0aa7870
Commit
e0aa7870
authored
Sep 02, 2020
by
Justin Zeng
Committed by
Rémy Coutable
Sep 02, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added test for Vulnerabilities::FindingSerializer
parent
2868b3a5
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
98 additions
and
0 deletions
+98
-0
ee/spec/serializers/vulnerabilities/finding_serializer_spec.rb
...ec/serializers/vulnerabilities/finding_serializer_spec.rb
+98
-0
No files found.
ee/spec/serializers/vulnerabilities/finding_serializer_spec.rb
0 → 100644
View file @
e0aa7870
# frozen_string_literal: true
require
'spec_helper'
RSpec
.
describe
Vulnerabilities
::
FindingSerializer
do
let_it_be
(
:project
)
{
create
(
:project
,
:repository
)
}
let_it_be
(
:user
)
{
create
(
:user
)
}
let
(
:serializer
)
do
described_class
.
new
(
current_user:
user
)
end
subject
{
serializer
.
represent
(
resource
)
}
describe
'#represent'
do
context
'when used without pagination'
do
it
'created a not paginated serializer'
do
expect
(
serializer
).
not_to
be_paginated
end
context
'when a single object is being serialized'
do
let
(
:resource
)
{
create
(
:vulnerabilities_finding
,
project:
project
)
}
it
'serializers the vulnerability finding object'
do
expect
(
subject
[
:id
]).
to
eq
resource
.
id
end
end
context
'when multiple objects are being serialized'
do
let
(
:resource
)
{
create_list
(
:vulnerabilities_finding
,
2
,
project:
project
)
}
it
'serializers the array of vulnerability finding object'
do
expect
(
subject
.
count
).
to
be
2
end
end
end
context
'when used with pagination'
do
let
(
:request
)
{
double
(
url:
"
#{
Gitlab
.
config
.
gitlab
.
url
}
:8080/api/v4/projects?
#{
query
.
to_query
}
"
,
query_parameters:
query
)
}
let
(
:response
)
{
spy
(
'response'
)
}
let
(
:query
)
{
{}
}
let
(
:serializer
)
do
described_class
.
new
(
current_user:
user
)
.
with_pagination
(
request
,
response
)
end
it
'created a paginated serializer'
do
expect
(
serializer
).
to
be_paginated
end
context
'when resource is not paginatable'
do
context
'when a single vulnerability finding object is being serialized'
do
let
(
:resource
)
{
create
(
:vulnerabilities_finding
)
}
let
(
:query
)
{
{
page:
1
,
per_page:
1
}
}
it
'raises error'
do
expect
{
subject
}.
to
raise_error
(
Gitlab
::
Serializer
::
Pagination
::
InvalidResourceError
)
end
end
end
context
'when resource is paginatable relation'
do
let
(
:resource
)
{
Vulnerabilities
::
Finding
.
all
}
let
(
:query
)
{
{
page:
1
,
per_page:
2
}
}
context
'when a single vulnerability finding object is present in relation'
do
before
do
create
(
:vulnerabilities_finding
)
end
it
'serializes vulnerability finding relation'
do
expect
(
subject
.
first
).
to
have_key
:id
end
end
context
'when multiple vulnerability finding objects are being serialized'
do
before
do
create_list
(
:vulnerabilities_finding
,
3
)
end
it
'serializes appropriate number of objects'
do
expect
(
subject
.
count
).
to
be
2
end
it
'append relevant headers'
do
expect
(
response
).
to
receive
(
:[]=
).
with
(
'X-Total'
,
'3'
)
expect
(
response
).
to
receive
(
:[]=
).
with
(
'X-Total-Pages'
,
'2'
)
expect
(
response
).
to
receive
(
:[]=
).
with
(
'X-Per-Page'
,
'2'
)
subject
end
end
end
end
end
end
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