require "test_helper" class NtfyDispatchableTest < ActiveJob::TestCase setup do ActiveJob::Base.queue_adapter = :test @admin = AdminUser.create!( name: "Dispatch Admin", email: "dispatch@example.com", password: "password123", ntfy_topic: "dispatch-topic", ntfy_token: "tk_dispatch", ntfy_enabled: true, ntfy_server_url: "https://ntfy.example.com" ) stub_request(:post, "https://ntfy.example.com/dispatch-topic") .to_return(status: 200, body: "", headers: {}) end test "dispatch_ntfy enqueues a SendNtfyNotificationJob per configured admin" do assert_enqueued_jobs 1 do TestModel.dispatch_ntfy("sms_failed", title: "SMS failed", message: "msg_abc failed", priority: 5, tags: ["x"], click: "https://app/admin/logs" ) end end test "dispatch_ntfy skips admins without ntfy configured" do AdminUser.create!(name: "No Ntfy", email: "none@example.com", password: "password123") assert_enqueued_jobs 1 do TestModel.dispatch_ntfy("sms_failed", title: "T", message: "M", priority: 3, tags: []) end end test "dispatch_ntfy enqueues zero jobs if no admins configured" do @admin.update!(ntfy_enabled: false) assert_enqueued_jobs 0 do TestModel.dispatch_ntfy("sms_failed", title: "T", message: "M", priority: 3, tags: []) end end end class TestModel include NtfyDispatchable end