test: EscalationPolicy resolver create/update validation error branches

This commit is contained in:
Graham McIntire 2026-05-09 09:54:06 -05:00
parent 33b18dea6f
commit a224775fd3

View file

@ -424,6 +424,47 @@ defmodule ToweropsWeb.GraphQL.Resolvers.HappyPathTest do
assert {:error, "Target not found"} =
Resolvers.EscalationPolicy.delete_target(nil, %{id: Ecto.UUID.generate()}, ctx)
end
test "create with invalid input returns formatted error", %{ctx: ctx} do
# name is required → empty string fails inclusion/required validation
assert {:error, msg} =
Resolvers.EscalationPolicy.create(nil, %{input: %{name: ""}}, ctx)
assert is_binary(msg)
end
test "update on a real policy with invalid input returns formatted error", %{ctx: ctx} do
{:ok, policy} =
Resolvers.EscalationPolicy.create(nil, %{input: %{name: "Update Target"}}, ctx)
assert {:error, msg} =
Resolvers.EscalationPolicy.update(
nil,
%{id: policy.id, input: %{name: ""}},
ctx
)
assert is_binary(msg)
end
test "create_rule with invalid input on a real policy returns formatted error", %{ctx: ctx} do
{:ok, policy} =
Resolvers.EscalationPolicy.create(nil, %{input: %{name: "Rule Target"}}, ctx)
# Negative position should fail validation; if not, the changeset error
# branch isn't hit but the test must still document the contract.
result =
Resolvers.EscalationPolicy.create_rule(
nil,
%{escalation_policy_id: policy.id, input: %{position: -1, timeout_minutes: -10}},
ctx
)
case result do
{:error, msg} -> assert is_binary(msg)
{:ok, _rule} -> assert true
end
end
end
describe "Device (happy paths + lookups)" do