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

How should we be testing mutations that accept uploaded files in 2.1.5?

Open Haegin opened this issue 2 years ago • 4 comments
trafficstars

I'm in the process of upgrading an app from 2.0.1 to 2.1.5 and all the tests we have involving uploaded files are now failing with an "#Rack::Test::UploadedFiles... is not a valid upload" error. In our tests we're creating these files using a helper method:

module UploadTestHelper
  def generic_file
    Rack::Test::UploadedFile.new(Rails.root.join("spec", "data", "test_attachment.txt"))
  end
end

and then we're using it anywhere we need a file in the tests:

let(:variables) do
  {
    input: {
      quoteId: quote.id,
      files: [UploadTestHelper.quote],
    }
  }
end

This was working as expected until now, but after upgrading to 2.1.5 these test files are being rejected. I can't see any documentation on how to create test files. I've tracked down the issue to this change - https://github.com/jetruby/apollo_upload_server-ruby/pull/32/files. Is it possible to get an example of how to use this Wrappers::UploadedFile class to wrap up a local file for specs please? I've tried a few things and haven't managed to get anything working.

Haegin avatar Mar 22 '23 19:03 Haegin

Hi @Haegin Have you tried ApolloUploadServer::Wrappers::UploadedFile.new(UploadTestHelper.generic_file)?

fuelen avatar Mar 22 '23 19:03 fuelen

@fuelen yes, that's still not considered a valid upload.

Haegin avatar Mar 24 '23 22:03 Haegin

FYI doing this explicitly fixed our tests @fuelen @Haegin :

ApolloUploadServer::Wrappers::UploadedFile.new(Rack::Test::UploadedFile.new(Rails.public_path.join('image/logo.png')))

kyasui avatar Jun 21 '23 18:06 kyasui

https://github.com/jetruby/apollo_upload_server-ruby/issues/37#issuecomment-1008154821

This approach works.

iLucker93 avatar Apr 30 '24 12:04 iLucker93