aprs.me/test/aprsme_web/live/map_live/url_params_test.exs
Graham McIntire 403300f696
test: broaden unit & property-test coverage (61.8% → 64.7%)
Adds ~800 new tests (incl. 27 StreamData properties) across 22 modules
that previously had little or no coverage. Highlights:

- Pure utility modules (LogSanitizer, PacketFieldWhitelist,
  PacketSanitizer, DeviceParser, CoordinateUtils, BoundsUtils,
  ParamUtils, Convert, WeatherUnits) get thorough unit + property
  coverage including UTF-8 truncation boundaries, antimeridian
  longitude wrap, Haversine symmetry, and unit-conversion inverses.
- JSON view modules (CallsignJSON, ErrorJSON, ChangesetJSON) verified
  for envelope shape and error templating.
- Plugs (HealthCheck, RateLimiter, ApiCSRF) exercised for happy-path
  and halt paths.
- GenServer modules (RegexCache, CleanupScheduler, DeploymentNotifier)
  tested without touching the supervised singleton where possible.
- Drops the orphaned map_live/map_helpers_test.exs whose module name
  collided with the new live/shared/coordinate_utils_test.exs.
2026-04-23 13:32:09 -05:00

95 lines
3.4 KiB
Elixir

defmodule AprsmeWeb.MapLive.UrlParamsTest do
use ExUnit.Case, async: true
alias AprsmeWeb.MapLive.UrlParams
describe "parse_map_params/1" do
test "parses a full set of params" do
{center, zoom} = UrlParams.parse_map_params(%{"lat" => "40.0", "lng" => "-95.0", "z" => "7"})
assert center == %{lat: 40.0, lng: -95.0}
assert zoom == 7
end
test "falls back to defaults for missing params" do
{center, zoom} = UrlParams.parse_map_params(%{})
assert center == UrlParams.default_center()
assert zoom == UrlParams.default_zoom()
end
test "falls back to defaults for garbage values" do
{center, zoom} = UrlParams.parse_map_params(%{"lat" => "foo", "lng" => "bar", "z" => "baz"})
assert center == UrlParams.default_center()
assert zoom == UrlParams.default_zoom()
end
test "rejects out-of-range values" do
{center, _} = UrlParams.parse_map_params(%{"lat" => "200.0", "lng" => "400.0"})
assert center == UrlParams.default_center()
end
end
describe "parse_latitude/1 / parse_longitude/1 / parse_zoom/1" do
test "individual parsers accept valid values" do
assert UrlParams.parse_latitude("30.5") == 30.5
assert UrlParams.parse_longitude("-120.0") == -120.0
assert UrlParams.parse_zoom("10") == 10
end
test "individual parsers return defaults for nil" do
assert UrlParams.parse_latitude(nil) == UrlParams.default_center().lat
assert UrlParams.parse_longitude(nil) == UrlParams.default_center().lng
assert UrlParams.parse_zoom(nil) == UrlParams.default_zoom()
end
test "individual parsers clamp invalid strings to defaults" do
assert UrlParams.parse_latitude("garbage") == UrlParams.default_center().lat
assert UrlParams.parse_zoom("garbage") == UrlParams.default_zoom()
end
end
describe "has_explicit_url_params?/1" do
test "returns true when any of lat, lng, or z is present" do
assert UrlParams.has_explicit_url_params?(%{"lat" => "1"})
assert UrlParams.has_explicit_url_params?(%{"lng" => "1"})
assert UrlParams.has_explicit_url_params?(%{"z" => "5"})
end
test "returns false when none of lat, lng, z is present" do
refute UrlParams.has_explicit_url_params?(%{})
refute UrlParams.has_explicit_url_params?(%{"other" => "1"})
end
test "returns false when keys are present but empty-string (treated truthy)" do
# Empty string is truthy in Elixir, so this actually returns true.
assert UrlParams.has_explicit_url_params?(%{"lat" => ""})
end
end
describe "defaults" do
test "default_center returns USA-centered coordinates" do
%{lat: lat, lng: lng} = UrlParams.default_center()
assert is_float(lat) and is_float(lng)
assert lat >= 25 and lat <= 50
assert lng >= -125 and lng <= -66
end
test "default_zoom is a valid zoom" do
assert UrlParams.default_zoom() == 5
end
end
describe "delegated helpers still work" do
test "parse_float_in_range delegates to ParamUtils" do
assert UrlParams.parse_float_in_range("30.5", 0.0, -90.0, 90.0) == 30.5
end
test "sanitize_numeric_string delegates to ParamUtils" do
assert UrlParams.sanitize_numeric_string("1<x>2") == "12"
end
test "valid_coordinates? delegates to CoordinateUtils" do
assert UrlParams.valid_coordinates?(30.5, -95.0)
refute UrlParams.valid_coordinates?(200, 0)
end
end
end