test: Packets MicE struct + ParseError position extraction
This commit is contained in:
parent
2352a7ef9e
commit
3c5447e0b6
1 changed files with 44 additions and 1 deletions
|
|
@ -1,6 +1,7 @@
|
|||
defmodule Aprsme.PacketsTest do
|
||||
use Aprsme.DataCase, async: true
|
||||
|
||||
alias Aprs.Types.MicE
|
||||
alias Aprsme.BadPacket
|
||||
alias Aprsme.Packet
|
||||
alias Aprsme.Packets
|
||||
|
|
@ -66,7 +67,7 @@ defmodule Aprsme.PacketsTest do
|
|||
raw_packet: "TEST3>APRS:`123abc",
|
||||
data_type: "mic_e",
|
||||
data_extended: %{
|
||||
__struct__: Aprs.Types.MicE,
|
||||
__struct__: MicE,
|
||||
lat_degrees: 39,
|
||||
lat_minutes: 50,
|
||||
lat_direction: :north,
|
||||
|
|
@ -326,6 +327,48 @@ defmodule Aprsme.PacketsTest do
|
|||
end
|
||||
end
|
||||
|
||||
describe "store_packet/1 with MicE struct position extraction" do
|
||||
test "extracts position from a MicE struct with numeric lat/lon" do
|
||||
packet_data = %{
|
||||
sender: "MICESTRUCT",
|
||||
base_callsign: "MICESTRUCT",
|
||||
ssid: "0",
|
||||
destination: "APRS",
|
||||
raw_packet: "MICESTRUCT>APRS",
|
||||
data_type: "mic_e",
|
||||
data_extended: %MicE{
|
||||
lat_degrees: 33,
|
||||
lat_minutes: 30,
|
||||
lat_direction: :north,
|
||||
lon_degrees: 96,
|
||||
lon_minutes: 30,
|
||||
lon_direction: :west
|
||||
}
|
||||
}
|
||||
|
||||
assert {:ok, packet} = Packets.store_packet(packet_data)
|
||||
assert packet.sender == "MICESTRUCT"
|
||||
end
|
||||
|
||||
test "handles a ParseError struct in data_extended gracefully" do
|
||||
packet_data = %{
|
||||
sender: "PARSEERR",
|
||||
base_callsign: "PARSEERR",
|
||||
ssid: "0",
|
||||
destination: "APRS",
|
||||
raw_packet: "PARSEERR>APRS",
|
||||
data_type: "position",
|
||||
data_extended: struct(Aprs.Types.ParseError)
|
||||
}
|
||||
|
||||
# ParseError branch should return {nil, nil} for position — packet stores
|
||||
# without coordinate data.
|
||||
result = Packets.store_packet(packet_data)
|
||||
# Either stores successfully without position or validation fails.
|
||||
assert match?({:ok, _}, result) or match?({:error, _}, result)
|
||||
end
|
||||
end
|
||||
|
||||
describe "store_packet/1 error paths" do
|
||||
test "storage exception path stores a bad packet" do
|
||||
# Send data that causes changeset insertion to fail at the DB level.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue