docbrown/spec/workers/users/delete_worker_spec.rb
Mac Siri e38196df6f
Create Settings::SMTP (#13943)
* Fix typo

* Add SMTP configs to Settings::General

* Expand Settings's show page

* Expand Settings::General's constants

* Move smtp_enabled? logic to ApplicationMailer

* Apply suggestions from code review

Co-authored-by: Ridhwana <Ridhwana.Khan16@gmail.com>

* Add missing descriptions and placeholders

* Remove production guard clause

* Change delivery_method to a callback

* Create Settings::SMTP

* Run migration

* Move constants

* Remove SMTP from Settings::General

* Create SMTPSettingsController

* Add back guard clause

* Change which perform_deliveries configuration to use from

* Update config/environments/production.rb

* Rename migration to singular

* Run migration again

* Fix name

* Alphabetize and add validation for authentication

* Move settings and enabled? logic to Settings::SMTP

* Change after_action to before_action

* Fix broken spec

* Fix broken spec

* Create SMTP specs

* Provide default for port

* Create spec for ApplicationMailer

* Fix broken spec

* Move smtp_enabled?

* Search and replace

Co-authored-by: Ridhwana <Ridhwana.Khan16@gmail.com>
2021-06-14 10:29:43 -04:00

73 lines
2.1 KiB
Ruby

require "rails_helper"
RSpec.describe Users::DeleteWorker, type: :worker do
let(:worker) { subject }
let(:mailer_class) { NotifyMailer }
let(:mailer) { double }
let(:message_delivery) { double }
before do
allow(ForemInstance).to receive(:smtp_enabled?).and_return(true)
end
describe "#perform" do
let!(:user) { create(:user) }
let(:delete) { Users::Delete }
context "when user is found" do
it "deletes the user correctly" do
worker.perform(user.id)
expect(User.exists?(id: user.id)).to be(false)
end
it "calls the service when a user is found" do
allow(delete).to receive(:call)
worker.perform(user.id)
expect(delete).to have_received(:call).with(user)
end
it "sends the notification" do
expect do
worker.perform(user.id)
end.to change(ActionMailer::Base.deliveries, :count).by(1)
end
it "doesn't send a notification for admin triggered deletion" do
expect do
worker.perform(user.id, true)
end.not_to change(ActionMailer::Base.deliveries, :count)
end
it "sends the correct notification" do
allow(mailer_class).to receive(:with).and_return(mailer)
allow(mailer).to receive(:account_deleted_email).and_return(message_delivery)
allow(message_delivery).to receive(:deliver_now)
worker.perform(user.id)
expect(mailer_class).to have_received(:with).with(name: user.name, email: user.email)
expect(mailer).to have_received(:account_deleted_email)
expect(message_delivery).to have_received(:deliver_now)
end
it "creates a gdpr-delete record" do
expect do
worker.perform(user.id, true)
end.to change(Users::GdprDeleteRequest, :count).by(1)
end
end
context "when user is not found" do
it "doesn't fail" do
worker.perform(-1)
end
it "doesn't send the notification" do
expect do
worker.perform(-1)
end.not_to change(ActionMailer::Base.deliveries, :count)
end
end
end
end