test: DeviceLive.Show trigger_manual_backup success and disabled-mikrotik branches

This commit is contained in:
Graham McIntire 2026-05-09 12:26:23 -05:00
parent bf2ad4031b
commit d15d2cf29f

View file

@ -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")