test: cover MobileController format_equipment_details interface mapping

Adds direct call to MobileController.get_device with a snmp_device that
has interfaces — drives the Enum.map over interfaces in
format_equipment_details that previously had no fixture coverage.
This commit is contained in:
Graham McIntire 2026-05-09 11:55:50 -05:00
parent 1ae6c2b879
commit 940b4daf14

View file

@ -208,6 +208,54 @@ defmodule ToweropsWeb.Api.MobileControllerTest do
assert is_list(body["sensors"])
assert body["uptime"] =~ "h"
end
test "get_device direct call maps interfaces when SNMP device has them",
%{user: user, organization: org} do
alias Towerops.Snmp.Interface
alias ToweropsWeb.Api.MobileController
{:ok, site} =
Towerops.Sites.create_site(%{name: "Iface Site", organization_id: org.id})
{:ok, device} =
Towerops.Devices.create_device(%{
name: "WithIfaces",
ip_address: "10.55.55.55",
site_id: site.id,
organization_id: org.id,
snmp_enabled: true
})
{:ok, snmp_dev} =
Towerops.Repo.insert(%Device{
device_id: device.id,
sys_uptime: 5_000,
sys_descr: "test"
})
{:ok, _iface} =
Towerops.Repo.insert(%Interface{
snmp_device_id: snmp_dev.id,
if_index: 1,
if_name: "ge-0/0/0",
if_alias: "uplink",
if_oper_status: "up",
if_admin_status: "up",
if_speed: 1_000_000_000,
if_phys_address: "aa:bb:cc:dd:ee:ff"
})
conn = Plug.Conn.assign(build_conn(), :current_user, user)
conn = MobileController.get_device(conn, %{"id" => device.id})
assert conn.status == 200
body = Jason.decode!(conn.resp_body)
assert [iface] = body["interfaces"]
assert iface["name"] == "ge-0/0/0"
assert iface["alias"] == "uplink"
assert iface["status"] == "up"
assert iface["mac_address"] == "aa:bb:cc:dd:ee:ff"
end
end
describe "list_alerts — formatting" do