apollo_upload_server-ruby
apollo_upload_server-ruby copied to clipboard
How should we be testing mutations that accept uploaded files in 2.1.5?
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.
Hi @Haegin Have you tried ApolloUploadServer::Wrappers::UploadedFile.new(UploadTestHelper.generic_file)?
@fuelen yes, that's still not considered a valid upload.
FYI doing this explicitly fixed our tests @fuelen @Haegin :
ApolloUploadServer::Wrappers::UploadedFile.new(Rack::Test::UploadedFile.new(Rails.public_path.join('image/logo.png')))
https://github.com/jetruby/apollo_upload_server-ruby/issues/37#issuecomment-1008154821
This approach works.