apollo_upload_server-ruby icon indicating copy to clipboard operation
apollo_upload_server-ruby copied to clipboard

ActionDispatch::Http::UploadedFile received as ActionController::Parameters in rspec tests

Open NathanielAwoke opened this issue 3 years ago • 2 comments
trafficstars

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 })

NathanielAwoke avatar Apr 07 '22 13:04 NathanielAwoke

Did you manage to sort it out?

carlows avatar Dec 15 '23 14:12 carlows

same issue here, does anyone have a clue?

lhguerra avatar Jun 19 '24 17:06 lhguerra