Browse Source
* Send success email to merged users * Update template id, date and remove username * Send absorbing organisation success mail * Update absorbing organisation email * Only send emails to active users * typo * Send a different email is only one organisation is absorbedpull/2088/head
kosiakkatrina
1 year ago
committed by
GitHub
4 changed files with 207 additions and 2 deletions
@ -0,0 +1,46 @@
|
||||
class MergeCompletionMailer < NotifyMailer |
||||
MERGE_COMPLETION_MERGING_ORGANISATION_TEMPLATE_ID = "b3b62e72-5ced-4515-8720-08bdc7bac792".freeze |
||||
MERGE_COMPLETION_ABSORBING_ORGANISATION_TEMPLATE_ID = "7cdfefac-84c3-4054-8bd9-63103b3847b6".freeze |
||||
ONE_ORG_MERGE_COMPLETION_ABSORBING_ORGANISATION_TEMPLATE_ID = "35456951-2046-468e-9f41-a620e94db203".freeze |
||||
|
||||
def send_merged_organisation_success_mail(email, merged_organisation_name, absorbing_organisation_name, merge_date) |
||||
send_email( |
||||
email, |
||||
MERGE_COMPLETION_MERGING_ORGANISATION_TEMPLATE_ID, |
||||
{ |
||||
merged_organisation_name:, |
||||
absorbing_organisation_name:, |
||||
merge_date: merge_date.to_formatted_s(:govuk_date), |
||||
email:, |
||||
}, |
||||
) |
||||
end |
||||
|
||||
def send_absorbing_organisation_success_mail(email, merged_organisations, absorbing_organisation_name, merge_date) |
||||
if merged_organisations.count > 1 |
||||
organisation_count = merged_organisations.count.to_s + " organisation".pluralize(merged_organisations.count) |
||||
merged_organisation_list = "The organisations are #{merged_organisations.to_sentence(last_word_connector: ' and ')}" |
||||
|
||||
send_email( |
||||
email, |
||||
MERGE_COMPLETION_ABSORBING_ORGANISATION_TEMPLATE_ID, |
||||
{ |
||||
organisation_count:, |
||||
merged_organisations: merged_organisation_list, |
||||
absorbing_organisation_name:, |
||||
merge_date: merge_date.to_formatted_s(:govuk_date), |
||||
}, |
||||
) |
||||
else |
||||
send_email( |
||||
email, |
||||
ONE_ORG_MERGE_COMPLETION_ABSORBING_ORGANISATION_TEMPLATE_ID, |
||||
{ |
||||
merged_organisation: merged_organisations.first, |
||||
absorbing_organisation_name:, |
||||
merge_date: merge_date.to_formatted_s(:govuk_date), |
||||
}, |
||||
) |
||||
end |
||||
end |
||||
end |
@ -0,0 +1,59 @@
|
||||
require "rails_helper" |
||||
|
||||
RSpec.describe MergeCompletionMailer do |
||||
let(:notify_client) { instance_double(Notifications::Client) } |
||||
|
||||
before do |
||||
allow(Notifications::Client).to receive(:new).and_return(notify_client) |
||||
allow(notify_client).to receive(:send_email).and_return(true) |
||||
end |
||||
|
||||
describe "#send_merged_organisation_success_mail" do |
||||
let(:merge_date) { Time.zone.local(2023, 1, 1) } |
||||
|
||||
it "sends a merge completion E-mail via notify" do |
||||
expect(notify_client).to receive(:send_email).with(hash_including({ |
||||
template_id: MergeCompletionMailer::MERGE_COMPLETION_MERGING_ORGANISATION_TEMPLATE_ID, |
||||
personalisation: hash_including({ |
||||
merged_organisation_name: "merged organisation", |
||||
absorbing_organisation_name: "absorbing organisation", |
||||
merge_date: "1 January 2023", |
||||
email: "user@example.com", |
||||
}), |
||||
})) |
||||
|
||||
described_class.new.send_merged_organisation_success_mail("user@example.com", "merged organisation", "absorbing organisation", merge_date) |
||||
end |
||||
end |
||||
|
||||
describe "#send_absorbing_organisation_success_mail" do |
||||
let(:merge_date) { Time.zone.local(2023, 1, 1) } |
||||
|
||||
it "sends a merge completion E-mail via notify for a single merge" do |
||||
expect(notify_client).to receive(:send_email).with(hash_including({ |
||||
template_id: MergeCompletionMailer::ONE_ORG_MERGE_COMPLETION_ABSORBING_ORGANISATION_TEMPLATE_ID, |
||||
personalisation: hash_including({ |
||||
merged_organisation: "merged organisation", |
||||
absorbing_organisation_name: "absorbing organisation", |
||||
merge_date: "1 January 2023", |
||||
}), |
||||
})) |
||||
|
||||
described_class.new.send_absorbing_organisation_success_mail("user@example.com", ["merged organisation"], "absorbing organisation", merge_date) |
||||
end |
||||
|
||||
it "sends a merge completion E-mail via notify for a multiple org merge" do |
||||
expect(notify_client).to receive(:send_email).with(hash_including({ |
||||
template_id: MergeCompletionMailer::MERGE_COMPLETION_ABSORBING_ORGANISATION_TEMPLATE_ID, |
||||
personalisation: hash_including({ |
||||
organisation_count: "2 organisations", |
||||
merged_organisations: "The organisations are merged organisation and other organisation", |
||||
absorbing_organisation_name: "absorbing organisation", |
||||
merge_date: "1 January 2023", |
||||
}), |
||||
})) |
||||
|
||||
described_class.new.send_absorbing_organisation_success_mail("user@example.com", ["merged organisation", "other organisation"], "absorbing organisation", merge_date) |
||||
end |
||||
end |
||||
end |
Loading…
Reference in new issue