Files
wanderer/test/unit/map_webhook_subscription_test.exs
Guarzo 182cc4f436 fix: make map webhooks usable
Route toggle requests before webhook resource IDs and write generated secrets through AshCloak. Add regression coverage for routing, map scope, creation, and rotation.
2026-09-09 15:14:51 -04:00

45 lines
1.4 KiB
Elixir

defmodule WandererApp.Api.MapWebhookSubscriptionTest do
use WandererApp.DataCase, async: false
alias WandererApp.Api.MapWebhookSubscription
describe "secret lifecycle" do
test "generates an encrypted secret when creating a subscription" do
map = insert(:map)
assert {:ok, webhook} =
MapWebhookSubscription.create(%{
map_id: map.id,
url: "https://example.com/webhook",
events: ["add_system"],
active?: true
})
assert is_binary(webhook.secret)
assert byte_size(webhook.secret) > 0
assert is_binary(webhook.encrypted_secret)
refute webhook.encrypted_secret == webhook.secret
end
test "replaces and encrypts the secret when rotating it" do
map = insert(:map)
assert {:ok, webhook} =
MapWebhookSubscription.create(%{
map_id: map.id,
url: "https://example.com/webhook",
events: ["add_system"],
active?: true
})
assert {:ok, rotated_webhook} = MapWebhookSubscription.rotate_secret(webhook)
refute rotated_webhook.secret == webhook.secret
refute rotated_webhook.encrypted_secret == webhook.encrypted_secret
assert is_binary(rotated_webhook.secret)
assert is_binary(rotated_webhook.encrypted_secret)
refute rotated_webhook.encrypted_secret == rotated_webhook.secret
end
end
end