aprs.me/test/aprsme/release_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

63 lines
1.8 KiB
Elixir

defmodule Aprsme.ReleaseTest do
# Mutates DEPLOYED_AT env var and :aprsme, :deployed_at — can't run in parallel.
use ExUnit.Case, async: false
alias Aprsme.Release
setup do
original_env = System.get_env("DEPLOYED_AT")
original_config = Application.get_env(:aprsme, :deployed_at)
on_exit(fn ->
if is_nil(original_env) do
System.delete_env("DEPLOYED_AT")
else
System.put_env("DEPLOYED_AT", original_env)
end
Application.put_env(:aprsme, :deployed_at, original_config)
end)
:ok
end
describe "init/0" do
test "returns DateTime and stores it in app env when DEPLOYED_AT is unset" do
System.delete_env("DEPLOYED_AT")
Application.delete_env(:aprsme, :deployed_at)
result = Release.init()
assert %DateTime{} = result
assert Application.get_env(:aprsme, :deployed_at) == result
end
test "parses valid ISO8601 DEPLOYED_AT" do
System.put_env("DEPLOYED_AT", "2024-01-15T12:00:00Z")
result = Release.init()
assert DateTime.to_iso8601(result) == "2024-01-15T12:00:00Z"
end
test "falls back to current time for invalid DEPLOYED_AT" do
System.put_env("DEPLOYED_AT", "not-a-timestamp")
before = DateTime.utc_now()
result = Release.init()
assert %DateTime{} = result
assert DateTime.compare(result, before) in [:gt, :eq]
end
end
describe "deployed_at/0" do
test "returns the stored value when set" do
dt = ~U[2024-06-01 00:00:00Z]
Application.put_env(:aprsme, :deployed_at, dt)
assert Release.deployed_at() == dt
end
test "initializes to current time when unset" do
Application.delete_env(:aprsme, :deployed_at)
result = Release.deployed_at()
assert %DateTime{} = result
assert Application.get_env(:aprsme, :deployed_at) == result
end
end
end