Poll UBNT AirFiber radios (AF11X + AF60-LR) every 5 minutes via net-snmp CLI, storing signal metrics in commercial_samples. Fetches ASOS weather alongside each cycle for propagation correlation. Includes 7 seeded link definitions, Oban cron worker, and net-snmp in the Docker image.
99 lines
2.5 KiB
Elixir
99 lines
2.5 KiB
Elixir
defmodule Microwaveprop.CommercialTest do
|
|
use Microwaveprop.DataCase, async: true
|
|
|
|
alias Microwaveprop.Commercial
|
|
alias Microwaveprop.Commercial.Link
|
|
|
|
setup do
|
|
Repo.delete_all(Link)
|
|
:ok
|
|
end
|
|
|
|
@link_attrs %{
|
|
label: "test-link",
|
|
host: "10.0.0.1",
|
|
community: "public",
|
|
radio_type: "af11x",
|
|
weather_station: "KTKI",
|
|
enabled: true
|
|
}
|
|
|
|
describe "enabled_links/0" do
|
|
test "returns only enabled links" do
|
|
{:ok, _enabled} = Commercial.create_link(@link_attrs)
|
|
|
|
{:ok, _disabled} =
|
|
Commercial.create_link(%{@link_attrs | label: "disabled-link", enabled: false})
|
|
|
|
links = Commercial.enabled_links()
|
|
assert length(links) == 1
|
|
assert hd(links).label == "test-link"
|
|
end
|
|
|
|
test "returns empty list when no enabled links" do
|
|
assert Commercial.enabled_links() == []
|
|
end
|
|
end
|
|
|
|
describe "create_link/1" do
|
|
test "creates a link with valid attrs" do
|
|
assert {:ok, link} = Commercial.create_link(@link_attrs)
|
|
assert link.label == "test-link"
|
|
assert link.enabled == true
|
|
end
|
|
|
|
test "returns error for invalid attrs" do
|
|
assert {:error, _changeset} = Commercial.create_link(%{})
|
|
end
|
|
end
|
|
|
|
describe "create_sample/1" do
|
|
test "creates a sample for a link" do
|
|
{:ok, link} = Commercial.create_link(@link_attrs)
|
|
|
|
attrs = %{
|
|
link_id: link.id,
|
|
sampled_at: DateTime.utc_now(),
|
|
rx_power_0: -55.0,
|
|
tx_power: 20.0,
|
|
link_state: 1
|
|
}
|
|
|
|
assert {:ok, sample} = Commercial.create_sample(attrs)
|
|
assert sample.rx_power_0 == -55.0
|
|
assert sample.link_id == link.id
|
|
end
|
|
end
|
|
|
|
describe "weather_stations/0" do
|
|
test "returns unique weather stations from enabled links" do
|
|
{:ok, _} = Commercial.create_link(@link_attrs)
|
|
|
|
{:ok, _} =
|
|
Commercial.create_link(%{@link_attrs | label: "link-2", host: "10.0.0.2"})
|
|
|
|
{:ok, _} =
|
|
Commercial.create_link(%{
|
|
@link_attrs
|
|
| label: "link-3",
|
|
host: "10.0.0.3",
|
|
weather_station: "KDFW"
|
|
})
|
|
|
|
stations = Commercial.weather_stations()
|
|
assert Enum.sort(stations) == ["KDFW", "KTKI"]
|
|
end
|
|
|
|
test "excludes disabled links" do
|
|
{:ok, _} = Commercial.create_link(%{@link_attrs | enabled: false})
|
|
|
|
assert Commercial.weather_stations() == []
|
|
end
|
|
|
|
test "excludes nil weather stations" do
|
|
{:ok, _} = Commercial.create_link(%{@link_attrs | weather_station: nil})
|
|
|
|
assert Commercial.weather_stations() == []
|
|
end
|
|
end
|
|
end
|