Skip to content

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

@NathanielAwoke

Description

@NathanielAwoke

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions