From a224775fd3a127694697bfae943feebe6b20b332 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Sat, 9 May 2026 09:54:06 -0500 Subject: [PATCH] test: EscalationPolicy resolver create/update validation error branches --- .../graphql/resolvers/happy_path_test.exs | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/test/towerops_web/graphql/resolvers/happy_path_test.exs b/test/towerops_web/graphql/resolvers/happy_path_test.exs index 250d68c2..cf71ae74 100644 --- a/test/towerops_web/graphql/resolvers/happy_path_test.exs +++ b/test/towerops_web/graphql/resolvers/happy_path_test.exs @@ -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