Skip to content

Commit 6f78a46

Browse files
authored
Merge pull request #2110 from govuk-forms/remove-mailer-options-data-object
Remove MailerOptions Data object used by confirmation email mailer
2 parents 26bb815 + 5b41679 commit 6f78a46

5 files changed

Lines changed: 118 additions & 167 deletions

File tree

app/jobs/send_confirmation_email_job.rb

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,17 @@
11
class SendConfirmationEmailJob < ApplicationJob
22
queue_as :confirmation_emails
3-
MailerOptions = Data.define(:title, :is_preview, :timestamp, :submission_reference, :payment_url)
43

54
def perform(submission:, notify_response_id:, confirmation_email_address:)
65
set_submission_logging_attributes(submission:)
76

87
form = submission.form
98
welsh_form = fetch_welsh_form(submission:, form:)
109
mail = FormSubmissionConfirmationMailer.send_confirmation_email(
11-
what_happens_next_markdown: form.what_happens_next_markdown,
12-
what_happens_next_markdown_cy: welsh_form&.what_happens_next_markdown,
13-
support_contact_details: form.support_details,
14-
support_contact_details_cy: welsh_form&.support_details,
10+
form:,
11+
welsh_form:,
12+
submission:,
1513
notify_response_id:,
1614
confirmation_email_address:,
17-
mailer_options: mailer_options_for(submission:, form:),
18-
submission_locale: submission.submission_locale,
1915
)
2016

2117
mail.deliver_now
@@ -27,16 +23,6 @@ def perform(submission:, notify_response_id:, confirmation_email_address:)
2723

2824
private
2925

30-
def mailer_options_for(submission:, form:)
31-
MailerOptions.new(
32-
title: form.name,
33-
is_preview: submission.preview?,
34-
timestamp: submission.submission_time,
35-
submission_reference: submission.reference,
36-
payment_url: submission.payment_url,
37-
)
38-
end
39-
4026
def fetch_welsh_form(submission:, form:)
4127
return nil unless submission.submission_locale.to_sym == :cy
4228

app/mailers/form_submission_confirmation_mailer.rb

Lines changed: 26 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,24 @@
11
class FormSubmissionConfirmationMailer < GovukNotifyRails::Mailer
22
include NotifyUtils
33

4-
def send_confirmation_email(what_happens_next_markdown:, support_contact_details:, notify_response_id:, confirmation_email_address:, mailer_options:, submission_locale: :en, what_happens_next_markdown_cy: nil, support_contact_details_cy: nil)
5-
@submission_locale = submission_locale.to_sym
4+
def send_confirmation_email(form:, welsh_form:, submission:, notify_response_id:, confirmation_email_address:)
5+
@submission_locale = submission.submission_locale.to_sym
66
set_template(template_id)
77

8+
what_happens_next_text = form.what_happens_next_markdown.presence || default_what_happens_next_text
89
set_personalisation(
9-
title: mailer_options.title,
10-
what_happens_next_text: what_happens_next_markdown.presence || default_what_happens_next_text,
11-
what_happens_next_text_cy: what_happens_next_markdown_cy.presence || what_happens_next_markdown.presence || default_what_happens_next_text,
12-
support_contact_details: format_support_details(support_contact_details).presence || default_support_contact_details_text,
13-
support_contact_details_cy: format_support_details(support_contact_details_cy || support_contact_details, locale: :cy).presence || default_support_contact_details_text,
14-
submission_time: mailer_options.timestamp.strftime("%l:%M%P").strip,
15-
submission_date: I18n.l(mailer_options.timestamp, format: "%-d %B %Y", locale: :en),
16-
submission_date_cy: I18n.l(mailer_options.timestamp, format: "%-d %B %Y", locale: :cy),
17-
# GOV.UK Notify's templates have conditionals, but only positive
18-
# conditionals, so to simulate negative conditionals we add two boolean
19-
# flags; but they must always have opposite values!
20-
test: make_notify_boolean(mailer_options.is_preview),
21-
submission_reference: mailer_options.submission_reference,
22-
include_payment_link: make_notify_boolean(mailer_options.payment_url.present?),
23-
payment_link: mailer_options.payment_url || "",
10+
title: form.name,
11+
what_happens_next_text:,
12+
what_happens_next_text_cy: welsh_form&.what_happens_next_markdown.presence || what_happens_next_text,
13+
support_contact_details: format_support_details(form.support_details).presence || default_support_contact_details_text,
14+
support_contact_details_cy: welsh_support_details(form, welsh_form),
15+
submission_time: submission.submission_time.strftime("%l:%M%P").strip,
16+
submission_date: I18n.l(submission.submission_time, format: "%-d %B %Y", locale: :en),
17+
submission_date_cy: I18n.l(submission.submission_time, format: "%-d %B %Y", locale: :cy),
18+
test: make_notify_boolean(submission.preview?),
19+
submission_reference: submission.reference,
20+
include_payment_link: make_notify_boolean(submission.payment_url.present?),
21+
payment_link: submission.payment_url || "",
2422
)
2523

