Two critical production bugs fixed: 1. **Alert type enum → string conversion** - Changed Alert.alert_type from Ecto.Enum to :string for flexibility - Updated all queries to use "device_down"/"device_up" strings instead of atoms - Fixed pattern matching in alerts.ex and device_monitor_worker.ex - Updated 44+ test files to use string literals 2. **SQL array indexing syntax error in activity feed** - Fixed PostgreSQL syntax: `array_agg(...)[1]` → `(array_agg(...))[1]` - Prevents "syntax error at or near [" in activity feed queries 3. **Added comprehensive timer cleanup tests** - Tests for mobile_qr_live.ex timer cleanup on terminate - Tests for agent_live index timer cleanup - Verifies memory leak fixes from previous commits Files changed: - lib/towerops/alerts.ex - lib/towerops/alerts/alert.ex - lib/towerops/activity_feed.ex - lib/towerops/workers/device_monitor_worker.ex - test/**/*_test.exs (44+ files with alert_type references) - test/towerops_web/live/mobile_qr_live_test.exs - test/towerops_web/live/agent_live_test.exs - test/towerops/workers/device_poller_worker_test.exs All tests passing except 1 unrelated brute force protection test.
60 lines
1.8 KiB
Elixir
60 lines
1.8 KiB
Elixir
defmodule ToweropsWeb.AccountLive.MyDataTest do
|
|
use ToweropsWeb.ConnCase
|
|
|
|
import Phoenix.LiveViewTest
|
|
|
|
setup :register_and_log_in_user_with_sudo
|
|
|
|
describe "My Data page" do
|
|
test "renders for organization owner without additional data", %{conn: conn} do
|
|
# register_and_log_in_user creates a user with a Personal org (as owner)
|
|
{:ok, _view, html} = live(conn, ~p"/users/my-data")
|
|
|
|
assert html =~ "My Data"
|
|
assert html =~ "Profile Information"
|
|
assert html =~ "Organizations"
|
|
assert html =~ "Devices"
|
|
assert html =~ "Audit Log"
|
|
end
|
|
|
|
test "renders for organization owner with full data", %{conn: conn, user: user} do
|
|
{:ok, organization} = Towerops.Organizations.create_organization(%{name: "Test Org"}, user.id)
|
|
|
|
{:ok, site} =
|
|
Towerops.Sites.create_site(%{
|
|
name: "Test Site",
|
|
organization_id: organization.id
|
|
})
|
|
|
|
{:ok, device} =
|
|
Towerops.Devices.create_device(%{
|
|
name: "Test Device",
|
|
ip_address: "192.168.1.1",
|
|
site_id: site.id,
|
|
organization_id: organization.id,
|
|
monitoring_enabled: true
|
|
})
|
|
|
|
# Create an alert
|
|
{:ok, _alert} =
|
|
Towerops.Alerts.create_alert(%{
|
|
device_id: device.id,
|
|
alert_type: "device_down",
|
|
triggered_at: DateTime.utc_now(),
|
|
message: "Device is down"
|
|
})
|
|
|
|
{:ok, _view, html} = live(conn, ~p"/users/my-data")
|
|
|
|
assert html =~ "My Data"
|
|
assert html =~ "Profile Information"
|
|
assert html =~ "Organizations"
|
|
assert html =~ "Devices"
|
|
assert html =~ "Recent Alerts"
|
|
assert html =~ "Audit Log"
|
|
assert html =~ "Test Org"
|
|
assert html =~ "Test Device"
|
|
assert html =~ "192.168.1.1"
|
|
end
|
|
end
|
|
end
|