jetruby / apollo_upload_server-ruby

MIT License
180 stars 50 forks source link

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

Open Haegin opened 1 year ago

Haegin commented 1 year ago

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 "# 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.

fuelen commented 1 year ago

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

Haegin commented 1 year ago

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

kyasui commented 1 year ago

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

ApolloUploadServer::Wrappers::UploadedFile.new(Rack::Test::UploadedFile.new(Rails.public_path.join('image/logo.png')))
iLucker93 commented 4 months ago

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

This approach works.