test: normalize_ssid integer coercion + keyset cursor pagination

This commit is contained in:
Graham McIntire 2026-04-24 09:58:39 -05:00
parent 8af9300469
commit a4fed063f7
No known key found for this signature in database
GPG key ID: F4ABF488E6029E59

View file

@ -419,6 +419,58 @@ defmodule Aprsme.PacketsTest do
assert lat > 0
assert lon < 0
end
test "keyset cursor excludes rows at/before cursor when paginating get_recent_packets" do
now = DateTime.truncate(DateTime.utc_now(), :microsecond)
older = DateTime.add(now, -3600, :second)
_newer_pk =
PacketsFixtures.packet_fixture(%{
sender: "CURSORA",
base_callsign: "CURSORA",
lat: 33.0,
lon: -96.0,
received_at: now,
has_position: true
})
older_pk =
PacketsFixtures.packet_fixture(%{
sender: "CURSORB",
base_callsign: "CURSORB",
lat: 33.0,
lon: -96.0,
received_at: older,
has_position: true
})
# Use a cursor pointing to the older packet's received_at/id — only rows
# strictly older should be returned, so we expect the set NOT to include
# the cursor row itself.
cursor = %{received_at: older_pk.received_at, id: older_pk.id}
results = Packets.get_recent_packets(%{hours_back: 2, cursor: cursor, limit: 50})
senders = Enum.map(results, & &1.sender)
refute "CURSORA" in senders
refute "CURSORB" in senders
end
test "integer SSID is coerced to string via normalize_ssid" do
# Covers the `defp normalize_ssid(%{ssid: ssid} = attrs), do: ...` clause
# that triggers when ssid is a non-binary, non-nil value.
packet_data = %{
sender: "SSIDI-5",
base_callsign: "SSIDI",
ssid: 5,
destination: "APRS",
raw_packet: "SSIDI-5>APRS:!3300.00N/09600.00W#",
data_type: "position",
data_extended: %{latitude: 33.0, longitude: -96.0}
}
assert {:ok, packet} = Packets.store_packet(packet_data)
assert packet.ssid == "5"
end
end
describe "store_packet/1 error paths" do