Fix KeyError on :data when rendering raw broadcast packets in callsign view
Raw APRS broadcast payloads don't have a :data key (only %Packet{}
structs do). Use Map.get/3 instead of dot-access to handle both cases.
This commit is contained in:
parent
4f5483de19
commit
f803c46b92
2 changed files with 45 additions and 1 deletions
|
|
@ -60,7 +60,7 @@
|
|||
</td>
|
||||
<td>
|
||||
<span class="text-sm font-mono">
|
||||
<% info_field = (packet.data || %{})["information_field"] || "" %>
|
||||
<% info_field = (Map.get(packet, :data) || %{})["information_field"] || "" %>
|
||||
<%= if String.length(info_field) > 50 do %>
|
||||
<span title={info_field}>
|
||||
{String.slice(info_field, 0, 50)}...
|
||||
|
|
|
|||
44
test/aprsme_web/live/packets_live/callsign_view_test.exs
Normal file
44
test/aprsme_web/live/packets_live/callsign_view_test.exs
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
defmodule AprsmeWeb.PacketsLive.CallsignViewTest do
|
||||
use AprsmeWeb.ConnCase
|
||||
|
||||
import Phoenix.LiveViewTest
|
||||
|
||||
describe "live packet broadcast" do
|
||||
test "handles raw broadcast packet without :data key", %{conn: conn} do
|
||||
{:ok, view, _html} = live(conn, "/packets/DB0WUN-13")
|
||||
|
||||
# Simulate a raw broadcast payload (as it arrives from the APRS pipeline)
|
||||
# This map does NOT have a :data key — only %Packet{} structs do
|
||||
raw_payload = %{
|
||||
sender: "DB0WUN-13",
|
||||
data_type: :weather,
|
||||
destination: "APN000",
|
||||
path: "TCPIP*,qAC,T2EISBERG",
|
||||
base_callsign: "DB0WUN",
|
||||
ssid: "13",
|
||||
received_at: DateTime.utc_now(),
|
||||
latitude: Decimal.new("50.0001"),
|
||||
longitude: Decimal.new("12.1393"),
|
||||
temperature: 31,
|
||||
humidity: 89,
|
||||
wind_speed: 3,
|
||||
comment: "232/003g009t031r000p000P000b10215h89L000eMB63",
|
||||
device_identifier: "APN000",
|
||||
data_extended: %{
|
||||
data_type: :weather,
|
||||
comment: "232/003g009t031r000p000P000b10215h89L000eMB63",
|
||||
latitude: Decimal.new("50.0001"),
|
||||
longitude: Decimal.new("12.1393"),
|
||||
symbol_code: "_",
|
||||
symbol_table_id: "/"
|
||||
}
|
||||
}
|
||||
|
||||
AprsmeWeb.Endpoint.broadcast!("aprs_messages", "packet", raw_payload)
|
||||
|
||||
# Should render without crashing
|
||||
html = render(view)
|
||||
assert html =~ "DB0WUN-13"
|
||||
end
|
||||
end
|
||||
end
|
||||
Loading…
Add table
Reference in a new issue