Skip to content

Commit

Permalink
Fix handling of JSON payload in API auth tests
Browse files Browse the repository at this point in the history
Rails 7 appears to apply stricter parsing rules. If the Content-Type is not JSON, then the body will not be parsed as JSON.
  • Loading branch information
aaronskiba committed Jul 15, 2024
1 parent 4bd0e9a commit d06f436
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions spec/requests/api/v1/authentication_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,22 @@

it 'calls the Api::Jwt::AuthenticationService' do
Api::V1::Auth::Jwt::AuthenticationService.any_instance.expects(:call).at_most(1)
post api_v1_authenticate_path, params: @payload.to_json
post api_v1_authenticate_path, params: @payload, as: :json
end
it 'renders /api/v1/error template if authentication fails' do
errs = [Faker::Lorem.sentence]
Api::V1::Auth::Jwt::AuthenticationService.any_instance
.stubs(:call).returns(nil)
.stubs(:errors).returns(errs)
post api_v1_authenticate_path, params: @payload.to_json
post api_v1_authenticate_path, params: @payload, as: :json
expect(response.code).to eql('401')
expect(response).to render_template('api/v1/error')
end
it 'returns a JSON Web Token' do
token = Api::V1::Auth::Jwt::JsonWebToken.encode(payload: @payload)
Api::V1::Auth::Jwt::AuthenticationService.any_instance.stubs(:call)
.returns(token)
post api_v1_authenticate_path, params: @payload.to_json
post api_v1_authenticate_path, params: @payload, as: :json
expect(response.code).to eql('200')
expect(response).to render_template('api/v1/token')
end
Expand Down

0 comments on commit d06f436

Please sign in to comment.