Skip to content

Commit

Permalink
Update Twilio verification only when transport_message_id is present (
Browse files Browse the repository at this point in the history
#703)

Adds a condition to check if a reset code message deliveries' transport_message_id exists. Otherwise we get an error as per #698
  • Loading branch information
DeeTheDev authored Sep 12, 2024
1 parent 2890c0f commit 0981c49
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions lib/suma/async/reset_code_update_twilio.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ def update_verification(code, status)
md &&
# email codes aren't using twilio verify, at least not yet (and probably never)
md.transport_type == "sms" &&
# deliveries can potentially be aborted therefore a having nil message id
md.transport_message_id &&
# We can send verifications using alternative templates; only the verification template uses
# the 'send via twilio verify' logic in SmsTransport, so we only update twilio when we use that template.
Suma::Message::SmsTransport.verification_delivery?(md)
Expand Down
6 changes: 5 additions & 1 deletion spec/suma/async/jobs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -182,13 +182,17 @@
let(:member) { Suma::Fixtures.member(phone: "12223334444").create }
let(:fac) { Suma::Fixtures.reset_code(member:).sms }

it "noops if the code has no delivery or has an invalid message id" do
it "noops if the code has no delivery, has an invalid message id or the delivery was aborted" do
no_delivery = fac.create
bad_msg_id = fac.create
bad_msg_id.update(message_delivery: Suma::Fixtures.message_delivery.create(transport_message_id: "MSGID"))
template = Suma::Message::SmsTransport.verification_template
message_delivery = Suma::Fixtures.message_delivery.via("sms").create(template:, transport_message_id: nil)
nil_msg_id = fac.create(message_delivery:)
expect do
no_delivery.expire!
bad_msg_id.expire!
nil_msg_id.expire!
end.to perform_async_job(Suma::Async::ResetCodeUpdateTwilio)
end

Expand Down

0 comments on commit 0981c49

Please sign in to comment.