ActionDispatch::Http::UploadedFile received as ActionController::Parameters in rspec tests
Opened this issue · 2 comments
I am writing a mutation that that includes file upload and spec fails throwing the error below
[{"extensions"=>{"problems"=>[{"explanation"=>"#<ActionController::Parameters {\"original_filename\"=...0x0000aaaaf8b0e868>\", \"content_type\"=>\"image/jpeg\"} permitted: false> is not a valid upload)"}]
.
I dug a bit further and found out that the file I passed was received as ActionController::parameters
rather than ActionDispatch::Http::UploadedFile
. Below is how I wrote the mutation in the spec
create_mutation = <<~GQL mutation createItem( $shortDescription: String! $image: Upload! ) { createItem( shortDescription: $shortDescription images: $images ) { id } } GQL
variables = { image: ::ApolloUploadServer::Wrappers::UploadedFile.new(ActionDispatch::Http::UploadedFile.new(filename: "image.png", type: "image/png", tempfile: File.new("spec/support/fixtures/image.png"))) }
response = ApiSchema.execute(create_mutation, variables: variables })
Did you manage to sort it out?
same issue here, does anyone have a clue?