From 33b18dea6fce64cea176c3b93d4b6969d3373adf Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Sat, 9 May 2026 09:50:08 -0500 Subject: [PATCH] test: GraphQL Schedule resolver create/update/delete success and error branches --- .../graphql/resolvers/happy_path_test.exs | 57 +++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/test/towerops_web/graphql/resolvers/happy_path_test.exs b/test/towerops_web/graphql/resolvers/happy_path_test.exs index eac46842..250d68c2 100644 --- a/test/towerops_web/graphql/resolvers/happy_path_test.exs +++ b/test/towerops_web/graphql/resolvers/happy_path_test.exs @@ -16,6 +16,63 @@ defmodule ToweropsWeb.GraphQL.Resolvers.HappyPathTest do %{user: user, org: org, ctx: %{context: %{organization_id: org.id, user: user}}} end + describe "Schedule (success/error branches)" do + test "create/3 returns the new schedule on success", %{ctx: ctx} do + input = %{name: "Primary On-Call", description: "24/7", timezone: "Etc/UTC"} + assert {:ok, schedule} = Resolvers.Schedule.create(nil, %{input: input}, ctx) + assert schedule.name == "Primary On-Call" + end + + test "create/3 with invalid input returns formatted error", %{ctx: ctx} do + # name is required + assert {:error, msg} = Resolvers.Schedule.create(nil, %{input: %{name: ""}}, ctx) + assert is_binary(msg) + end + + test "update/3 succeeds on a real schedule", %{ctx: ctx, org: org} do + {:ok, schedule} = + Towerops.OnCall.create_schedule(%{ + name: "Original", + timezone: "Etc/UTC", + organization_id: org.id + }) + + assert {:ok, updated} = + Resolvers.Schedule.update(nil, %{id: schedule.id, input: %{name: "Renamed"}}, ctx) + + assert updated.name == "Renamed" + end + + test "update/3 with invalid input on a real schedule returns formatted error", %{ + ctx: ctx, + org: org + } do + {:ok, schedule} = + Towerops.OnCall.create_schedule(%{ + name: "Pre-update", + timezone: "Etc/UTC", + organization_id: org.id + }) + + assert {:error, msg} = + Resolvers.Schedule.update(nil, %{id: schedule.id, input: %{name: ""}}, ctx) + + assert is_binary(msg) + end + + test "delete/3 succeeds on a real schedule", %{ctx: ctx, org: org} do + {:ok, schedule} = + Towerops.OnCall.create_schedule(%{ + name: "Doomed", + timezone: "Etc/UTC", + organization_id: org.id + }) + + assert {:ok, %{success: true}} = + Resolvers.Schedule.delete(nil, %{id: schedule.id}, ctx) + end + end + describe "Member" do test "invite/3 creates an invitation", %{ctx: ctx} do assert {:ok, invitation} =