From bd3f5c043469f19c201d7bcc0cb49ad706a7e5ee Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Fri, 24 Apr 2026 08:58:42 -0500 Subject: [PATCH] test: PacketConsumer item/object detection branches --- test/aprsme/packet_consumer_test.exs | 45 ++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/test/aprsme/packet_consumer_test.exs b/test/aprsme/packet_consumer_test.exs index da39d10..a670cc1 100644 --- a/test/aprsme/packet_consumer_test.exs +++ b/test/aprsme/packet_consumer_test.exs @@ -40,6 +40,51 @@ defmodule Aprsme.PacketConsumerTest do end end + describe "item/object detection" do + test "detects object via info_field prefix ';'" do + events = [ + %{ + sender: "INFOBJ-1", + data_type: "position", + lat: 35.0, + lon: -75.0, + destination: "APRS", + path: "WIDE1-1", + information_field: ";MYOBJ *192200z3500.00N/07500.00W#Test", + raw_packet: "INFOBJ-1>APRS", + data: %{"information_field" => ";MYOBJ *192200z3500.00N/07500.00W#Test"} + } + ] + + state = %{batch: [], batch_length: 0, batch_size: 1, batch_timeout: 1000, max_batch_size: 100, timer: nil} + {:noreply, [], new_state} = PacketConsumer.handle_events(events, nil, state) + Process.sleep(50) + + assert new_state.batch == [] + end + + test "detects item via :itemname" do + events = [ + %{ + sender: "ITEMS-1", + data_type: "item", + lat: 35.0, + lon: -75.0, + destination: "APRS", + path: "WIDE1-1", + itemname: "MyCustomItem", + raw_packet: "ITEMS-1>APRS" + } + ] + + state = %{batch: [], batch_length: 0, batch_size: 1, batch_timeout: 1000, max_batch_size: 100, timer: nil} + {:noreply, [], new_state} = PacketConsumer.handle_events(events, nil, state) + Process.sleep(50) + + assert new_state.batch == [] + end + end + describe "handle_events/3 batch sizing" do test "partial batch just accumulates and re-schedules" do {:consumer, state, _} = PacketConsumer.init(subscribe_to: [])