Skip to content

Commit ab29a85

Browse files
committed
wip: Use SES to send all confirmation emails
1 parent 6bb5ed9 commit ab29a85

7 files changed

Lines changed: 19 additions & 458 deletions

app/jobs/send_confirmation_email_job.rb

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
11
class SendConfirmationEmailJob < ApplicationJob
22
queue_as :confirmation_emails
33

4-
def perform(submission:, notify_response_id:, confirmation_email_address:, include_copy_of_answers: false)
4+
def perform(submission:, confirmation_email_address:, include_copy_of_answers: false)
55
set_submission_logging_attributes(submission:)
66

77
# The job will use the locale at the time it was created. Force it to be "en" as we send multilingual emails for
88
# forms submitted in Welsh.
99
I18n.with_locale("en") do
10-
mail = if include_copy_of_answers
11-
AwsSesSubmissionConfirmationMailer.submission_confirmation_email(
12-
submission:, confirmation_email_address:, include_copy_of_answers:,
13-
)
14-
else
15-
FormSubmissionConfirmationMailer.send_confirmation_email(
16-
submission:, notify_response_id:, confirmation_email_address:,
17-
)
18-
end
10+
mail = AwsSesSubmissionConfirmationMailer.submission_confirmation_email(
11+
submission:, confirmation_email_address:, include_copy_of_answers:,
12+
)
1913

2014
mail.deliver_now
21-
CurrentJobLoggingAttributes.confirmation_email_id = mail.govuk_notify_response&.id.presence || mail.message_id
15+
CurrentJobLoggingAttributes.confirmation_email_id = mail.message_id
2216
end
2317
rescue StandardError
2418
CloudWatchService.record_job_failure_metric(self.class.name)

app/mailers/form_submission_confirmation_mailer.rb

Lines changed: 0 additions & 73 deletions
This file was deleted.

app/services/form_submission_service.rb

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ def validate_confirmation_email_address
141141
def enqueue_send_confirmation_email_job(submission:)
142142
SendConfirmationEmailJob.perform_later(
143143
submission:,
144-
notify_response_id: email_confirmation_input.confirmation_email_reference,
145144
confirmation_email_address: confirmation_email_address,
146145
include_copy_of_answers: send_copy_of_answers?,
147146
) do |job|

spec/jobs/send_confirmation_email_job_spec.rb

Lines changed: 4 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
submission_locale: "en",
3131
)
3232
end
33-
let(:notify_response_id) { "confirmation-ref" }
3433
let(:confirmation_email_address) { "testing@gov.uk" }
3534

3635
context "when include_copy_of_answers is false" do
@@ -43,7 +42,6 @@
4342
expect {
4443
described_class.perform_now(
4544
submission:,
46-
notify_response_id:,
4745
confirmation_email_address:,
4846
)
4947
}.to change(ActionMailer::Base.deliveries, :count).by(1)
@@ -53,53 +51,26 @@
5351
end
5452

5553
it "builds mailer arguments from the submission" do
56-
allow(FormSubmissionConfirmationMailer).to receive(:send_confirmation_email).and_call_original
54+
allow(AwsSesSubmissionConfirmationMailer).to receive(:submission_confirmation_email).and_call_original
5755

5856
described_class.perform_now(
5957
submission:,
60-
notify_response_id:,
6158
confirmation_email_address:,
6259
)
6360

64-
expect(FormSubmissionConfirmationMailer).to have_received(:send_confirmation_email).with(
61+
expect(AwsSesSubmissionConfirmationMailer).to have_received(:submission_confirmation_email).with(
6562
submission:,
66-
notify_response_id: "confirmation-ref",
6763
confirmation_email_address: "testing@gov.uk",
64+
include_copy_of_answers: false,
6865
)
6966
end
70-
71-
context "when submission locale is Welsh" do
72-
let(:welsh_form_document) { build(:v2_form_document, name: "Welsh Form") }
73-
74-
before do
75-
submission.update!(submission_locale: "cy")
76-
allow(Api::V2::FormDocumentRepository).to receive(:find_with_mode).and_call_original
77-
allow(Api::V2::FormDocumentRepository).to receive(:find_with_mode).with(
78-
form_id: anything,
79-
mode: anything,
80-
language: :cy,
81-
).and_return(welsh_form_document)
82-
end
83-
84-
it "uses the bilingual template" do
85-
described_class.perform_now(
86-
submission:,
87-
notify_response_id:,
88-
confirmation_email_address:,
89-
)
90-
91-
mail = ActionMailer::Base.deliveries.last
92-
expect(mail.govuk_notify_template).to eq("7891011")
93-
end
94-
end
9567
end
9668

9769
context "when include_copy_of_answers is true" do
9870
it "sends the confirmation email including the answers" do
9971
expect {
10072
described_class.perform_now(
10173
submission:,
102-
notify_response_id:,
10374
confirmation_email_address:,
10475
include_copy_of_answers: true,
10576
)
@@ -115,7 +86,6 @@
11586
I18n.with_locale(:cy) do
11687
described_class.perform_now(
11788
submission:,
118-
notify_response_id:,
11989
confirmation_email_address:,
12090
include_copy_of_answers: true,
12191
)
@@ -148,7 +118,6 @@
148118
it "passes the confirmation email configuration set name to SES" do
149119
described_class.perform_now(
150120
submission:,
151-
notify_response_id:,
152121
confirmation_email_address:,
153122
include_copy_of_answers: true,
154123
)
@@ -162,15 +131,14 @@
162131

163132
context "when there is an error during processing" do
164133
before do
165-
allow(FormSubmissionConfirmationMailer).to receive(:send_confirmation_email).and_raise(StandardError, "Test error")
134+
allow(AwsSesSubmissionConfirmationMailer).to receive(:submission_confirmation_email).and_raise(StandardError, "Test error")
166135
allow(CloudWatchService).to receive(:record_job_failure_metric)
167136
end
168137

169138
it "raises an error" do
170139
expect {
171140
described_class.perform_now(
172141
submission:,
173-
notify_response_id:,
174142
confirmation_email_address:,
175143
)
176144
}.to raise_error(StandardError, "Test error")
@@ -179,7 +147,6 @@
179147
it "sends cloudwatch metric for failure" do
180148
described_class.perform_now(
181149
submission:,
182-
notify_response_id:,
183150
confirmation_email_address:,
184151
)
185152
expect(CloudWatchService).to have_received(:record_job_failure_metric).with("SendConfirmationEmailJob")

0 commit comments

Comments
 (0)