50 lines
1.5 KiB
Ruby
50 lines
1.5 KiB
Ruby
require "test_helper"
|
|
|
|
class SendNtfyNotificationJobTest < ActiveJob::TestCase
|
|
setup do
|
|
@admin = AdminUser.create!(
|
|
name: "Job Admin", email: "jobadmin@example.com",
|
|
password: "password123",
|
|
ntfy_topic: "job-topic", ntfy_token: "tk_job",
|
|
ntfy_enabled: true,
|
|
ntfy_server_url: "https://ntfy.example.com"
|
|
)
|
|
|
|
stub_request(:post, "https://ntfy.example.com/job-topic")
|
|
.to_return(status: 200, body: "", headers: {})
|
|
end
|
|
|
|
test "perform calls Publisher with provided params" do
|
|
SendNtfyNotificationJob.perform_now(
|
|
@admin.id,
|
|
"gateway_offline",
|
|
title: "Gateway offline",
|
|
message: "gw-001 went offline",
|
|
priority: 4,
|
|
tags: ["rotating_light"],
|
|
click: "https://app.example.com/admin/gateways"
|
|
)
|
|
|
|
assert_requested :post, "https://ntfy.example.com/job-topic",
|
|
body: hash_including("title" => "Gateway offline", "priority" => 4)
|
|
end
|
|
|
|
test "perform does nothing if admin not found" do
|
|
assert_nothing_raised do
|
|
SendNtfyNotificationJob.perform_now(999999, "gateway_offline",
|
|
title: "X", message: "Y", priority: 3, tags: [])
|
|
end
|
|
end
|
|
|
|
test "perform does nothing if admin ntfy not configured" do
|
|
unconfigured = AdminUser.create!(
|
|
name: "UC", email: "uc@example.com", password: "password123"
|
|
)
|
|
|
|
SendNtfyNotificationJob.perform_now(unconfigured.id, "gateway_offline",
|
|
title: "X", message: "Y", priority: 3, tags: [])
|
|
|
|
assert_not_requested :post, "https://ntfy.example.com/job-topic"
|
|
end
|
|
end
|