Skip to content

Commit

Permalink
Add has_unconfirmed_email to update_user_by_subject_identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
barrucadu committed Jun 17, 2021
1 parent 8017e41 commit f2bd922
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# unreleased

* Add functions and test helpers for account-linked email subscriptions.
* Add `has_unconfirmed_email` option to `update_user_by_subject_identifier`.

# 71.4.0

Expand Down
15 changes: 11 additions & 4 deletions lib/gds_api/account_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,19 @@ def get_user(govuk_account_session:)
# Update the user record with privileged information from the auth service. Only the auth service will call this.
#
# @param [String] subject_identifier The identifier of the user, shared between the auth service and GOV.UK.
# @param [String, nil] email The new email address
# @param [Boolean, nil] email_verified Whether the new email address is verified
# @param [String, nil] email The user's current
# @param [Boolean, nil] email_verified Whether the user's current email address is verified
# @param [Boolean, nil] has_unconfirmed_email Whether the user has a new, pending, email address
#
# @return [Hash] The user's subject identifier and email attributes
def update_user_by_subject_identifier(subject_identifier:, email: nil, email_verified: nil)
patch_json("#{endpoint}/api/oidc-users/#{subject_identifier}", { email: email, email_verified: email_verified }.compact)
def update_user_by_subject_identifier(subject_identifier:, email: nil, email_verified: nil, has_unconfirmed_email: nil)
params = {
email: email,
email_verified: email_verified,
has_unconfirmed_email: has_unconfirmed_email,
}.compact

patch_json("#{endpoint}/api/oidc-users/#{subject_identifier}", params)
end

# Check if a user has an email subscription for the Transition Checker
Expand Down
5 changes: 3 additions & 2 deletions lib/gds_api/test_helpers/account_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -95,15 +95,16 @@ def stub_account_api_unauthorized_user_info(**options)
###########################################
# PATCH /api/oidc-users/:subject_identifier
###########################################
def stub_update_user_by_subject_identifier(subject_identifier:, email: nil, email_verified: nil, old_email: nil, old_email_verified: nil)
def stub_update_user_by_subject_identifier(subject_identifier:, email: nil, email_verified: nil, has_unconfirmed_email: nil, old_email: nil, old_email_verified: nil, old_has_unconfirmed_email: nil)
stub_account_api_request(
:patch,
"/api/oidc-users/#{subject_identifier}",
with: { body: hash_including({ email: email, email_verified: email_verified }.compact) },
with: { body: hash_including({ email: email, email_verified: email_verified, has_unconfirmed_email: has_unconfirmed_email }.compact) },
response_body: {
sub: subject_identifier,
email: email || old_email,
email_verified: email_verified || old_email_verified,
has_unconfirmed_email: has_unconfirmed_email || old_has_unconfirmed_email,
},
)
end
Expand Down
4 changes: 2 additions & 2 deletions test/account_api_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@
email_attributes = {
email: "[email protected]",
email_verified: true,
has_unconfirmed_email: false,
}
response_body = email_attributes.merge(sub: subject_identifier)

Expand All @@ -106,8 +107,7 @@

api_client.update_user_by_subject_identifier(
subject_identifier: subject_identifier,
email: email_attributes[:email],
email_verified: email_attributes[:email_verified],
**email_attributes,
)
end
end
Expand Down

0 comments on commit f2bd922

Please sign in to comment.