Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 5 additions & 11 deletions app/jobs/send_confirmation_email_job.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
class SendConfirmationEmailJob < ApplicationJob
queue_as :confirmation_emails

def perform(submission:, notify_response_id:, confirmation_email_address:, include_copy_of_answers: false)
def perform(submission:, confirmation_email_address:, include_copy_of_answers: false)
set_submission_logging_attributes(submission:)

# The job will use the locale at the time it was created. Force it to be "en" as we send multilingual emails for
# forms submitted in Welsh.
I18n.with_locale("en") do
mail = if include_copy_of_answers
AwsSesSubmissionConfirmationMailer.submission_confirmation_email(
submission:, confirmation_email_address:, include_copy_of_answers:,
)
else
FormSubmissionConfirmationMailer.send_confirmation_email(
submission:, notify_response_id:, confirmation_email_address:,
)
end
mail = AwsSesSubmissionConfirmationMailer.submission_confirmation_email(
submission:, confirmation_email_address:, include_copy_of_answers:,
)

mail.deliver_now
CurrentJobLoggingAttributes.confirmation_email_id = mail.govuk_notify_response&.id.presence || mail.message_id
CurrentJobLoggingAttributes.confirmation_email_id = mail.message_id
end
rescue StandardError
CloudWatchService.record_job_failure_metric(self.class.name)
Expand Down
73 changes: 0 additions & 73 deletions app/mailers/form_submission_confirmation_mailer.rb

This file was deleted.

1 change: 0 additions & 1 deletion app/services/form_submission_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ def validate_confirmation_email_address
def enqueue_send_confirmation_email_job(submission:)
SendConfirmationEmailJob.perform_later(
submission:,
notify_response_id: email_confirmation_input.confirmation_email_reference,
confirmation_email_address: confirmation_email_address,
include_copy_of_answers: send_copy_of_answers?,
) do |job|
Expand Down
41 changes: 4 additions & 37 deletions spec/jobs/send_confirmation_email_job_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
submission_locale: "en",
)
end
let(:notify_response_id) { "confirmation-ref" }
let(:confirmation_email_address) { "testing@gov.uk" }

context "when include_copy_of_answers is false" do
Expand All @@ -43,7 +42,6 @@
expect {
described_class.perform_now(
submission:,
notify_response_id:,
confirmation_email_address:,
)
}.to change(ActionMailer::Base.deliveries, :count).by(1)
Expand All @@ -53,53 +51,26 @@
end

it "builds mailer arguments from the submission" do
allow(FormSubmissionConfirmationMailer).to receive(:send_confirmation_email).and_call_original
allow(AwsSesSubmissionConfirmationMailer).to receive(:submission_confirmation_email).and_call_original

described_class.perform_now(
submission:,
notify_response_id:,
confirmation_email_address:,
)

expect(FormSubmissionConfirmationMailer).to have_received(:send_confirmation_email).with(
expect(AwsSesSubmissionConfirmationMailer).to have_received(:submission_confirmation_email).with(
submission:,
notify_response_id: "confirmation-ref",
confirmation_email_address: "testing@gov.uk",
include_copy_of_answers: false,
)
end

context "when submission locale is Welsh" do
let(:welsh_form_document) { build(:v2_form_document, name: "Welsh Form") }

before do
submission.update!(submission_locale: "cy")
allow(Api::V2::FormDocumentRepository).to receive(:find_with_mode).and_call_original
allow(Api::V2::FormDocumentRepository).to receive(:find_with_mode).with(
form_id: anything,
mode: anything,
language: :cy,
).and_return(welsh_form_document)
end

it "uses the bilingual template" do
described_class.perform_now(
submission:,
notify_response_id:,
confirmation_email_address:,
)

mail = ActionMailer::Base.deliveries.last
expect(mail.govuk_notify_template).to eq("7891011")
end
end
end

context "when include_copy_of_answers is true" do
it "sends the confirmation email including the answers" do
expect {
described_class.perform_now(
submission:,
notify_response_id:,
confirmation_email_address:,
include_copy_of_answers: true,
)
Expand All @@ -115,7 +86,6 @@
I18n.with_locale(:cy) do
described_class.perform_now(
submission:,
notify_response_id:,
confirmation_email_address:,
include_copy_of_answers: true,
)
Expand Down Expand Up @@ -148,7 +118,6 @@
it "passes the confirmation email configuration set name to SES" do
described_class.perform_now(
submission:,
notify_response_id:,
confirmation_email_address:,
include_copy_of_answers: true,
)
Expand All @@ -162,15 +131,14 @@

context "when there is an error during processing" do
before do
allow(FormSubmissionConfirmationMailer).to receive(:send_confirmation_email).and_raise(StandardError, "Test error")
allow(AwsSesSubmissionConfirmationMailer).to receive(:submission_confirmation_email).and_raise(StandardError, "Test error")
allow(CloudWatchService).to receive(:record_job_failure_metric)
end

it "raises an error" do
expect {
described_class.perform_now(
submission:,
notify_response_id:,
confirmation_email_address:,
)
}.to raise_error(StandardError, "Test error")
Expand All @@ -179,7 +147,6 @@
it "sends cloudwatch metric for failure" do
described_class.perform_now(
submission:,
notify_response_id:,
confirmation_email_address:,
)
expect(CloudWatchService).to have_received(:record_job_failure_metric).with("SendConfirmationEmailJob")
Expand Down
Loading
Loading