Skip to content

Commit 5a589e9

Browse files
authored
Merge pull request #4731 from nhsuk/sms-team-only
Set `delivery_status` from team API key error
2 parents 2206c25 + f4d6e5c commit 5a589e9

2 files changed

Lines changed: 31 additions & 0 deletions

File tree

app/jobs/sms_delivery_job.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ def perform(
5454
e.message.include?(TEAM_ONLY_API_KEY_MESSAGE)
5555
# Prevent retries and job failures.
5656
Sentry.capture_exception(e)
57+
[nil, "technical_failure"]
5758
elsif e.message == INVALID_UK_MOBILE_NUMBER_ERROR
5859
[nil, "not_uk_mobile_number_failure"]
5960
else

spec/jobs/sms_delivery_job_spec.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,36 @@
127127
end
128128
end
129129

130+
context "when the parent phone number is not part of the allow list" do
131+
before do
132+
allow(notifications_client).to receive(:send_sms).and_raise(
133+
Notifications::Client::BadRequestError.new(
134+
OpenStruct.new(
135+
code: 400,
136+
body: "Can’t send to this recipient using a team-only API key"
137+
)
138+
)
139+
)
140+
end
141+
142+
it "creates a log entry for the failure" do
143+
expect { perform_now }.to change(NotifyLogEntry, :count).by(1)
144+
145+
notify_log_entry = NotifyLogEntry.last
146+
expect(notify_log_entry).to be_sms
147+
expect(notify_log_entry).to be_technical_failure
148+
expect(notify_log_entry.delivery_id).to be_nil
149+
expect(notify_log_entry.recipient).to eq("01234 567890")
150+
expect(notify_log_entry.template_id).to eq(
151+
GOVUK_NOTIFY_SMS_TEMPLATES[template_name]
152+
)
153+
expect(notify_log_entry.parent).to eq(parent)
154+
expect(notify_log_entry.patient).to eq(patient)
155+
expect(notify_log_entry.programme_ids).to eq(programmes.map(&:id))
156+
expect(notify_log_entry.sent_by).to eq(sent_by)
157+
end
158+
end
159+
130160
context "with a consent form" do
131161
let(:consent_form) do
132162
create(:consent_form, session:, parent_phone: "01234567890")

0 commit comments

Comments
 (0)