Skip to content

Commit ca7e25d

Browse files
Merge pull request #1484 from alphagov/theseanything/send-confirmation-emails
Send confirmation emails when config missing
2 parents 5d5501d + 409f742 commit ca7e25d

6 files changed

Lines changed: 48 additions & 32 deletions

File tree

app/mailers/form_submission_confirmation_mailer.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ def send_confirmation_email(what_happens_next_markdown:, support_contact_details
44

55
set_personalisation(
66
title: mailer_options.title,
7-
what_happens_next_text: what_happens_next_markdown,
8-
support_contact_details:,
7+
what_happens_next_text: what_happens_next_markdown.presence || default_what_happens_next_text,
8+
support_contact_details: support_contact_details.presence || default_support_contact_details_text,
99
submission_time: mailer_options.timestamp.strftime("%l:%M%P").strip,
1010
submission_date: I18n.l(mailer_options.timestamp, format: "%-d %B %Y"),
1111
# GOV.UK Notify's templates have conditionals, but only positive
@@ -26,6 +26,14 @@ def send_confirmation_email(what_happens_next_markdown:, support_contact_details
2626

2727
private
2828

29+
def default_what_happens_next_text
30+
I18n.t("mailer.submission_confirmation.default_what_happens_next")
31+
end
32+
33+
def default_support_contact_details_text
34+
I18n.t("mailer.submission_confirmation.default_support_contact_details")
35+
end
36+
2937
def make_notify_boolean(bool)
3038
bool ? "yes" : "no"
3139
end

app/services/form_submission_service.rb

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,6 @@ def submit_using_form_submission_type
4545
end
4646

4747
def submit_confirmation_email_to_user
48-
unless @form.what_happens_next_markdown.present? && has_support_contact_details?
49-
Rails.logger.info "Skipping sending confirmation email to user as what happens next and support contact details have not been set"
50-
return nil
51-
end
52-
5348
mail = FormSubmissionConfirmationMailer.send_confirmation_email(
5449
what_happens_next_markdown: @form.what_happens_next_markdown,
5550
support_contact_details: formatted_support_details,

config/locales/cy.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,9 @@ cy:
421421
time: This form was submitted at %{time} on %{date}
422422
title: This is a completed “%{title}” form.
423423
title_preview: This is a test of the “%{title}” form.
424+
submission_confirmation:
425+
default_support_contact_details: The form’s contact details for support will appear here once they’ve been added.
426+
default_what_happens_next: The form’s information about what happens next will appear here once it has been added.
424427
mode:
425428
phase_banner_tag_preview-archived: Archived preview
426429
phase_banner_tag_preview-draft: Draft preview

config/locales/en.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,9 @@ en:
421421
time: This form was submitted at %{time} on %{date}
422422
title: This is a completed “%{title}” form.
423423
title_preview: This is a test of the “%{title}” form.
424+
submission_confirmation:
425+
default_support_contact_details: The form’s contact details for support will appear here once they’ve been added.
426+
default_what_happens_next: The form’s information about what happens next will appear here once it has been added.
424427
mode:
425428
phase_banner_tag_preview-archived: Archived preview
426429
phase_banner_tag_preview-draft: Draft preview

spec/mailers/form_submission_confirmation_mailer_spec.rb

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,38 @@
6868
expect(mail.govuk_notify_personalisation[:support_contact_details]).to eq("Call: 0203 222 2222")
6969
end
7070

71+
context "when what happens next is missing" do
72+
let(:what_happens_next_markdown) { nil }
73+
74+
it "uses placeholder text" do
75+
expect(mail.govuk_notify_personalisation[:what_happens_next_text]).to eq(I18n.t("mailer.submission_confirmation.default_what_happens_next"))
76+
end
77+
end
78+
79+
context "when what happens next is blank" do
80+
let(:what_happens_next_markdown) { "" }
81+
82+
it "uses placeholder text" do
83+
expect(mail.govuk_notify_personalisation[:what_happens_next_text]).to eq(I18n.t("mailer.submission_confirmation.default_what_happens_next"))
84+
end
85+
end
86+
87+
context "when support contact details are missing" do
88+
let(:support_contact_details) { nil }
89+
90+
it "uses placeholder text" do
91+
expect(mail.govuk_notify_personalisation[:support_contact_details]).to eq(I18n.t("mailer.submission_confirmation.default_support_contact_details"))
92+
end
93+
end
94+
95+
context "when support contact details are blank" do
96+
let(:support_contact_details) { "" }
97+
98+
it "uses placeholder text" do
99+
expect(mail.govuk_notify_personalisation[:support_contact_details]).to eq(I18n.t("mailer.submission_confirmation.default_support_contact_details"))
100+
end
101+
end
102+
71103
it "includes an email reference (mostly used to retrieve specific email in notify for e2e tests)" do
72104
expect(mail.govuk_notify_reference).to eq("for-my-ref")
73105
end

spec/services/form_submission_service_spec.rb

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -252,31 +252,6 @@
252252
expect(FormSubmissionConfirmationMailer).not_to have_received(:send_confirmation_email)
253253
end
254254
end
255-
256-
context "when form is draft" do
257-
context "when form does not have 'what happens next details'" do
258-
let(:what_happens_next_markdown) { nil }
259-
260-
it "does not call FormSubmissionConfirmationMailer" do
261-
allow(FormSubmissionConfirmationMailer).to receive(:send_confirmation_email)
262-
service.submit
263-
expect(FormSubmissionConfirmationMailer).not_to have_received(:send_confirmation_email)
264-
end
265-
end
266-
267-
context "when form does not have any support details" do
268-
let(:support_email) { nil }
269-
let(:support_phone) { nil }
270-
let(:support_url) { nil }
271-
let(:support_url_text) { nil }
272-
273-
it "does not call FormSubmissionConfirmationMailer" do
274-
allow(FormSubmissionConfirmationMailer).to receive(:send_confirmation_email)
275-
service.submit
276-
expect(FormSubmissionConfirmationMailer).not_to have_received(:send_confirmation_email)
277-
end
278-
end
279-
end
280255
end
281256
end
282257

0 commit comments

Comments
 (0)