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
8610f33d
Commit
8610f33d
authored
Jun 11, 2020
by
Brett Walker
Committed by
Michael Kozono
Jun 11, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use shared pagination specs
for board lists
parent
b47db5cb
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
80 additions
and
85 deletions
+80
-85
ee/spec/requests/api/graphql/boards/board_lists_query_spec.rb
...pec/requests/api/graphql/boards/board_lists_query_spec.rb
+33
-37
ee/spec/requests/api/graphql/project/issues_spec.rb
ee/spec/requests/api/graphql/project/issues_spec.rb
+1
-1
spec/requests/api/graphql/boards/board_lists_query_spec.rb
spec/requests/api/graphql/boards/board_lists_query_spec.rb
+28
-36
spec/requests/api/graphql/project/issues_spec.rb
spec/requests/api/graphql/project/issues_spec.rb
+1
-1
spec/support/helpers/graphql_helpers.rb
spec/support/helpers/graphql_helpers.rb
+7
-2
spec/support/shared_examples/graphql/sorted_paginated_query_shared_examples.rb
...xamples/graphql/sorted_paginated_query_shared_examples.rb
+10
-8
No files found.
ee/spec/requests/api/graphql/boards/board_lists_query_spec.rb
View file @
8610f33d
...
...
@@ -5,8 +5,8 @@ require 'spec_helper'
RSpec
.
describe
'get board lists'
do
include
GraphqlHelpers
let_it_be
(
:
user
)
{
create
(
:user
)
}
let_it_be
(
:project
)
{
create
(
:project
,
creator_id:
user
.
id
,
namespace:
user
.
namespace
)
}
let_it_be
(
:
current_user
)
{
create
(
:user
)
}
let_it_be
(
:project
)
{
create
(
:project
,
creator_id:
current_user
.
id
,
namespace:
current_
user
.
namespace
)
}
let_it_be
(
:group
)
{
create
(
:group
,
:private
)
}
let_it_be
(
:project_milestone
)
{
create
(
:milestone
,
project:
project
)
}
let_it_be
(
:project_milestone2
)
{
create
(
:milestone
,
project:
project
)
}
...
...
@@ -58,46 +58,45 @@ RSpec.describe 'get board lists' do
context
'when user can read the board'
do
before
do
board_parent
.
add_reporter
(
user
)
board_parent
.
add_reporter
(
current_
user
)
end
describe
'sorting and pagination'
do
let
(
:data_path
)
{
[
board_parent_type
,
:boards
,
:edges
,
0
,
:node
,
:lists
]
}
def
pagination_query
(
params
,
page_info
)
graphql_query_for
(
board_parent_type
,
{
'fullPath'
=>
board_parent
.
full_path
},
<<~
BOARDS
boards(first: 1) {
edges {
node {
#{
query_graphql_field
(
'lists'
,
params
,
"
#{
page_info
}
edges { node { id } }"
)
}
}
}
}
BOARDS
)
end
def
pagination_results_data
(
data
)
data
.
map
{
|
list
|
list
.
dig
(
'node'
,
'id'
)
}
end
context
'when using default sorting'
do
let!
(
:milestone_list
)
{
create
(
:milestone_list
,
board:
board
,
milestone:
milestone
,
position:
10
)
}
let!
(
:milestone_list2
)
{
create
(
:milestone_list
,
board:
board
,
milestone:
milestone2
,
position:
2
)
}
let!
(
:assignee_list
)
{
create
(
:user_list
,
board:
board
,
user:
assignee
,
position:
5
)
}
let!
(
:assignee_list2
)
{
create
(
:user_list
,
board:
board
,
user:
assignee2
,
position:
1
)
}
let
(
:closed_list
)
{
board
.
lists
.
find_by
(
list_type: :closed
)
}
before
do
post_graphql
(
query
,
current_user:
user
)
end
it_behaves_like
'a working graphql query'
let
(
:lists
)
{
[
closed_list
,
assignee_list2
,
assignee_list
,
milestone_list2
,
milestone_list
]
}
context
'when ascending'
do
let
(
:lists
)
{
[
closed_list
,
assignee_list2
,
assignee_list
,
milestone_list2
,
milestone_list
]
}
let
(
:expected_list_gids
)
do
lists
.
map
{
|
list
|
list
.
to_global_id
.
to_s
}
end
it
'sorts lists'
do
expect
(
grab_ids
).
to
eq
expected_list_gids
end
context
'when paginating'
do
let
(
:params
)
{
'first: 2'
}
it
'sorts boards'
do
expect
(
grab_ids
).
to
eq
expected_list_gids
.
first
(
2
)
cursored_query
=
query
(
"after:
\"
#{
end_cursor
}
\"
"
)
post_graphql
(
cursored_query
,
current_user:
user
)
response_data
=
grab_list_data
(
response
.
body
)
expect
(
grab_ids
(
response_data
)).
to
eq
expected_list_gids
.
drop
(
2
).
first
(
3
)
end
it_behaves_like
'sorted paginated query'
do
let
(
:sort_param
)
{
}
let
(
:first_param
)
{
2
}
let
(
:expected_results
)
{
lists
.
map
{
|
list
|
list
.
to_global_id
.
to_s
}
}
end
end
end
...
...
@@ -108,7 +107,7 @@ RSpec.describe 'get board lists' do
let!
(
:list_with_limit_metrics
)
{
create
(
:list
,
board:
board
,
**
limit_metric_params
)
}
before
do
post_graphql
(
query
,
current_user:
user
)
post_graphql
(
query
,
current_user:
current_
user
)
end
it
'returns the expected limit metric settings'
do
...
...
@@ -144,11 +143,8 @@ RSpec.describe 'get board lists' do
it_behaves_like
'group and project board lists query'
end
def
grab_ids
(
data
=
lists_data
)
data
.
map
{
|
list
|
list
.
dig
(
'node'
,
'id'
)
}
end
def
grab_list_data
(
response_body
)
Gitlab
::
Json
.
parse
(
response_body
)[
'data'
][
board_parent_type
][
'boards'
][
'edges'
][
0
][
'node'
][
'lists'
][
'edges'
]
keys
=
[
:data
,
board_parent_type
,
:boards
,
:edges
,
0
,
:node
,
:lists
,
:edges
]
graphql_dig_at
(
Gitlab
::
Json
.
parse
(
response_body
),
*
keys
)
end
end
ee/spec/requests/api/graphql/project/issues_spec.rb
View file @
8610f33d
...
...
@@ -15,7 +15,7 @@ RSpec.describe 'getting an issue list for a project' do
graphql_query_for
(
'project'
,
{
'fullPath'
=>
sort_project
.
full_path
},
"issues(
#{
params
}
) {
#{
page_info
}
edges { node { iid weight } } }"
query_graphql_field
(
'issues'
,
params
,
"
#{
page_info
}
edges { node { iid weight} }"
)
)
end
...
...
spec/requests/api/graphql/boards/board_lists_query_spec.rb
View file @
8610f33d
...
...
@@ -65,41 +65,41 @@ describe 'get board lists' do
end
describe
'sorting and pagination'
do
let_it_be
(
:current_user
)
{
user
}
let
(
:data_path
)
{
[
board_parent_type
,
:boards
,
:edges
,
0
,
:node
,
:lists
]
}
def
pagination_query
(
params
,
page_info
)
graphql_query_for
(
board_parent_type
,
{
'fullPath'
=>
board_parent
.
full_path
},
<<~
BOARDS
boards(first: 1) {
edges {
node {
#{
query_graphql_field
(
'lists'
,
params
,
"
#{
page_info
}
edges { node { id } }"
)
}
}
}
}
BOARDS
)
end
def
pagination_results_data
(
data
)
data
.
map
{
|
list
|
list
.
dig
(
'node'
,
'id'
)
}
end
context
'when using default sorting'
do
let!
(
:label_list
)
{
create
(
:list
,
board:
board
,
label:
label
,
position:
10
)
}
let!
(
:label_list2
)
{
create
(
:list
,
board:
board
,
label:
label2
,
position:
2
)
}
let!
(
:backlog_list
)
{
create
(
:backlog_list
,
board:
board
)
}
let
(
:closed_list
)
{
board
.
lists
.
find_by
(
list_type: :closed
)
}
before
do
post_graphql
(
query
,
current_user:
user
)
end
it_behaves_like
'a working graphql query'
let
(
:lists
)
{
[
backlog_list
,
label_list2
,
label_list
,
closed_list
]
}
context
'when ascending'
do
let
(
:lists
)
{
[
backlog_list
,
label_list2
,
label_list
,
closed_list
]
}
let
(
:expected_list_gids
)
do
lists
.
map
{
|
list
|
list
.
to_global_id
.
to_s
}
end
it
'sorts lists'
do
expect
(
grab_ids
).
to
eq
expected_list_gids
end
context
'when paginating'
do
let
(
:params
)
{
'first: 2'
}
it
'sorts boards'
do
expect
(
grab_ids
).
to
eq
expected_list_gids
.
first
(
2
)
cursored_query
=
query
(
"after:
\"
#{
end_cursor
}
\"
"
)
post_graphql
(
cursored_query
,
current_user:
user
)
response_data
=
grab_list_data
(
response
.
body
)
expect
(
grab_ids
(
response_data
)).
to
eq
expected_list_gids
.
drop
(
2
).
first
(
2
)
end
it_behaves_like
'sorted paginated query'
do
let
(
:sort_param
)
{
}
let
(
:first_param
)
{
2
}
let
(
:expected_results
)
{
lists
.
map
{
|
list
|
list
.
to_global_id
.
to_s
}
}
end
end
end
...
...
@@ -126,12 +126,4 @@ describe 'get board lists' do
it_behaves_like
'group and project board lists query'
end
def
grab_ids
(
data
=
lists_data
)
data
.
map
{
|
list
|
list
.
dig
(
'node'
,
'id'
)
}
end
def
grab_list_data
(
response_body
)
Gitlab
::
Json
.
parse
(
response_body
)[
'data'
][
board_parent_type
][
'boards'
][
'edges'
][
0
][
'node'
][
'lists'
][
'edges'
]
end
end
spec/requests/api/graphql/project/issues_spec.rb
View file @
8610f33d
...
...
@@ -124,7 +124,7 @@ describe 'getting an issue list for a project' do
graphql_query_for
(
'project'
,
{
'fullPath'
=>
sort_project
.
full_path
},
"issues(
#{
params
}
) {
#{
page_info
}
edges { node { iid dueDate } } }"
query_graphql_field
(
'issues'
,
params
,
"
#{
page_info
}
edges { node { iid dueDate} }"
)
)
end
...
...
spec/support/helpers/graphql_helpers.rb
View file @
8610f33d
...
...
@@ -279,8 +279,13 @@ module GraphqlHelpers
end
def
graphql_dig_at
(
data
,
*
path
)
keys
=
path
.
map
{
|
segment
|
GraphqlHelpers
.
fieldnamerize
(
segment
)
}
data
.
dig
(
*
keys
)
keys
=
path
.
map
{
|
segment
|
segment
.
is_a?
(
Integer
)
?
segment
:
GraphqlHelpers
.
fieldnamerize
(
segment
)
}
# Allows for array indexing, like this
# ['project', 'boards', 'edges', 0, 'node', 'lists']
keys
.
reduce
(
data
)
do
|
memo
,
key
|
memo
.
is_a?
(
Array
)
?
memo
[
key
]
:
memo
&
.
dig
(
key
)
end
end
def
graphql_errors
...
...
spec/support/shared_examples/graphql/sorted_paginated_query_shared_examples.rb
View file @
8610f33d
...
...
@@ -23,7 +23,7 @@
# graphql_query_for(
# 'project',
# { 'fullPath' => sort_project.full_path },
#
"issues(#{params}) { #{page_info} edges { node { iid weight } } }"
#
query_graphql_field('issues', params, "#{page_info} edges { node { id } }")
# )
# end
#
...
...
@@ -47,11 +47,13 @@ RSpec.shared_examples 'sorted paginated query' do
end
describe
do
let
(
:params
)
{
"sort:
#{
sort_param
}
"
}
let
(
:start_cursor
)
{
graphql_data_at
(
*
data_path
,
:pageInfo
,
:startCursor
)
}
let
(
:end_cursor
)
{
graphql_data_at
(
*
data_path
,
:pageInfo
,
:endCursor
)
}
let
(
:sorted_edges
)
{
graphql_data_at
(
*
data_path
,
:edges
)
}
let
(
:page_info
)
{
"pageInfo { startCursor endCursor }"
}
let
(
:sort_argument
)
{
"sort:
#{
sort_param
}
"
if
sort_param
.
present?
}
let
(
:first_argument
)
{
"first:
#{
first_param
}
"
if
first_param
.
present?
}
let
(
:params
)
{
sort_argument
}
let
(
:start_cursor
)
{
graphql_data_at
(
*
data_path
,
:pageInfo
,
:startCursor
)
}
let
(
:end_cursor
)
{
graphql_data_at
(
*
data_path
,
:pageInfo
,
:endCursor
)
}
let
(
:sorted_edges
)
{
graphql_data_at
(
*
data_path
,
:edges
)
}
let
(
:page_info
)
{
"pageInfo { startCursor endCursor }"
}
def
pagination_query
(
params
,
page_info
)
raise
(
'pagination_query(params, page_info) must be defined in the test, see example in comment'
)
unless
defined?
(
super
)
...
...
@@ -75,12 +77,12 @@ RSpec.shared_examples 'sorted paginated query' do
end
context
'when paginating'
do
let
(
:params
)
{
"sort:
#{
sort_param
}
, first:
#{
first_param
}
"
}
let
(
:params
)
{
[
sort_argument
,
first_argument
].
compact
.
join
(
','
)
}
it
'paginates correctly'
do
expect
(
pagination_results_data
(
sorted_edges
)).
to
eq
expected_results
.
first
(
first_param
)
cursored_query
=
pagination_query
(
"sort:
#{
sort_param
}
, after:
\"
#{
end_cursor
}
\"
"
,
page_info
)
cursored_query
=
pagination_query
(
[
sort_argument
,
"after:
\"
#{
end_cursor
}
\"
"
].
compact
.
join
(
','
)
,
page_info
)
post_graphql
(
cursored_query
,
current_user:
current_user
)
response_data
=
graphql_dig_at
(
Gitlab
::
Json
.
parse
(
response
.
body
),
:data
,
*
data_path
,
:edges
)
...
...
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