Browse Source

Send a different email is only one organisation is absorbed

pull/2078/head
Kat 2 years ago
parent
commit
152164f39c
  1. 39
      app/mailers/merge_completion_mailer.rb
  2. 7
      spec/mailers/merge_completion_mailer_spec.rb

39
app/mailers/merge_completion_mailer.rb

@ -1,6 +1,7 @@
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(
@ -16,20 +17,30 @@ class MergeCompletionMailer < NotifyMailer
end
def send_absorbing_organisation_success_mail(email, merged_organisations, absorbing_organisation_name, merge_date)
organisation_count = merged_organisations.count.to_s + " organisation".pluralize(merged_organisations.count)
pluralised_organisation = merged_organisations.count > 1 ? "these organisations" : "this organisation"
merged_organisation_list = (merged_organisations.count > 1 ? "The organisations are " : "The organisation is ") + merged_organisations.to_sentence(last_word_connector: " and ")
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),
pluralised_organisation:,
},
)
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

7
spec/mailers/merge_completion_mailer_spec.rb

@ -31,13 +31,11 @@ RSpec.describe MergeCompletionMailer do
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::MERGE_COMPLETION_ABSORBING_ORGANISATION_TEMPLATE_ID,
template_id: MergeCompletionMailer::ONE_ORG_MERGE_COMPLETION_ABSORBING_ORGANISATION_TEMPLATE_ID,
personalisation: hash_including({
organisation_count: "1 organisation",
merged_organisations: "The organisation is merged organisation",
merged_organisation: "merged organisation",
absorbing_organisation_name: "absorbing organisation",
merge_date: "1 January 2023",
pluralised_organisation: "this organisation",
}),
}))
@ -52,7 +50,6 @@ RSpec.describe MergeCompletionMailer do
merged_organisations: "The organisations are merged organisation and other organisation",
absorbing_organisation_name: "absorbing organisation",
merge_date: "1 January 2023",
pluralised_organisation: "these organisations",
}),
}))

Loading…
Cancel
Save