feat(ntfy): dispatch sms_delivered and sms_failed from SmsMessage
This commit is contained in:
46
test/models/sms_message_test.rb
Normal file
46
test/models/sms_message_test.rb
Normal file
@@ -0,0 +1,46 @@
|
||||
require "test_helper"
|
||||
|
||||
class SmsMessageTest < ActiveSupport::TestCase
|
||||
include ActiveJob::TestHelper
|
||||
|
||||
setup do
|
||||
ActiveJob::Base.queue_adapter = :test
|
||||
@admin = AdminUser.create!(
|
||||
name: "SMS Admin", email: "sms@example.com",
|
||||
password: "password123",
|
||||
ntfy_topic: "sms-topic", ntfy_token: "tk_sms",
|
||||
ntfy_enabled: true, ntfy_server_url: "https://ntfy.example.com"
|
||||
)
|
||||
stub_request(:post, "https://ntfy.example.com/sms-topic").to_return(status: 200)
|
||||
|
||||
@gateway = Gateway.create!(
|
||||
device_id: "sms-gw", name: "SMS GW",
|
||||
api_key_digest: "d" * 64, status: "online",
|
||||
last_heartbeat_at: 1.second.ago
|
||||
)
|
||||
end
|
||||
|
||||
test "mark_delivered! dispatches sms_delivered notification" do
|
||||
sms = SmsMessage.create!(
|
||||
direction: "outbound", phone_number: "+14152345678",
|
||||
message_body: "Hello", status: "sent",
|
||||
gateway: @gateway, sent_at: 1.minute.ago
|
||||
)
|
||||
|
||||
assert_enqueued_jobs 1 do
|
||||
sms.mark_delivered!
|
||||
end
|
||||
end
|
||||
|
||||
test "mark_failed! dispatches sms_failed notification with urgent priority" do
|
||||
sms = SmsMessage.create!(
|
||||
direction: "outbound", phone_number: "+14152345678",
|
||||
message_body: "Hello", status: "sent",
|
||||
gateway: @gateway, sent_at: 1.minute.ago
|
||||
)
|
||||
|
||||
assert_enqueued_jobs 1 do
|
||||
sms.mark_failed!("Network timeout")
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user