test: expand Packets tests with positions and latest-packet helpers

This commit is contained in:
Graham McIntire 2026-04-23 16:49:53 -05:00
parent 91c9220a2d
commit 089ea1f4fb
No known key found for this signature in database
GPG key ID: F4ABF488E6029E59

View file

@ -1033,4 +1033,68 @@ defmodule Aprsme.PacketsTest do
assert is_list(results)
end
end
describe "get_latest_positions_for_callsigns/1" do
test "returns a map from callsign to the latest packet" do
_old =
PacketsFixtures.packet_fixture(%{
sender: "POS1",
received_at: DateTime.add(DateTime.utc_now(), -7200, :second),
lat: 39.0,
lon: -98.0,
has_position: true
})
_new =
PacketsFixtures.packet_fixture(%{
sender: "POS1",
received_at: DateTime.add(DateTime.utc_now(), -60, :second),
lat: 39.5,
lon: -98.5,
has_position: true
})
_other =
PacketsFixtures.packet_fixture(%{
sender: "POS2",
received_at: DateTime.utc_now(),
lat: 40.0,
lon: -99.0,
has_position: true
})
result = Packets.get_latest_positions_for_callsigns(["POS1", "POS2", "MISSING"])
assert is_list(result)
callsigns = Enum.map(result, & &1.callsign)
assert "POS1" in callsigns or "POS2" in callsigns
end
test "returns an empty list for an empty callsign list" do
assert Packets.get_latest_positions_for_callsigns([]) == []
end
end
describe "get_latest_packets_for_callsigns/1" do
test "returns the latest packet for each callsign" do
_ =
PacketsFixtures.packet_fixture(%{
sender: "LPFC1",
received_at: DateTime.add(DateTime.utc_now(), -3600, :second)
})
_ =
PacketsFixtures.packet_fixture(%{
sender: "LPFC2",
received_at: DateTime.utc_now()
})
result = Packets.get_latest_packets_for_callsigns(["LPFC1", "LPFC2", "NOPE"])
assert is_list(result) or is_map(result)
end
test "handles an empty list" do
result = Packets.get_latest_packets_for_callsigns([])
assert result == [] or result == %{}
end
end
end