Skip to content

Commit

Permalink
Add logic and helpers for account api delete user
Browse files Browse the repository at this point in the history
  • Loading branch information
huwd committed Jul 27, 2021
1 parent 732c893 commit c8ca830
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/gds_api/account_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ def get_user(govuk_account_session:)
get_json("#{endpoint}/api/user", auth_headers(govuk_account_session))
end

# Delete a users account
#
# @param [String] subject_identifier The identifier of the user, shared between the auth service and GOV.UK.
def delete_user_by_subject_identifier(subject_identifier:)
delete_json("#{endpoint}/api/oidc-users/#{subject_identifier}")
end

# 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.
Expand Down
20 changes: 20 additions & 0 deletions lib/gds_api/test_helpers/account_api.rb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,26 @@ def stub_account_api_unauthorized_user_info(**options)
)
end

############################################
# DELETE /api/oidc-users/:subject_identifier
############################################

def stub_account_api_delete_user_by_subject_identifier(subject_identifier:)
stub_account_api_request(
:delete,
"/api/oidc-users/#{subject_identifier}",
response_status: 204,
)
end

def stub_account_api_delete_user_by_subject_identifier_does_not_exist(subject_identifier:)
stub_account_api_request(
:delete,
"/api/oidc-users/#{subject_identifier}",
response_status: 404,
)
end

###########################################
# PATCH /api/oidc-users/:subject_identifier
###########################################
Expand Down
14 changes: 14 additions & 0 deletions test/account_api/account_api_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,20 @@
end
end

describe "#delete_user_by_subject_identifier" do
it "returns 204 if the account is successfully deleted" do
stub_account_api_delete_user_by_subject_identifier(subject_identifier: "sid")
assert_equal(204, api_client.delete_user_by_subject_identifier(subject_identifier: "sid").code)
end

it "returns 404 if the user cannot be found" do
stub_account_api_delete_user_by_subject_identifier_does_not_exist(subject_identifier: "sid")
assert_raises GdsApi::HTTPNotFound do
api_client.delete_user_by_subject_identifier(subject_identifier: "sid")
end
end
end

describe "#update_user_by_subject_identifier" do
it "updates the user's email attributes" do
stub_update_user_by_subject_identifier(subject_identifier: "sid", email_verified: true, old_email: "[email protected]")
Expand Down

0 comments on commit c8ca830

Please sign in to comment.