aprs.me/test/support/test_helpers.ex
Graham McInitre 1006fdaefc refactor: remove dead code, duplication, and over-abstractions
- Delete dead config keys and test file (typo'd aprsme_is_*, vacuous disable test)
- Remove duplicate function clauses and identical function pairs
- Rename misleading one_hour_ago variable to one_day_ago
- Strip stale Oban comment
- Remove TestHelpers time function duplicates
- Inline Aprsme.Schema module (only 1 caller)
- Deduplicate prod esbuild config
- Thin SymbolRenderer delegations, inline TimeUtils wrappers
- Remove redundant DeploymentNotifier GenServer polling
- Replace random fallback in get_callsign_key with sentinel
2026-07-21 10:36:49 -05:00

66 lines
1.6 KiB
Elixir

defmodule AprsmeWeb.TestHelpers do
@moduledoc """
Common test helper functions to reduce duplication across test files.
"""
alias Aprsme.Packet
alias Aprsme.Repo
@doc """
Creates a test packet with default values that can be overridden.
"""
def create_test_packet(attrs \\ %{}) do
default_attrs = %{
sender: "TEST-1",
base_callsign: "TEST",
ssid: "1",
lat: Decimal.new("33.0000"),
lon: Decimal.new("-96.0000"),
has_position: true,
received_at: DateTime.truncate(DateTime.utc_now(), :second),
data_type: "position"
}
attrs = Map.merge(default_attrs, attrs)
Repo.insert(%Packet{
sender: attrs.sender,
base_callsign: attrs.base_callsign,
ssid: attrs.ssid,
lat: attrs.lat,
lon: attrs.lon,
has_position: attrs.has_position,
received_at: attrs.received_at,
data_type: attrs.data_type,
symbol_table_id: Map.get(attrs, :symbol_table_id),
symbol_code: Map.get(attrs, :symbol_code),
temperature: Map.get(attrs, :temperature),
humidity: Map.get(attrs, :humidity),
wind_speed: Map.get(attrs, :wind_speed)
})
end
@doc """
Creates common test bounds for Texas area.
"""
def texas_bounds do
%{
"north" => "33.0",
"south" => "32.0",
"east" => "-96.0",
"west" => "-97.0"
}
end
@doc """
Creates common test bounds for a restrictive area.
"""
def restrictive_bounds do
%{
"north" => "31.0",
"south" => "30.0",
"east" => "-95.0",
"west" => "-96.0"
}
end
end