diff --git a/CHANGELOG.md b/CHANGELOG.md index 4653c46f..1253f828 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/gds_api/account_api.rb b/lib/gds_api/account_api.rb index 27aadbde..ded5fd06 100644 --- a/lib/gds_api/account_api.rb +++ b/lib/gds_api/account_api.rb @@ -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 diff --git a/lib/gds_api/test_helpers/account_api.rb b/lib/gds_api/test_helpers/account_api.rb index 359a355d..6e04f3e0 100644 --- a/lib/gds_api/test_helpers/account_api.rb +++ b/lib/gds_api/test_helpers/account_api.rb @@ -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 diff --git a/test/account_api_test.rb b/test/account_api_test.rb index b34f0a31..82dda92d 100644 --- a/test/account_api_test.rb +++ b/test/account_api_test.rb @@ -96,6 +96,7 @@ email_attributes = { email: "example.email.address@gov.uk", email_verified: true, + has_unconfirmed_email: false, } response_body = email_attributes.merge(sub: subject_identifier) @@ -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