test: GraphQL Device resolver update error/metrics/interfaces branches
This commit is contained in:
parent
8bc4f120c6
commit
1d5a5a8a73
1 changed files with 51 additions and 0 deletions
|
|
@ -16,6 +16,57 @@ defmodule ToweropsWeb.GraphQL.Resolvers.HappyPathTest do
|
|||
%{user: user, org: org, ctx: %{context: %{organization_id: org.id, user: user}}}
|
||||
end
|
||||
|
||||
describe "Device (additional success/error branches)" do
|
||||
test "update/3 with invalid input returns formatted error", %{ctx: ctx, org: org} do
|
||||
{:ok, device} =
|
||||
Towerops.Devices.create_device(%{
|
||||
name: "ToUpdate",
|
||||
ip_address: "10.66.0.1",
|
||||
organization_id: org.id
|
||||
})
|
||||
|
||||
assert {:error, msg} =
|
||||
Resolvers.Device.update(nil, %{id: device.id, input: %{ip_address: ""}}, ctx)
|
||||
|
||||
assert is_binary(msg)
|
||||
end
|
||||
|
||||
test "metrics/3 returns metrics shape for a real device", %{ctx: ctx, org: org} do
|
||||
{:ok, device} =
|
||||
Towerops.Devices.create_device(%{
|
||||
name: "MetricsDev",
|
||||
ip_address: "10.77.0.1",
|
||||
organization_id: org.id
|
||||
})
|
||||
|
||||
assert {:ok, metrics} =
|
||||
Resolvers.Device.metrics(nil, %{device_id: device.id, time_range: "24h"}, ctx)
|
||||
|
||||
assert is_list(metrics)
|
||||
end
|
||||
|
||||
test "metrics/3 unauthenticated returns auth error" do
|
||||
assert {:error, _} =
|
||||
Resolvers.Device.metrics(nil, %{device_id: Ecto.UUID.generate()}, %{context: %{}})
|
||||
end
|
||||
|
||||
test "interfaces/3 returns [] for device without SNMP record", %{ctx: ctx, org: org} do
|
||||
{:ok, device} =
|
||||
Towerops.Devices.create_device(%{
|
||||
name: "NoSnmp",
|
||||
ip_address: "10.88.0.1",
|
||||
organization_id: org.id
|
||||
})
|
||||
|
||||
assert {:ok, []} = Resolvers.Device.interfaces(nil, %{device_id: device.id}, ctx)
|
||||
end
|
||||
|
||||
test "interfaces/3 unauthenticated returns auth error" do
|
||||
assert {:error, _} =
|
||||
Resolvers.Device.interfaces(nil, %{device_id: Ecto.UUID.generate()}, %{context: %{}})
|
||||
end
|
||||
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"}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue