|
1 | 1 | require "rails_helper" |
2 | 2 |
|
3 | 3 | describe FormSubmissionConfirmationMailer, type: :mailer do |
| 4 | + let(:submission_locale) { :en } |
4 | 5 | let(:mail) do |
5 | 6 | described_class.send_confirmation_email(what_happens_next_markdown:, |
6 | 7 | support_contact_details:, |
7 | 8 | notify_response_id: "for-my-ref", |
8 | 9 | confirmation_email_address:, |
9 | | - mailer_options:) |
| 10 | + mailer_options:, |
| 11 | + submission_locale:) |
10 | 12 | end |
11 | 13 | let(:mailer_options) do |
12 | 14 | FormSubmissionService::MailerOptions.new(title:, |
|
30 | 32 | Settings.govuk_notify.form_filler_confirmation_email_welsh_template_id = "7891011" |
31 | 33 | end |
32 | 34 |
|
33 | | - context "when the request locale is not set" do |
34 | | - it "uses the English language template" do |
35 | | - expect(mail.govuk_notify_template).to eq("123456") |
36 | | - end |
37 | | - end |
38 | | - |
39 | | - context "when the request locale is set to :en" do |
40 | | - include_context "with locale set to :en" |
| 35 | + context "when submission_locale is :en" do |
| 36 | + let(:submission_locale) { :en } |
41 | 37 |
|
42 | 38 | it "uses the English language template" do |
43 | 39 | expect(mail.govuk_notify_template).to eq("123456") |
44 | 40 | end |
45 | 41 | end |
46 | 42 |
|
47 | | - context "when the request locale is set to :cy" do |
48 | | - include_context "with locale set to :cy" |
| 43 | + context "when submission_locale is :cy" do |
| 44 | + let(:submission_locale) { :cy } |
49 | 45 |
|
50 | | - it "uses the Welsh language template" do |
| 46 | + it "uses the bilingual template" do |
51 | 47 | expect(mail.govuk_notify_template).to eq("7891011") |
52 | 48 | end |
53 | 49 | end |
|
64 | 60 | expect(mail.govuk_notify_personalisation[:what_happens_next_text]).to eq("Please wait for a response") |
65 | 61 | end |
66 | 62 |
|
| 63 | + context "when what_happens_next_markdown_cy is provided" do |
| 64 | + let(:mail) do |
| 65 | + described_class.send_confirmation_email(what_happens_next_markdown:, |
| 66 | + support_contact_details:, |
| 67 | + notify_response_id: "for-my-ref", |
| 68 | + confirmation_email_address:, |
| 69 | + mailer_options:, |
| 70 | + submission_locale:, |
| 71 | + what_happens_next_markdown_cy: "Arhoswch am ymateb") |
| 72 | + end |
| 73 | + |
| 74 | + it "includes the Welsh what happens next" do |
| 75 | + expect(mail.govuk_notify_personalisation[:what_happens_next_text_cy]).to eq("Arhoswch am ymateb") |
| 76 | + end |
| 77 | + end |
| 78 | + |
| 79 | + context "when what_happens_next_markdown_cy is not provided" do |
| 80 | + it "falls back to the English what happens next" do |
| 81 | + expect(mail.govuk_notify_personalisation[:what_happens_next_text_cy]).to eq("Please wait for a response") |
| 82 | + end |
| 83 | + end |
| 84 | + |
67 | 85 | it "includes the forms support contact details" do |
68 | 86 | expect(mail.govuk_notify_personalisation[:support_contact_details]).to eq("0203 222 2222\n\n[Find out about call charges](https://www.gov.uk/call-charges)") |
69 | 87 | end |
70 | 88 |
|
| 89 | + context "when support_contact_details_cy is not provided" do |
| 90 | + it "falls back to support_contact_details formatted with Welsh locale" do |
| 91 | + expect(mail.govuk_notify_personalisation[:support_contact_details_cy]).to eq("0203 222 2222\n\n[Darganfyddwch am gostau galwadau](https://www.gov.uk/call-charges)") |
| 92 | + end |
| 93 | + end |
| 94 | + |
| 95 | + context "when support_contact_details_cy is provided" do |
| 96 | + let(:welsh_support) { OpenStruct.new(phone: "0291 111 1111", email: nil, url: nil, url_text: nil, call_charges_url: "https://www.gov.uk/call-charges") } |
| 97 | + let(:mail) do |
| 98 | + described_class.send_confirmation_email(what_happens_next_markdown:, |
| 99 | + support_contact_details:, |
| 100 | + support_contact_details_cy: welsh_support, |
| 101 | + notify_response_id: "for-my-ref", |
| 102 | + confirmation_email_address:, |
| 103 | + mailer_options:, |
| 104 | + submission_locale:) |
| 105 | + end |
| 106 | + |
| 107 | + it "uses the Welsh support details formatted with Welsh locale" do |
| 108 | + expect(mail.govuk_notify_personalisation[:support_contact_details_cy]).to eq("0291 111 1111\n\n[Darganfyddwch am gostau galwadau](https://www.gov.uk/call-charges)") |
| 109 | + end |
| 110 | + end |
| 111 | + |
71 | 112 | context "when what happens next is missing" do |
72 | 113 | let(:what_happens_next_markdown) { nil } |
73 | 114 |
|
|
143 | 184 | end |
144 | 185 | end |
145 | 186 |
|
146 | | - context "when the request locale is not set" do |
147 | | - it "includes the date user submitted the form in English" do |
148 | | - travel_to timestamp do |
149 | | - expect(mail.govuk_notify_personalisation[:submission_date]).to eq("14 September 2022") |
150 | | - end |
151 | | - end |
152 | | - end |
153 | | - |
154 | | - context "when the request locale is set to :en" do |
155 | | - include_context "with locale set to :en" |
156 | | - it "includes the date user submitted the form in English" do |
157 | | - travel_to timestamp do |
158 | | - expect(mail.govuk_notify_personalisation[:submission_date]).to eq("14 September 2022") |
159 | | - end |
| 187 | + it "includes the date user submitted the form in English" do |
| 188 | + travel_to timestamp do |
| 189 | + expect(mail.govuk_notify_personalisation[:submission_date]).to eq("14 September 2022") |
160 | 190 | end |
161 | 191 | end |
162 | 192 |
|
163 | | - context "when the request locale is set to :cy" do |
164 | | - include_context "with locale set to :cy" |
165 | | - |
166 | | - it "includes the date user submitted the form in Welsh" do |
167 | | - travel_to timestamp do |
168 | | - expect(mail.govuk_notify_personalisation[:submission_date]).to eq("14 Medi 2022") |
169 | | - end |
| 193 | + it "includes the date user submitted the form in Welsh" do |
| 194 | + travel_to timestamp do |
| 195 | + expect(mail.govuk_notify_personalisation[:submission_date_cy]).to eq("14 Medi 2022") |
170 | 196 | end |
171 | 197 | end |
172 | 198 | end |
|
0 commit comments