Skip to content

Commit 2a2a38b

Browse files
committed
Add language to Mailer
When a form is submitted in Welsh, we include a message in the email to inform the processor.
1 parent 9555d5b commit 2a2a38b

File tree

7 files changed

+55
-1
lines changed

7 files changed

+55
-1
lines changed

app/mailers/aws_ses_form_submission_mailer.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ def submission_email(answer_content_html:, answer_content_plain_text:, submissio
1010
@subject = email_subject
1111
@csv_filename = csv_filename
1212
@json_filename = json_filename
13+
@welsh_submission = submission.submission_locale.to_sym == :cy
1314

1415
files.each do |name, file|
1516
attachments[name] = {

app/views/aws_ses_form_submission_mailer/submission_email.html.erb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@
99
<p>
1010
<%= I18n.t("mailer.submission.time", time: @submission.submission_time.strftime("%l:%M%P").strip, date: @submission.submission_time.strftime("%-d %B %Y") ) %>
1111
</p>
12+
<p>
13+
<% if @welsh_submission %>
14+
<%= I18n.t("mailer.submission.welsh_submission") %>
15+
<% end %>
16+
</p>
1217
<p>
1318
<%= I18n.t("mailer.submission.reference", submission_reference: @submission.reference) %>
1419
</p>

app/views/aws_ses_form_submission_mailer/submission_email.text.erb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@
66

77
<%= I18n.t("mailer.submission.time", time: @submission.submission_time.strftime("%l:%M%P").strip, date: @submission.submission_time.strftime("%-d %B %Y") ) %>
88

9+
<% if @welsh_submission %>
10+
<%= I18n.t("mailer.submission.welsh_submission") %>
11+
<% end %>
12+
913
<%= I18n.t("mailer.submission.reference", submission_reference: @submission.reference) %>
1014

1115
<% if @submission.payment_url.present? %>

config/locales/cy.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ cy:
448448
subject_preview: 'TEST FORM SUBMISSION: %{form_name} - reference: %{reference}'
449449
time: 'Submitted at: %{time} on %{date}'
450450
title: 'Form name: “%{form_name}”'
451+
welsh_submission: At least one of the questions was answered in Welsh
451452
submission_confirmation:
452453
default_support_contact_details: The form’s contact details for support will appear here once they’ve been added.
453454
default_what_happens_next: The form’s information about what happens next will appear here once it has been added.

config/locales/en.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ en:
448448
subject_preview: 'TEST FORM SUBMISSION: %{form_name} - reference: %{reference}'
449449
time: 'Submitted at: %{time} on %{date}'
450450
title: 'Form name: “%{form_name}”'
451+
welsh_submission: At least one of the questions was answered in Welsh
451452
submission_confirmation:
452453
default_support_contact_details: The form’s contact details for support will appear here once they’ve been added.
453454
default_what_happens_next: The form’s information about what happens next will appear here once it has been added.

spec/mailers/aws_ses_form_submission_mailer_preview.rb

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,15 @@ def submission_email_with_payment_link
2828
files: {})
2929
end
3030

31+
def submission_email_with_welsh
32+
form_document = build(:v2_form_document, submission_email: "testing@gov.uk", payment_url: "https://www.gov.uk/payments/your-payment-link")
33+
submission = build(:submission, form_document:, is_preview: false, submission_locale: :cy)
34+
AwsSesFormSubmissionMailer.submission_email(answer_content_html: "<h3>What's your email address?</h3><p>forms@example.gov.uk</p>",
35+
answer_content_plain_text: "What's your email address?\n\nforms@example.gov.uk",
36+
submission:,
37+
files: {})
38+
end
39+
3140
def submission_email_with_csv
3241
form_document = build(:v2_form_document, submission_email: "testing@gov.uk", payment_url: "https://www.gov.uk/payments/your-payment-link")
3342
submission = build(:submission, form_document:, is_preview: false)

spec/mailers/aws_ses_form_submission_mailer_spec.rb

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
let(:submission) do
77
build(:submission, form_document: form_document, created_at: submission_timestamp,
8-
reference: submission_reference, is_preview:)
8+
reference: submission_reference, is_preview:, submission_locale:)
99
end
1010
let(:form_document) { build(:v2_form_document, name: form_name, submission_email: submission_email_address, payment_url:) }
1111
let(:form_name) { "Form 1" }
@@ -19,6 +19,7 @@
1919
let(:csv_filename) { nil }
2020
let(:json_filename) { nil }
2121
let(:submission_timestamp) { Time.utc(2022, 12, 14, 13, 0o0, 0o0) }
22+
let(:submission_locale) { :en }
2223

2324
context "when form filler submits a completed form" do
2425
context "when form is not in preview" do
@@ -92,6 +93,22 @@
9293
end
9394
end
9495
end
96+
97+
describe "submission_locale" do
98+
context "with a submission in English" do
99+
it "does not include the Welsh submission text" do
100+
expect(part.body).not_to match("Welsh")
101+
end
102+
end
103+
104+
context "with a submission in Welsh" do
105+
let(:submission_locale) { :cy }
106+
107+
it "includes the Welsh submission text" do
108+
expect(part.body).to match("Welsh")
109+
end
110+
end
111+
end
95112
end
96113

97114
describe "the plaintext part" do
@@ -148,6 +165,22 @@
148165
end
149166
end
150167
end
168+
169+
describe "submission_locale" do
170+
context "with a submission in English" do
171+
it "does not include the Welsh submission text" do
172+
expect(part.body).not_to match("Welsh")
173+
end
174+
end
175+
176+
context "with a submission in Welsh" do
177+
let(:submission_locale) { :cy }
178+
179+
it "includes the Welsh submission text" do
180+
expect(part.body).to match("Welsh")
181+
end
182+
end
183+
end
151184
end
152185
end
153186

0 commit comments

Comments
 (0)