Skip to content

Commit

Permalink
Allow for form data at session create endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
360dgries committed Jan 10, 2024
1 parent fef1e5d commit 1c4ae0b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
4 changes: 3 additions & 1 deletion lib/inferno/apps/web/controllers/test_sessions/create.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down
4 changes: 4 additions & 0 deletions spec/request_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions spec/requests/test_sessions_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 1c4ae0b

Please sign in to comment.