feat(ntfy): dispatch gateway_offline from CheckGatewayHealthJob after bulk update

This commit is contained in:
Min Zeya Phyo
2026-07-28 02:16:59 +08:00
parent 4420000148
commit 36a3f6daad
2 changed files with 60 additions and 4 deletions

View File

@@ -0,0 +1,45 @@
require "test_helper"
class CheckGatewayHealthJobTest < ActiveJob::TestCase
setup do
ActiveJob::Base.queue_adapter = :test
@admin = AdminUser.create!(
name: "Health Admin", email: "health@example.com",
password: "password123",
ntfy_topic: "health-topic", ntfy_token: "tk_health",
ntfy_enabled: true, ntfy_server_url: "https://ntfy.example.com"
)
stub_request(:post, "https://ntfy.example.com/health-topic").to_return(status: 200)
end
test "dispatches gateway_offline for each stale gateway marked offline" do
stale_gw = Gateway.create!(
device_id: "stale-1", name: "Stale One",
api_key_digest: "a" * 64, status: "online",
last_heartbeat_at: 5.minutes.ago
)
Gateway.create!(
device_id: "fresh-1", name: "Fresh",
api_key_digest: "b" * 64, status: "online",
last_heartbeat_at: 30.seconds.ago
)
assert_enqueued_jobs 1 do
CheckGatewayHealthJob.perform_now
end
assert_equal "offline", stale_gw.reload.status
end
test "does not dispatch when no gateways go stale" do
Gateway.create!(
device_id: "fresh-2", name: "Fresh Two",
api_key_digest: "c" * 64, status: "online",
last_heartbeat_at: 10.seconds.ago
)
assert_enqueued_jobs 0 do
CheckGatewayHealthJob.perform_now
end
end
end