diff --git a/lib/inferno/apps/web/controllers/test_sessions/create.rb b/lib/inferno/apps/web/controllers/test_sessions/create.rb index 1add2f170..28af67820 100644 --- a/lib/inferno/apps/web/controllers/test_sessions/create.rb +++ b/lib/inferno/apps/web/controllers/test_sessions/create.rb @@ -10,7 +10,9 @@ class Create < Controller def handle(req, res) params = req.params.to_h - params.merge!(JSON.parse(req.body.string).symbolize_keys) unless req.body.string.blank? + unless req.body.string.blank? || req.env['CONTENT_TYPE'].include?('multipart/form-data') + params.merge!(JSON.parse(req.body.string).symbolize_keys) + end session = repo.create(create_params(params)) diff --git a/spec/request_helper.rb b/spec/request_helper.rb index 16410364c..00e3b1381 100644 --- a/spec/request_helper.rb +++ b/spec/request_helper.rb @@ -11,6 +11,10 @@ def post_json(path, data) post path, data.to_json, 'CONTENT_TYPE' => 'application/json' end + def post_form_data(path, data) + post path, data, 'CONTENT_TYPE' => 'multipart/form-data' + end + def parsed_body JSON.parse(last_response.body) end diff --git a/spec/requests/test_sessions_spec.rb b/spec/requests/test_sessions_spec.rb index ff2024d28..c0d4e7766 100644 --- a/spec/requests/test_sessions_spec.rb +++ b/spec/requests/test_sessions_spec.rb @@ -52,6 +52,18 @@ expect(persisted_session.suite_options).to eq(expected_options) end end + + context 'with form data' do + it 'renders the test session json' do + post_form_data create_path, input + + expect(last_response.status).to eq(200) + + expect(parsed_body).to include(*response_fields) + expect(parsed_body['id']).to be_present + expect(parsed_body['test_suite_id']).to eq(test_suite_id) + end + end end context 'with invalid input' do