test: add comprehensive integration tests for monitoring dashboard

Added integration tests for real-time updates and metrics display.
Also fixed dialyzer warnings in worker event broadcasting by removing
unreachable error handling branches.

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Graham McIntire 2026-02-06 18:41:08 -06:00 committed by Graham McIntire
parent 070241d15a
commit 137d7c83ec
No known key found for this signature in database
3 changed files with 46 additions and 12 deletions

View file

@ -53,13 +53,7 @@ defmodule Towerops.Workers.DevicePollerWorker do
duration = System.monotonic_time(:second) - start_time
case result do
:ok ->
Events.broadcast_job_event(job, :completed, %{duration: duration})
{:error, reason} ->
Events.broadcast_job_event(job, :failed, %{error: inspect(reason), duration: duration})
end
Events.broadcast_job_event(job, :completed, %{duration: duration})
result
end

View file

@ -88,9 +88,6 @@ defmodule Towerops.Workers.DiscoveryWorker do
:discard ->
Events.broadcast_job_event(job, :completed, %{duration: duration})
{:error, reason} ->
Events.broadcast_job_event(job, :failed, %{error: inspect(reason), duration: duration})
end
result

View file

@ -2,6 +2,8 @@ defmodule ToweropsWeb.Admin.MonitoringLiveTest do
use ToweropsWeb.ConnCase
import Phoenix.LiveViewTest
import Towerops.DevicesFixtures
import Towerops.JobsFixtures
describe "MonitoringLive" do
setup [:register_and_log_in_superuser]
@ -19,14 +21,55 @@ defmodule ToweropsWeb.Admin.MonitoringLiveTest do
{:ok, view, _html} = live(conn, ~p"/admin/monitoring")
# Verify PubSub subscription by checking it's alive
assert view.pid |> Process.alive?()
assert Process.alive?(view.pid)
end
test "displays active operations section", %{conn: conn} do
{:ok, _view, html} = live(conn, ~p"/admin/monitoring")
assert html =~ "Active Operations"
assert html =~ "No active jobs"
assert html =~ "No jobs currently executing"
end
end
describe "real-time updates" do
setup [:register_and_log_in_superuser]
test "displays executing jobs from database", %{conn: conn} do
device = device_fixture()
_job =
oban_job_fixture(%{
worker: "Towerops.Workers.DevicePollerWorker",
state: "executing",
args: %{"device_id" => device.id},
attempted_at: DateTime.utc_now()
})
{:ok, _view, html} = live(conn, ~p"/admin/monitoring")
# Should show the device name in executing jobs
assert html =~ device.name
assert html =~ "Active Operations (1)"
end
end
describe "metrics display" do
setup [:register_and_log_in_superuser]
test "shows current activity metrics", %{conn: conn} do
device = device_fixture()
oban_job_fixture(%{
worker: "Towerops.Workers.DevicePollerWorker",
state: "executing",
args: %{"device_id" => device.id}
})
{:ok, _view, html} = live(conn, ~p"/admin/monitoring")
assert html =~ "Executing"
assert html =~ "1"
end
end