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
7b2baef3
Commit
7b2baef3
authored
Dec 05, 2019
by
Alex Kalderimis
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Graph-QL testing support
parent
e7c31078
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
52 additions
and
7 deletions
+52
-7
spec/support/helpers/graphql_helpers.rb
spec/support/helpers/graphql_helpers.rb
+19
-5
spec/support/matchers/graphql_matchers.rb
spec/support/matchers/graphql_matchers.rb
+16
-2
spec/support/shared_examples/graphql/failure_to_find_anything.rb
...pport/shared_examples/graphql/failure_to_find_anything.rb
+17
-0
No files found.
spec/support/helpers/graphql_helpers.rb
View file @
7b2baef3
...
@@ -105,12 +105,15 @@ module GraphqlHelpers
...
@@ -105,12 +105,15 @@ module GraphqlHelpers
end
end
def
query_graphql_field
(
name
,
attributes
=
{},
fields
=
nil
)
def
query_graphql_field
(
name
,
attributes
=
{},
fields
=
nil
)
fields
||=
all_graphql_fields_for
(
name
.
classify
)
field_params
=
if
attributes
.
present?
attributes
=
attributes_to_graphql
(
attributes
)
"(
#{
attributes_to_graphql
(
attributes
)
}
)"
if
attributes
.
present?
attributes
=
"(
#{
attributes
}
)"
if
attributes
.
present?
else
''
end
<<~
QUERY
<<~
QUERY
#{
name
}#{
attribute
s
}
#{
GraphqlHelpers
.
fieldnamerize
(
name
.
to_s
)
}#{
field_param
s
}
#{
wrap_fields
(
fields
)
}
#{
wrap_fields
(
fields
||
all_graphql_fields_for
(
name
.
to_s
.
classify
)
)
}
QUERY
QUERY
end
end
...
@@ -301,6 +304,17 @@ module GraphqlHelpers
...
@@ -301,6 +304,17 @@ module GraphqlHelpers
def
global_id_of
(
model
)
def
global_id_of
(
model
)
model
.
to_global_id
.
to_s
model
.
to_global_id
.
to_s
end
end
def
missing_required_argument
(
path
,
argument
)
a_hash_including
(
'path'
=>
[
'query'
].
concat
(
path
),
'extensions'
=>
a_hash_including
(
'code'
=>
'missingRequiredArguments'
,
'arguments'
=>
argument
.
to_s
)
)
end
def
custom_graphql_error
(
path
,
msg
)
a_hash_including
(
'path'
=>
path
,
'message'
=>
msg
)
end
end
end
# This warms our schema, doing this as part of loading the helpers to avoid
# This warms our schema, doing this as part of loading the helpers to avoid
...
...
spec/support/matchers/graphql_matchers.rb
View file @
7b2baef3
...
@@ -11,8 +11,22 @@ RSpec::Matchers.define :have_graphql_fields do |*expected|
...
@@ -11,8 +11,22 @@ RSpec::Matchers.define :have_graphql_fields do |*expected|
Array
.
wrap
(
expected
).
map
{
|
name
|
GraphqlHelpers
.
fieldnamerize
(
name
)
}
Array
.
wrap
(
expected
).
map
{
|
name
|
GraphqlHelpers
.
fieldnamerize
(
name
)
}
end
end
@allow_extra
=
false
chain
:only
do
@allow_extra
=
false
end
chain
:at_least
do
@allow_extra
=
true
end
match
do
|
kls
|
match
do
|
kls
|
expect
(
kls
.
fields
.
keys
).
to
contain_exactly
(
*
expected_field_names
)
if
@allow_extra
expect
(
kls
.
fields
.
keys
).
to
include
(
*
expected_field_names
)
else
expect
(
kls
.
fields
.
keys
).
to
contain_exactly
(
*
expected_field_names
)
end
end
end
failure_message
do
|
kls
|
failure_message
do
|
kls
|
...
@@ -22,7 +36,7 @@ RSpec::Matchers.define :have_graphql_fields do |*expected|
...
@@ -22,7 +36,7 @@ RSpec::Matchers.define :have_graphql_fields do |*expected|
message
=
[]
message
=
[]
message
<<
"is missing fields: <
#{
missing
.
inspect
}
>"
if
missing
.
any?
message
<<
"is missing fields: <
#{
missing
.
inspect
}
>"
if
missing
.
any?
message
<<
"contained unexpected fields: <
#{
extra
.
inspect
}
>"
if
extra
.
any?
message
<<
"contained unexpected fields: <
#{
extra
.
inspect
}
>"
if
extra
.
any?
&&
!
@allow_extra
message
.
join
(
"
\n
"
)
message
.
join
(
"
\n
"
)
end
end
...
...
spec/support/shared_examples/graphql/failure_to_find_anything.rb
0 → 100644
View file @
7b2baef3
# frozen_string_literal: true
require
'spec_helper'
# Shared example for legal queries that are expected to return nil.
# Requires the following let bindings to be defined:
# - post_query: action to send the query
# - path: array of keys from query root to the result
shared_examples
'a failure to find anything'
do
it
'finds nothing'
do
post_query
data
=
graphql_data
.
dig
(
*
path
)
expect
(
data
).
to
be_nil
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