Add focused tests across many modules to push overall coverage from 75.45% to ~77%. New test files: - test/towerops/snmp/topology_test.exs - test/towerops/vault_test.exs - test/towerops/workers/check_worker_test.exs - test/towerops_web/graphql/resolvers/happy_path_test.exs - test/towerops_web/graphql/schema_test.exs - test/towerops_web/live/reports_live_test.exs Expanded existing tests for: Airos vendor, ProfileWatcher, StormDetector, LLDP, GpsSync, MikrotikBackupWorker, AdminController, MibController, MobileController, GeoipController, OnboardingLive, UserResetPasswordLive, SessionManager, Telemetry, CoverageLive.Show. Also fix a pre-existing dead test in ApplicationSettingTest where the schema default for value_type made the 'invalid without value_type' test unreachable.
131 lines
4.7 KiB
Elixir
131 lines
4.7 KiB
Elixir
defmodule ToweropsWeb.GraphQL.SchemaTest do
|
|
@moduledoc """
|
|
Schema-level tests that go through the Absinthe pipeline so the field
|
|
configs, middleware, and helper functions in `Schema` are exercised.
|
|
"""
|
|
use Towerops.DataCase, async: true
|
|
|
|
import Towerops.AccountsFixtures
|
|
import Towerops.DevicesFixtures
|
|
import Towerops.OrganizationsFixtures
|
|
|
|
alias ToweropsWeb.GraphQL.Schema
|
|
|
|
setup do
|
|
user = user_fixture()
|
|
org = organization_fixture(user.id)
|
|
%{user: user, org: org, ctx: %{organization_id: org.id, user: user}}
|
|
end
|
|
|
|
defp run(query, ctx, vars \\ %{}) do
|
|
Absinthe.run(query, Schema, context: ctx, variables: vars)
|
|
end
|
|
|
|
describe "queries" do
|
|
test "my_organizations returns the user's orgs", %{ctx: ctx, org: org} do
|
|
query = "{ myOrganizations { id name } }"
|
|
assert {:ok, %{data: %{"myOrganizations" => orgs}}} = run(query, ctx)
|
|
assert Enum.any?(orgs, &(&1["id"] == org.id))
|
|
end
|
|
|
|
test "devices returns []", %{ctx: ctx} do
|
|
query = "{ devices { id name } }"
|
|
assert {:ok, %{data: %{"devices" => []}}} = run(query, ctx)
|
|
end
|
|
|
|
test "device returns a device by id", %{ctx: ctx, org: org} do
|
|
d = device_fixture(%{organization_id: org.id})
|
|
query = ~s|{ device(id: "#{d.id}") { id name } }|
|
|
assert {:ok, %{data: %{"device" => %{"id" => id}}}} = run(query, ctx)
|
|
assert id == d.id
|
|
end
|
|
|
|
test "sites returns []", %{ctx: ctx} do
|
|
query = "{ sites { id name } }"
|
|
assert {:ok, %{data: %{"sites" => _}}} = run(query, ctx)
|
|
end
|
|
|
|
test "alerts returns []", %{ctx: ctx} do
|
|
query = "{ alerts { id message } }"
|
|
assert {:ok, %{data: %{"alerts" => []}}} = run(query, ctx)
|
|
end
|
|
|
|
test "checks returns []", %{ctx: ctx} do
|
|
query = "{ checks { id name } }"
|
|
assert {:ok, %{data: %{"checks" => []}}} = run(query, ctx)
|
|
end
|
|
|
|
test "agents returns []", %{ctx: ctx} do
|
|
query = "{ agents { id name } }"
|
|
assert {:ok, %{data: %{"agents" => _}}} = run(query, ctx)
|
|
end
|
|
|
|
test "organization returns the current org", %{ctx: ctx, org: org} do
|
|
query = "{ organization { id name } }"
|
|
assert {:ok, %{data: %{"organization" => %{"id" => id}}}} = run(query, ctx)
|
|
assert id == org.id
|
|
end
|
|
|
|
test "members lists at least the owner", %{ctx: ctx, user: user} do
|
|
query = "{ members { userId } }"
|
|
assert {:ok, %{data: %{"members" => members}}} = run(query, ctx)
|
|
assert Enum.any?(members, &(&1["userId"] == user.id))
|
|
end
|
|
|
|
test "integrations returns []", %{ctx: ctx} do
|
|
query = "{ integrations { id provider } }"
|
|
assert {:ok, %{data: %{"integrations" => []}}} = run(query, ctx)
|
|
end
|
|
|
|
test "activity returns a list", %{ctx: ctx} do
|
|
query = "{ activity { summary timestamp } }"
|
|
assert {:ok, %{data: %{"activity" => items}}} = run(query, ctx)
|
|
assert is_list(items)
|
|
end
|
|
|
|
test "schedules returns []", %{ctx: ctx} do
|
|
query = "{ schedules { id name } }"
|
|
assert {:ok, %{data: %{"schedules" => []}}} = run(query, ctx)
|
|
end
|
|
|
|
test "escalationPolicies returns []", %{ctx: ctx} do
|
|
query = "{ escalationPolicies { id name } }"
|
|
assert {:ok, %{data: %{"escalationPolicies" => []}}} = run(query, ctx)
|
|
end
|
|
|
|
test "maintenanceWindows returns []", %{ctx: ctx} do
|
|
query = "{ maintenanceWindows { id name } }"
|
|
assert {:ok, %{data: %{"maintenanceWindows" => []}}} = run(query, ctx)
|
|
end
|
|
|
|
test "device_metrics with default time_range", %{ctx: ctx, org: org} do
|
|
d = device_fixture(%{organization_id: org.id})
|
|
query = ~s|{ deviceMetrics(deviceId: "#{d.id}") { timestamp } }|
|
|
assert {:ok, %{data: %{"deviceMetrics" => _}}} = run(query, ctx)
|
|
end
|
|
|
|
test "device_interfaces returns [] when device has no snmp", %{ctx: ctx, org: org} do
|
|
d = device_fixture(%{organization_id: org.id})
|
|
query = ~s|{ deviceInterfaces(deviceId: "#{d.id}") { id } }|
|
|
assert {:ok, %{data: %{"deviceInterfaces" => []}}} = run(query, ctx)
|
|
end
|
|
end
|
|
|
|
describe "mutations — error paths" do
|
|
test "update_device with unknown id returns an error", %{ctx: ctx} do
|
|
query = ~s|mutation { updateDevice(id: "#{Ecto.UUID.generate()}", input: { name: "x" }) { id } }|
|
|
assert {:ok, %{errors: errors}} = run(query, ctx)
|
|
assert Enum.any?(errors, &String.contains?(&1.message, "not found"))
|
|
end
|
|
|
|
test "delete_alert (resolveAlert) with unknown id errors", %{ctx: ctx} do
|
|
query = ~s|mutation { resolveAlert(id: "#{Ecto.UUID.generate()}") { id } }|
|
|
assert {:ok, %{errors: _}} = run(query, ctx)
|
|
end
|
|
|
|
test "send_invitation with bad email returns an error", %{ctx: ctx} do
|
|
query = ~s|mutation { sendInvitation(email: "") { id } }|
|
|
assert {:ok, _result} = run(query, ctx)
|
|
end
|
|
end
|
|
end
|