From 4ea38c05853031482f9618f5fc09e7cd39740134 Mon Sep 17 00:00:00 2001 From: Graham McIntire Date: Fri, 24 Apr 2026 08:57:10 -0500 Subject: [PATCH] test: store_bad_packet error-shape branches --- test/aprsme/packets_test.exs | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/test/aprsme/packets_test.exs b/test/aprsme/packets_test.exs index 93a4b0f..233755b 100644 --- a/test/aprsme/packets_test.exs +++ b/test/aprsme/packets_test.exs @@ -292,6 +292,40 @@ defmodule Aprsme.PacketsTest do end end + describe "store_bad_packet/2 error shape coverage" do + test "stores bad packet from string with struct error" do + # An exception struct — should hit the struct-type branch for error_type. + error = %ArgumentError{message: "bad arg"} + + assert {:ok, bad_packet} = Packets.store_bad_packet("INVALID", error) + assert bad_packet.raw_packet == "INVALID" + assert bad_packet.error_type == "ArgumentError" + assert bad_packet.error_message =~ "bad arg" + end + + test "stores bad packet from string with unstructured error" do + # An error that's neither a map nor a struct — falls to UnknownError. + assert {:ok, bad_packet} = Packets.store_bad_packet("INVALID", :some_atom) + assert bad_packet.error_type == "UnknownError" + assert bad_packet.error_message == ":some_atom" + end + + test "stores bad packet from map with struct error" do + error = %RuntimeError{message: "boom"} + + assert {:ok, bad_packet} = + Packets.store_bad_packet(%{raw_packet: "MAP-STRUCT"}, error) + + assert bad_packet.raw_packet == "MAP-STRUCT" + assert bad_packet.error_type == "RuntimeError" + end + + test "stores bad packet from map with unstructured error" do + assert {:ok, bad_packet} = Packets.store_bad_packet(%{raw_packet: "MAP-UNK"}, :unknown) + assert bad_packet.error_type == "UnknownError" + 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.