Skip to content

Commit

Permalink
Add tests for normal signin
Browse files Browse the repository at this point in the history
  • Loading branch information
sinaeftekhar committed Aug 11, 2023
1 parent ceb2717 commit d2d15fd
Showing 1 changed file with 21 additions and 0 deletions.
21 changes: 21 additions & 0 deletions spec/controllers/apiauth/sessions_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,27 @@ module Apiauth
parsed_response_body = JSON.parse(response.body)
expect(parsed_response_body.has_key?("jwt_token")).to be(false)
end

context "with normal sign in" do
before do
allow(::Decidim::Apiauth).to receive(:force_api_authentication).and_return(false)
end

it "returns jwt_token when credentials are valid" do
expect(request.env[::Warden::JWTAuth::Hooks::PREPARED_TOKEN_ENV_KEY]).not_to be_present
post :create, params: params
expect(response).to have_http_status(:ok)
expect(request.env[::Warden::JWTAuth::Hooks::PREPARED_TOKEN_ENV_KEY]).to be_present
parsed_response_body = JSON.parse(response.body)
expect(parsed_response_body["jwt_token"]).to eq(request.env[::Warden::JWTAuth::Hooks::PREPARED_TOKEN_ENV_KEY])
end

it "returns 403 when credentials are invalid" do
post :create, params: invalid_params
expect(response).to have_http_status(:forbidden)
expect(request.env[::Warden::JWTAuth::Hooks::PREPARED_TOKEN_ENV_KEY]).not_to be_present
end
end
end
end
end
Expand Down

0 comments on commit d2d15fd

Please sign in to comment.