1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52
|
require 'spec_helper'
require 'action_dispatch'
require 'apollo_upload_server/middleware'
describe ApolloUploadServer::Middleware do
around do |example|
mode = described_class.strict_mode
example.run
described_class.strict_mode = mode
end
describe '#call' do
let(:app) do
Rack::Builder.new do
use ApolloUploadServer::Middleware
run ->(_env) { [200, { 'Content-Type' => 'text/plain' }, 'Hello, World.'] }
end
end
context "when CONTENT_TYPE is 'multipart/form-data'" do
subject do
Rack::MockRequest.new(app).post('/', { 'CONTENT_TYPE' => 'multipart/form-data', input: 'operations={}&map={}' })
end
it { expect(subject.status).to eq(200) }
end
context "when CONTENT_TYPE is not 'multipart/form-data'" do
subject do
Rack::MockRequest.new(app).post('/', { 'CONTENT_TYPE' => 'text/plain' })
end
it { expect(subject.status).to eq(200) }
end
context 'when configured to run in strict mode' do
before do
described_class.strict_mode = true
end
subject do
Rack::MockRequest.new(app).post('/', { 'CONTENT_TYPE' => 'multipart/form-data', input: 'operations={}&map={}' })
end
it 'propagates this setting to the data builder' do
expect(ApolloUploadServer::GraphQLDataBuilder).to receive(:new).with(strict_mode: true).and_call_original
subject
end
end
end
end
|