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
4a97c182
Commit
4a97c182
authored
Sep 11, 2019
by
Alessio Caiazza
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Test a real GraphQL multipart request
parent
568f9aa3
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
39 additions
and
1 deletion
+39
-1
ee/spec/requests/api/graphql/mutations/design_management/upload_spec.rb
...ts/api/graphql/mutations/design_management/upload_spec.rb
+14
-1
spec/support/helpers/graphql_helpers.rb
spec/support/helpers/graphql_helpers.rb
+25
-0
No files found.
ee/spec/requests/api/graphql/mutations/design_management/upload_spec.rb
View file @
4a97c182
...
...
@@ -4,6 +4,7 @@ require "spec_helper"
describe
"uploading designs"
do
include
GraphqlHelpers
include
DesignManagementTestHelpers
include
WorkhorseHelpers
let
(
:current_user
)
{
create
(
:user
)
}
let
(
:issue
)
{
create
(
:issue
)
}
...
...
@@ -34,12 +35,24 @@ describe "uploading designs" do
expect
(
graphql_errors
).
to
be_present
end
it
'succeeds'
do
it
'succeeds
(backward compatibility)
'
do
post_graphql_mutation
(
mutation
,
current_user:
current_user
)
expect
(
graphql_errors
).
not_to
be_present
end
it
'succeeds'
do
file_path_in_params
=
[
'designManagementUploadInput'
,
'files'
,
0
]
params
=
mutation_to_apollo_uploads_param
(
mutation
,
files:
[
file_path_in_params
])
workhorse_post_with_file
(
api
(
'/'
,
current_user
,
version:
'graphql'
),
params:
params
,
file_key:
'1'
)
expect
(
graphql_errors
).
not_to
be_present
end
it
"responds with the created designs"
do
post_graphql_mutation
(
mutation
,
current_user:
current_user
)
...
...
spec/support/helpers/graphql_helpers.rb
View file @
4a97c182
...
...
@@ -172,6 +172,31 @@ module GraphqlHelpers
post_graphql
(
mutation
.
query
,
current_user:
current_user
,
variables:
mutation
.
variables
)
end
# this implements GraphQL multipart request v2
# https://github.com/jaydenseric/graphql-multipart-request-spec/tree/v2.0.0-alpha.2
# this is simplified and do not support file deduplication
def
mutation_to_apollo_uploads_param
(
mutation
,
files:
[])
operations
=
{
'query'
=>
mutation
.
query
,
'variables'
=>
mutation
.
variables
}
map
=
{}
extracted_files
=
{}
files
.
each_with_index
do
|
file_path
,
idx
|
apollo_idx
=
(
idx
+
1
).
to_s
parent_dig_path
=
file_path
[
0
..-
2
]
file_key
=
file_path
[
-
1
]
parent
=
operations
[
'variables'
]
parent
=
parent
.
dig
(
*
parent_dig_path
)
unless
parent_dig_path
.
empty?
extracted_files
[
apollo_idx
]
=
parent
[
file_key
]
parent
[
file_key
]
=
nil
map
[
apollo_idx
]
=
[
"variables.
#{
file_path
.
join
(
'.'
)
}
"
]
end
{
operations:
operations
.
to_json
,
map:
map
.
to_json
}.
merge
(
extracted_files
)
end
# Raises an error if no data is found
def
graphql_data
json_response
[
'data'
]
||
(
raise
NoData
,
graphql_errors
)
...
...
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