jetruby / apollo_upload_server-ruby

MIT License
180 stars 50 forks source link

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

Open NathanielAwoke opened 2 years ago

NathanielAwoke commented 2 years ago

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

carlows commented 9 months ago

Did you manage to sort it out?

lhguerra commented 2 months ago

same issue here, does anyone have a clue?