Commit 4a97c182 authored by Alessio Caiazza's avatar Alessio Caiazza

Test a real GraphQL multipart request

parent 568f9aa3
......@@ -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)
......
......@@ -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)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment