Browse Source

Only send emails to active users

pull/2078/head
Kat 2 years ago
parent
commit
c0c5944b56
  1. 2
      app/services/merge/merge_organisations_service.rb
  2. 24
      spec/services/merge/merge_organisations_service_spec.rb

2
app/services/merge/merge_organisations_service.rb

@ -154,6 +154,8 @@ private
def send_success_emails
@absorbing_organisation.users.each do |user|
next unless user.active?
merged_organisation, merged_user = find_merged_user_and_organization_by_email(user.email)
if merged_user.present?
MergeCompletionMailer.send_merged_organisation_success_mail(merged_user[:email], merged_organisation, @absorbing_organisation.name, @merge_date).deliver_later

24
spec/services/merge/merge_organisations_service_spec.rb

@ -848,6 +848,18 @@ RSpec.describe Merge::MergeOrganisationsService do
merge_organisations_service.call
end
it "does not send a merge completion E-mail to deactivated merged organisation users" do
merging_organisation_user.update!(active: false)
expect(MergeCompletionMailer).to receive(:send_merged_organisation_success_mail).with(merging_organisation.data_protection_officers.first.email, "fake org", "absorbing org", Time.zone.today).once
expect(MergeCompletionMailer).not_to receive(:send_merged_organisation_success_mail).with(merging_organisation_user.email, "fake org", "absorbing org", Time.zone.today)
expect(MergeCompletionMailer).not_to receive(:send_merged_organisation_success_mail).with(absorbing_organisation.data_protection_officers.first.email, "fake org", "absorbing org", Time.zone.today)
expect(MergeCompletionMailer).not_to receive(:send_merged_organisation_success_mail).with(absorbing_organisation_user.email, "fake org", "absorbing org", Time.zone.today)
merge_organisations_service.call
end
it "sends a merge completion E-mail to the original absorbing organisation users" do
expect(MergeCompletionMailer).to receive(:send_absorbing_organisation_success_mail).with(absorbing_organisation.data_protection_officers.first.email, ["fake org"], "absorbing org", Time.zone.today).once
expect(MergeCompletionMailer).to receive(:send_absorbing_organisation_success_mail).with(absorbing_organisation_user.email, ["fake org"], "absorbing org", Time.zone.today).once
@ -857,6 +869,18 @@ RSpec.describe Merge::MergeOrganisationsService do
merge_organisations_service.call
end
it "does not send a merge completion E-mail to deactivated original absorbing organisation users" do
absorbing_organisation_user.update!(active: false)
expect(MergeCompletionMailer).to receive(:send_absorbing_organisation_success_mail).with(absorbing_organisation.data_protection_officers.first.email, ["fake org"], "absorbing org", Time.zone.today).once
expect(MergeCompletionMailer).not_to receive(:send_absorbing_organisation_success_mail).with(absorbing_organisation_user.email, ["fake org"], "absorbing org", Time.zone.today)
expect(MergeCompletionMailer).not_to receive(:send_absorbing_organisation_success_mail).with(merging_organisation_user.email, ["fake org"], "absorbing org", Time.zone.today)
expect(MergeCompletionMailer).not_to receive(:send_absorbing_organisation_success_mail).with(merging_organisation.data_protection_officers.first.email, ["fake org"], "absorbing org", Time.zone.today)
merge_organisations_service.call
end
end
context "when merging a multiple organisations into an existing organisation" do

Loading…
Cancel
Save