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
b77da98e
Commit
b77da98e
authored
Jun 10, 2020
by
Brett Walker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Convert to using shared pagination specs
for project requirements
parent
963966c1
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
19 additions
and
71 deletions
+19
-71
ee/spec/requests/api/graphql/project/requirements_management/requirements_spec.rb
...phql/project/requirements_management/requirements_spec.rb
+19
-71
No files found.
ee/spec/requests/api/graphql/project/requirements_management/requirements_spec.rb
View file @
b77da98e
...
...
@@ -135,13 +135,18 @@ RSpec.describe 'getting a requirement list for a project' do
end
describe
'sorting and pagination'
do
let
(
:start_cursor
)
{
graphql_data
[
'project'
][
'requirements'
][
'pageInfo'
][
'startCursor'
]
}
let
(
:end_cursor
)
{
graphql_data
[
'project'
][
'requirements'
][
'pageInfo'
][
'endCursor'
]
}
let_it_be
(
:data_path
)
{
[
:project
,
:requirements
]
}
def
grab_iids
(
data
=
requirements_data
)
data
.
map
do
|
requirement_hash
|
requirement_hash
.
dig
(
'node'
,
'iid'
).
to_i
end
def
pagination_query
(
params
,
page_info
)
graphql_query_for
(
'project'
,
{
'fullPath'
=>
sort_project
.
full_path
},
query_graphql_field
(
'requirements'
,
params
,
"
#{
page_info
}
edges { node { iid createdAt} }"
)
)
end
def
pagination_results_data
(
data
)
data
.
map
{
|
issue
|
issue
.
dig
(
'node'
,
'iid'
).
to_i
}
end
context
'when sorting by created_at'
do
...
...
@@ -152,76 +157,19 @@ RSpec.describe 'getting a requirement list for a project' do
let_it_be
(
:requirement4
)
{
create
(
:requirement
,
project:
sort_project
,
created_at:
5
.
days
.
ago
)
}
let_it_be
(
:requirement5
)
{
create
(
:requirement
,
project:
sort_project
,
created_at:
1
.
day
.
ago
)
}
let
(
:params
)
{
'sort: created_asc'
}
def
query
(
requirement_params
=
params
)
graphql_query_for
(
'project'
,
{
'fullPath'
=>
sort_project
.
full_path
},
<<~
REQUIREMENTS
requirements(
#{
requirement_params
}
) {
pageInfo {
endCursor
}
edges {
node {
iid
createdAt
}
}
}
REQUIREMENTS
)
end
def
post_query_with_after_cursor
(
sort_by
)
cursored_query
=
query
(
"sort:
#{
sort_by
}
, after:
\"
#{
end_cursor
}
\"
"
)
post_graphql
(
cursored_query
,
current_user:
current_user
)
Gitlab
::
Json
.
parse
(
response
.
body
)[
'data'
][
'project'
][
'requirements'
][
'edges'
]
end
before
do
post_graphql
(
query
,
current_user:
current_user
)
end
it_behaves_like
'a working graphql query'
context
'when ascending'
do
it
'sorts requirements'
do
expect
(
grab_iids
).
to
eq
[
requirement4
.
iid
,
requirement3
.
iid
,
requirement5
.
iid
,
requirement1
.
iid
,
requirement2
.
iid
]
end
context
'when paginating'
do
let
(
:params
)
{
'sort: created_asc, first: 2'
}
it
'sorts requirements'
do
expect
(
grab_iids
).
to
eq
[
requirement4
.
iid
,
requirement3
.
iid
]
response_data
=
post_query_with_after_cursor
(
'created_asc'
)
expect
(
grab_iids
(
response_data
)).
to
eq
[
requirement5
.
iid
,
requirement1
.
iid
,
requirement2
.
iid
]
end
it_behaves_like
'sorted paginated query'
do
let
(
:sort_param
)
{
'created_asc'
}
let
(
:first_param
)
{
2
}
let
(
:expected_results
)
{
[
requirement4
.
iid
,
requirement3
.
iid
,
requirement5
.
iid
,
requirement1
.
iid
,
requirement2
.
iid
]
}
end
end
context
'when descending'
do
let
(
:params
)
{
'sort: created_desc'
}
it
'sorts requirements'
do
expect
(
grab_iids
).
to
eq
[
requirement2
.
iid
,
requirement1
.
iid
,
requirement5
.
iid
,
requirement3
.
iid
,
requirement4
.
iid
]
end
context
'when paginating'
do
let
(
:params
)
{
'sort: created_desc, first: 2'
}
it
'sorts requirements'
do
expect
(
grab_iids
).
to
eq
[
requirement2
.
iid
,
requirement1
.
iid
]
response_data
=
post_query_with_after_cursor
(
'created_desc'
)
expect
(
grab_iids
(
response_data
)).
to
eq
[
requirement5
.
iid
,
requirement3
.
iid
,
requirement4
.
iid
]
end
it_behaves_like
'sorted paginated query'
do
let
(
:sort_param
)
{
'created_desc'
}
let
(
:first_param
)
{
2
}
let
(
:expected_results
)
{
[
requirement2
.
iid
,
requirement1
.
iid
,
requirement5
.
iid
,
requirement3
.
iid
,
requirement4
.
iid
]
}
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