diff --git a/test/towerops_web/live/device_live/show_events_test.exs b/test/towerops_web/live/device_live/show_events_test.exs index 4d867402..66d9317b 100644 --- a/test/towerops_web/live/device_live/show_events_test.exs +++ b/test/towerops_web/live/device_live/show_events_test.exs @@ -277,6 +277,43 @@ defmodule ToweropsWeb.DeviceLive.ShowEventsTest do assert html =~ "no agent assigned" or html =~ "MikroTik" or html =~ "MikroTik API is not enabled" end + test "backup_now with agent but mikrotik disabled shows error flash", + %{conn: conn, user: user, device: device, organization: organization} do + {:ok, token, _raw} = Towerops.AgentsFixtures.agent_token_fixture(organization.id) + {:ok, _} = Towerops.Agents.assign_device_to_agent(token.id, device.id) + + conn = log_in_user(conn, user) + {:ok, view, _html} = live(conn, ~p"/devices/#{device.id}?tab=backups") + + html = render_hook(view, "backup_now", %{}) + # Device has no mikrotik_enabled — should hit the !device.mikrotik_enabled branch + assert html =~ "MikroTik API is not enabled" or html =~ "MikroTik" + end + + test "backup_now with agent and mikrotik enabled creates backup request", + %{conn: conn, user: user, device: device, organization: organization} do + {:ok, token, _raw} = Towerops.AgentsFixtures.agent_token_fixture(organization.id) + {:ok, _} = Towerops.Agents.assign_device_to_agent(token.id, device.id) + + {:ok, _device} = + Towerops.Devices.update_device(device, %{ + mikrotik_enabled: true, + mikrotik_credential_source: "device", + mikrotik_username: "admin", + mikrotik_password: "secret", + mikrotik_use_ssl: true, + mikrotik_port: 8729 + }) + + conn = log_in_user(conn, user) + {:ok, view, _html} = live(conn, ~p"/devices/#{device.id}?tab=backups") + + html = render_hook(view, "backup_now", %{}) + # Triggering trigger_manual_backup with a backup request created + assert html =~ "Manual backup requested" or + html =~ "Failed to create backup request" + end + test "backups tab pagination handles ?page param", %{conn: conn, user: user, device: device} do conn = log_in_user(conn, user) {:ok, _view, html} = live(conn, ~p"/devices/#{device.id}?tab=backups&page=1")