-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
17 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,18 +30,9 @@ | |
end | ||
|
||
it "get /auth/result successful" do | ||
user = User.new(email: "[email protected]", token: SecureRandom.uuid) | ||
code = "ABC123" | ||
login_gov = instance_double(LoginGov) | ||
allow(LoginGov).to receive(:new).and_return(login_gov) | ||
allow(login_gov).to receive(:exchange_token_from_auth_result).with(code).and_return( | ||
[{ email: "[email protected]", sub: "sub" }] | ||
) | ||
|
||
# rubocop:disable RSpec/AnyInstance | ||
allow_any_instance_of(SessionsController).to( | ||
receive(:send_user_jwt_to_phoenix).with(instance_of(String)).and_return(true) | ||
) | ||
# rubocop:enable RSpec/AnyInstance | ||
mock_login_gov(user, code) | ||
|
||
get "/auth/result", params: { code: } | ||
expect(response).to have_http_status(:redirect) | ||
|
@@ -54,20 +45,10 @@ | |
email = "[email protected]" | ||
token = SecureRandom.uuid | ||
|
||
User.create!({ email:, token: }) | ||
user = User.create!({ email:, token: }) | ||
|
||
code = "ABC123" | ||
login_gov = instance_double(LoginGov) | ||
allow(LoginGov).to receive(:new).and_return(login_gov) | ||
allow(login_gov).to receive(:exchange_token_from_auth_result).with(code).and_return( | ||
[{ email:, sub: token }] | ||
) | ||
|
||
# rubocop:disable RSpec/AnyInstance | ||
allow_any_instance_of(SessionsController).to( | ||
receive(:send_user_jwt_to_phoenix).with(instance_of(String)).and_return(true) | ||
) | ||
# rubocop:enable RSpec/AnyInstance | ||
mock_login_gov(user, code) | ||
|
||
get "/auth/result", params: { code: } | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,28 +17,30 @@ | |
config.shared_context_metadata_behavior = :apply_to_host_groups | ||
end | ||
|
||
# rubocop:disable Metrics/AbcSize | ||
def create_and_log_in_user(user_attrs = {}) | ||
user = create_user(user_attrs) | ||
code = "ABC123" | ||
login_gov = instance_double(LoginGov) | ||
allow(LoginGov).to receive(:new).and_return(login_gov) | ||
allow(login_gov).to receive(:exchange_token_from_auth_result).with(code).and_return( | ||
[{ email: user.email, sub: user.token }] | ||
) | ||
|
||
# rubocop:disable Layout/LineLength, RSpec/AnyInstance | ||
allow_any_instance_of(SessionsController).to receive(:send_user_jwt_to_phoenix).with(instance_of(String)).and_return(true) | ||
# rubocop:enable Layout/LineLength, RSpec/AnyInstance | ||
mock_login_gov(user, code) | ||
|
||
get "/auth/result", params: { code: } | ||
user | ||
end | ||
# rubocop:enable Metrics/AbcSize | ||
|
||
def create_user(user_attrs = {}) | ||
email = "[email protected]" | ||
token = SecureRandom.uuid | ||
user_attrs = { email:, token: }.merge(user_attrs) | ||
User.create!(user_attrs) | ||
end | ||
|
||
def mock_login_gov(user, code = "ABC123") # rubocop:disable Metrics/AbcSize | ||
login_gov = instance_double(LoginGov) | ||
allow(LoginGov).to receive(:new).and_return(login_gov) | ||
allow(login_gov).to receive(:exchange_token_from_auth_result).with(code).and_return( | ||
[{ email: user.email, sub: user.token }] | ||
) | ||
|
||
allow_any_instance_of(SessionsController).to( # rubocop:disable RSpec/AnyInstance | ||
receive(:send_user_jwt_to_phoenix).with(instance_of(String)).and_return(true) | ||
) | ||
end |