diff --git a/test/towerops_web/live/dashboard_live_test.exs b/test/towerops_web/live/dashboard_live_test.exs index 130909b4..18b1507d 100644 --- a/test/towerops_web/live/dashboard_live_test.exs +++ b/test/towerops_web/live/dashboard_live_test.exs @@ -384,6 +384,51 @@ defmodule ToweropsWeb.DashboardLiveTest do end end + describe "acknowledge_alert event" do + test "ack'd alert disappears from active feed", %{conn: conn, organization: organization, site: site} do + {:ok, device} = create_device(organization, site) + + {:ok, alert} = + Towerops.Alerts.create_alert(%{ + device_id: device.id, + alert_type: "device_down", + triggered_at: DateTime.utc_now(), + message: "Down for ack" + }) + + {:ok, view, _html} = live(conn, ~p"/dashboard") + html = render_click(view, "acknowledge_alert", %{"id" => alert.id}) + assert html =~ "Alert acknowledged" or html =~ "Failed" + end + + test "acknowledging an alert from another org returns not-found", + %{conn: conn} do + other_user = Towerops.AccountsFixtures.user_fixture() + {:ok, other_org} = Towerops.Organizations.create_organization(%{name: "Other"}, other_user.id) + {:ok, other_site} = Towerops.Sites.create_site(%{name: "Other", organization_id: other_org.id}) + + {:ok, other_device} = + Towerops.Devices.create_device(%{ + name: "Other Dev", + ip_address: "10.0.0.99", + site_id: other_site.id, + organization_id: other_org.id + }) + + {:ok, alert} = + Towerops.Alerts.create_alert(%{ + device_id: other_device.id, + alert_type: "device_down", + triggered_at: DateTime.utc_now(), + message: "Foreign" + }) + + {:ok, view, _html} = live(conn, ~p"/dashboard") + html = render_click(view, "acknowledge_alert", %{"id" => alert.id}) + assert html =~ "Alert not found" + end + end + defp create_device(organization, site, name \\ "Test Device", ip \\ "192.168.1.1") do Towerops.Devices.create_device(%{ name: name,