-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathsend_confirmation_email_job_spec.rb
More file actions
131 lines (114 loc) · 3.95 KB
/
send_confirmation_email_job_spec.rb
File metadata and controls
131 lines (114 loc) · 3.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
require "rails_helper"
RSpec.describe SendConfirmationEmailJob, type: :job do
let(:submission_created_at) { Time.utc(2022, 12, 14, 13, 0o0, 0o0) }
let(:form_document) do
build(
:v2_form_document,
name: "Form 1",
what_happens_next_markdown: "Please wait for a response",
support_phone: "0203 222 2222",
support_email: "help@example.gov.uk",
support_url: "https://example.gov.uk/help",
support_url_text: "Get help",
payment_url: "https://www.gov.uk/payments/test-service/pay-for-licence",
)
end
let(:submission) do
create(
:submission,
form_document:,
created_at: submission_created_at,
reference: "ABC12345",
submission_locale: "en",
)
end
let(:notify_response_id) { "confirmation-ref" }
let(:confirmation_email_address) { "testing@gov.uk" }
before do
Settings.govuk_notify.form_filler_confirmation_email_template_id = "123456"
Settings.govuk_notify.form_filler_confirmation_email_welsh_template_id = "7891011"
end
it "sends the confirmation email" do
expect {
described_class.perform_now(
submission:,
notify_response_id:,
confirmation_email_address:,
)
}.to change(ActionMailer::Base.deliveries, :count).by(1)
mail = ActionMailer::Base.deliveries.last
expect(mail.to).to eq(["testing@gov.uk"])
end
it "builds mailer arguments from the submission" do
allow(FormSubmissionConfirmationMailer).to receive(:send_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(
form: submission.form,
welsh_form: nil,
submission:,
notify_response_id: "confirmation-ref",
confirmation_email_address: "testing@gov.uk",
)
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
it "passes the Welsh form to the mailer" do
allow(FormSubmissionConfirmationMailer).to receive(:send_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(
hash_including(welsh_form: have_attributes(name: welsh_form_document.name)),
)
end
end
context "when there is an error during processing" do
before do
allow(FormSubmissionConfirmationMailer).to receive(:send_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")
end
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")
rescue StandardError
nil
end
end
end