-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #742 from alphagov/unsubscribe-email-subscriptions
Delete subscriptions on manually deleting account
- Loading branch information
Showing
3 changed files
with
37 additions
and
6 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
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
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 |
---|---|---|
@@ -1,6 +1,10 @@ | ||
require "gds_api/test_helpers/email_alert_api" | ||
|
||
Rails.application.load_tasks | ||
|
||
RSpec.describe "Support tasks" do | ||
include GdsApi::TestHelpers::EmailAlertApi | ||
|
||
describe ":find_user" do | ||
subject(:task) { Rake.application["support:find_user"] } | ||
|
||
|
@@ -24,9 +28,7 @@ | |
end | ||
|
||
describe ":delete_user" do | ||
before do | ||
FactoryBot.create(:oidc_user, email: "[email protected]", sub: "123") | ||
end | ||
let!(:user) { FactoryBot.create(:oidc_user, email: "[email protected]", sub: "123") } | ||
|
||
context "when a dry run" do | ||
subject(:task) { Rake.application["support:delete_user:dry_run"] } | ||
|
@@ -47,18 +49,33 @@ | |
|
||
context "when a user with email exists" do | ||
it "reports that the user has been deleted" do | ||
stub_email_alert_api_find_subscriber_by_govuk_account_no_subscriber(user.id) | ||
|
||
expect { task.execute({ email: "[email protected]" }) }.to output("User '[email protected]' deleted\nUser sub: 123\n").to_stdout | ||
end | ||
|
||
it "deletes the user" do | ||
stub_email_alert_api_find_subscriber_by_govuk_account_no_subscriber(user.id) | ||
|
||
count = OidcUser.count | ||
task.execute({ email: "[email protected]" }) | ||
expect(OidcUser.count).to eq count - 1 | ||
end | ||
|
||
it "outputs other users don't exist" do | ||
it "outputs if user doesn't exist" do | ||
stub_email_alert_api_find_subscriber_by_govuk_account_no_subscriber(user.id) | ||
|
||
expect { task.execute({ email: "[email protected]" }) }.to output("User '[email protected]' does not exist\n").to_stdout | ||
end | ||
|
||
it "deletes email subscriptions if present" do | ||
stub_email_alert_api_find_subscriber_by_govuk_account(user.id, "iddddd", user.email) | ||
request = stub_email_alert_api_unsubscribes_a_subscriber("iddddd") | ||
|
||
task.execute({ email: user.email }) | ||
|
||
expect(request).to have_been_requested | ||
end | ||
end | ||
end | ||
end | ||
|