feat(ntfy): dispatch gateway_offline from CheckGatewayHealthJob after bulk update
This commit is contained in:
45
test/jobs/check_gateway_health_job_test.rb
Normal file
45
test/jobs/check_gateway_health_job_test.rb
Normal 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
|
||||
Reference in New Issue
Block a user