towerops/test/towerops_web/live/device_live/show_smoke_test.exs
Graham McIntire 3ca0834ef0 tests: raise coverage to 70% via helper promotion + new unit/property tests
Promoted pure presentation and utility helpers from `defp` to `def @doc false`
across ~20 LiveViews, Oban workers, and sync modules so they're reachable from
unit tests. Refactored several `cond` blocks into idiomatic function heads with
guards. Added ~250 new test cases in new files under test/towerops and
test/towerops_web, including DB-backed tests for CnMaestro.Sync and
AlertNotificationWorker, and removed dead LiveView tab components and
CapacityLive (no callers anywhere in lib/test).

Configured mix.exs test_coverage.ignore_modules to exclude vendored third-party
code (SnmpKit, protobuf-generated Towerops.Agent.*, Absinthe GraphQL types,
Phoenix HTML modules, Inspect protocol impls) from coverage calculations —
these are not our project code.

Coverage: 66.93% → 70.09%. Full suite: 10,127 tests, 0 failures.
2026-04-24 09:49:06 -05:00

55 lines
1.6 KiB
Elixir

defmodule ToweropsWeb.DeviceLive.ShowSmokeTest do
@moduledoc """
Smoke test for DeviceLive.Show, SiteLive.Show, and DeviceLive.Form mount paths.
Mount is expected to succeed or redirect (e.g. scope mismatch). Both outcomes
still exercise the parameter-resolving code paths.
"""
use ToweropsWeb.ConnCase, async: true
import Phoenix.LiveViewTest
setup :register_and_log_in_user
setup %{user: user} do
{:ok, org} = Towerops.Organizations.create_organization(%{name: "Smoke Dev Org"}, user.id)
{:ok, site} =
Towerops.Sites.create_site(%{
name: "Site #{System.unique_integer([:positive])}",
organization_id: org.id
})
device =
Towerops.DevicesFixtures.device_fixture(%{
organization_id: org.id,
site_id: site.id,
name: "SmokeDev"
})
%{org: org, site: site, device: device}
end
defp assert_mount_or_redirect(result) do
assert match?({:ok, _, _}, result) or
match?({:error, {:redirect, _}}, result) or
match?({:error, {:live_redirect, _}}, result)
end
describe "GET /devices/:id" do
test "mount attempt succeeds or redirects", %{conn: conn, device: device} do
assert_mount_or_redirect(live(conn, ~p"/devices/#{device.id}"))
end
end
describe "GET /devices/:id/edit" do
test "mount attempt succeeds or redirects", %{conn: conn, device: device} do
assert_mount_or_redirect(live(conn, ~p"/devices/#{device.id}/edit"))
end
end
describe "GET /sites/:id" do
test "mount attempt succeeds or redirects", %{conn: conn, site: site} do
assert_mount_or_redirect(live(conn, ~p"/sites/#{site.id}"))
end
end
end