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

52 lines
1.9 KiB
Elixir

defmodule Aprsme.CleanupSchedulerTest do
# Mutates :aprsme, :cleanup_scheduler env; must be serialized with anything
# else that reads it.
use ExUnit.Case, async: false
alias Aprsme.CleanupScheduler
setup do
original = Application.get_env(:aprsme, :cleanup_scheduler)
on_exit(fn -> Application.put_env(:aprsme, :cleanup_scheduler, original || []) end)
:ok
end
describe "init/1" do
test "returns default 6-hour interval when enabled" do
Application.put_env(:aprsme, :cleanup_scheduler, enabled: true)
assert {:ok, %{interval: interval}} = CleanupScheduler.init([])
assert interval == 6 * 60 * 60 * 1000
end
test "honors a configured interval" do
Application.put_env(:aprsme, :cleanup_scheduler, enabled: true, interval: 5_000)
assert {:ok, %{interval: 5_000}} = CleanupScheduler.init([])
end
test "returns nil interval when disabled" do
Application.put_env(:aprsme, :cleanup_scheduler, enabled: false)
assert {:ok, %{interval: nil}} = CleanupScheduler.init([])
end
test "defaults to enabled when no config" do
Application.put_env(:aprsme, :cleanup_scheduler, [])
assert {:ok, %{interval: interval}} = CleanupScheduler.init([])
assert is_integer(interval)
end
test "init schedules a follow-up :schedule_cleanup message when enabled" do
Application.put_env(:aprsme, :cleanup_scheduler, enabled: true, interval: 10)
{:ok, _state} = CleanupScheduler.init([])
# Process.send_after targets self() (the test process in this call context),
# so we should receive the scheduled message shortly.
assert_receive :schedule_cleanup, 100
end
end
describe "handle_info/2" do
test "no-op for :schedule_cleanup when disabled" do
state = %{interval: nil}
assert CleanupScheduler.handle_info(:schedule_cleanup, state) == {:noreply, state}
end
end
end