2624
set_reference(notify_response_id)
@@ -31,11 +29,11 @@ def send_confirmation_email(what_happens_next_markdown:, support_contact_details
3129
end
3230

3331
def format_support_details(support_details, locale: :en)
34-
phone = support_details.phone
35-
call_charges_url = support_details.call_charges_url
36-
email = support_details.email
37-
url = support_details.url
38-
url_text = support_details.url_text
32+
phone = support_details&.phone
33+
call_charges_url = support_details&.call_charges_url
34+
email = support_details&.email
35+
url = support_details&.url
36+
url_text = support_details&.url_text
3937

4038
support_details = []
4139
support_details << normalize_whitespace(phone) if phone.present?
@@ -48,6 +46,12 @@ def format_support_details(support_details, locale: :en)
4846

4947
private
5048

49+
def welsh_support_details(form, welsh_form)
50+
format_support_details(welsh_form&.support_details, locale: :cy).presence ||
51+
format_support_details(form.support_details, locale: :cy).presence ||
52+
default_support_contact_details_text
53+
end
54+
5155
def default_what_happens_next_text
5256
I18n.t("mailer.submission_confirmation.default_what_happens_next")
5357
end

app/services/form_submission_service.rb

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ def call(**args)
99
end
1010
end
1111

12-
MailerOptions = Data.define(:title, :is_preview, :timestamp, :submission_reference, :payment_url)
13-
1412
def initialize(current_context:, email_confirmation_input:, mode:)
1513
@current_context = current_context
1614
@form = current_context.form

spec/jobs/send_confirmation_email_job_spec.rb

Lines changed: 6 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -54,30 +54,16 @@
5454
)
5555

5656
expect(FormSubmissionConfirmationMailer).to have_received(:send_confirmation_email).with(
57-
what_happens_next_markdown: "Please wait for a response",
58-
what_happens_next_markdown_cy: nil,
59-
support_contact_details: have_attributes(
60-
phone: "0203 222 2222",
61-
call_charges_url: "https://www.gov.uk/call-charges",
62-
email: "help@example.gov.uk",
63-
url: "https://example.gov.uk/help",
64-
url_text: "Get help",
65-
),
66-
support_contact_details_cy: nil,
57+
form: submission.form,
58+
welsh_form: nil,
59+
submission:,
6760
notify_response_id: "confirmation-ref",
6861
confirmation_email_address: "testing@gov.uk",
69-
mailer_options: an_instance_of(SendConfirmationEmailJob::MailerOptions),
70-
submission_locale: "en",
7162
)
7263
end
7364

7465
context "when submission locale is Welsh" do
75-
let(:welsh_form_document) do
76-
build(:v2_form_document,
77-
what_happens_next_markdown: "Arhoswch am ymateb",
78-
support_phone: "0291 111 1111",
79-
support_email: "cymraeg@example.gov.uk")
80-
end
66+
let(:welsh_form_document) { build(:v2_form_document, name: "Welsh Form") }
8167

8268
before do
8369
submission.update!(submission_locale: "cy")
@@ -100,21 +86,7 @@
10086
expect(mail.govuk_notify_template).to eq("7891011")
10187
end
10288

103-
it "passes the Welsh what happens next to the mailer" do
104-
allow(FormSubmissionConfirmationMailer).to receive(:send_confirmation_email).and_call_original
105-
106-
described_class.perform_now(
107-
submission:,
108-
notify_response_id:,
109-
confirmation_email_address:,
110-
)
111-
112-
expect(FormSubmissionConfirmationMailer).to have_received(:send_confirmation_email).with(
113-
hash_including(what_happens_next_markdown_cy: "Arhoswch am ymateb"),
114-
)
115-
end
116-
117-
it "passes the Welsh support details" do
89+
it "passes the Welsh form to the mailer" do
11890
allow(FormSubmissionConfirmationMailer).to receive(:send_confirmation_email).and_call_original
11991

12092
described_class.perform_now(
@@ -124,10 +96,7 @@
12496
)
12597

12698
expect(FormSubmissionConfirmationMailer).to have_received(:send_confirmation_email).with(
127-
hash_including(support_contact_details_cy: have_attributes(
128-
phone: "0291 111 1111",
129-
email: "cymraeg@example.gov.uk",
130-
)),
99+
hash_including(welsh_form: have_attributes(name: welsh_form_document.name)),
131100
)
132101
end
133102
end

0 commit comments

Comments
 (0)