Adds ~600 new test cases (2013 → 2613 tests; 170 properties; 0
failures) across 12 new test files plus expansions of eight existing
files. Big lifts per module:
ContactLive.Mechanism 33 → 100%
MetricsPlug 54 → ~100%
Microwaveprop.Release 15.8 → 70%+
Telemetry 38 → 76%
HrrrNativeGridWorker 27.7 → 76%
ContactLive.Show 34 → 48% (handler + render branches)
Admin.ContactEditLive 49.7 → 70%+
GefsFetchWorker 35.8 → ~55%
IonosphereFetchWorker 56.3 → 75%
PathLive 58.9 → 67%
WeatherMapLive 66.9 → 80.2%
RoverLive 0 → 70.3%
ContactMapLive 59.2 → 89.8%
ContactMapController 0 → 100%
Mix tasks (Rust.Golden, Notebook, Backtest, HrrrBackfill,
HrrrClimatology, HrrrNativeBackfill, NexradBackfill,
RadarBackfill, ImportContestLogs, PropagationGrid,
ResetEnrichment, Hrrr.PurgeGridPoints) 0 → ~60-100%
Two incidental fixes made while adding tests:
- ContactLive.Show.handle_event("toggle_flag", ...) was passing
socket.assigns.current_scope to admin?/1 instead of socket.assigns,
so admins never matched the pattern and every toggle ran the
"Admins only." flash branch. Flag now toggles for admins again.
- Commercial.PollWorker.fetch_weather/1 promoted from private to
@doc'd public so the IEM-fetch + ASOS-upsert path can be tested
directly without driving perform/1 through live SNMP (which was
timing out for ~50 s per test in the earlier attempt).
Stable property-test additions cover the dewpoint-from-RH monotonicity,
nearest_run/1 idempotence, and the ionosphere station envelope.
60 lines
2 KiB
Elixir
60 lines
2 KiB
Elixir
defmodule MicrowavepropWeb.ContactMapControllerTest do
|
|
use MicrowavepropWeb.ConnCase, async: false
|
|
|
|
alias Microwaveprop.Cache
|
|
|
|
setup do
|
|
# The controller caches a gzipped payload under a module-level key —
|
|
# clear it between tests so gzip vs identity requests don't reuse
|
|
# each other's output.
|
|
Cache.invalidate({MicrowavepropWeb.ContactMapController, :gzipped_payload})
|
|
:ok
|
|
end
|
|
|
|
describe "GET /api/contacts/map" do
|
|
test "serves plain JSON when the client does not accept gzip", %{conn: conn} do
|
|
conn = get(conn, ~p"/api/contacts/map")
|
|
|
|
assert conn.status == 200
|
|
assert get_resp_header(conn, "content-type") == ["application/json; charset=utf-8"]
|
|
assert get_resp_header(conn, "content-encoding") == []
|
|
assert [cache_control] = get_resp_header(conn, "cache-control")
|
|
assert cache_control =~ "max-age=60"
|
|
|
|
# Body must be parseable JSON; on an empty dev/test DB that's a
|
|
# list (possibly empty) of contact tuples.
|
|
assert {:ok, parsed} = Jason.decode(conn.resp_body)
|
|
assert is_list(parsed)
|
|
end
|
|
|
|
test "emits gzip-encoded body when the client advertises gzip support", %{conn: conn} do
|
|
conn =
|
|
conn
|
|
|> put_req_header("accept-encoding", "gzip, deflate")
|
|
|> get(~p"/api/contacts/map")
|
|
|
|
assert conn.status == 200
|
|
assert get_resp_header(conn, "content-encoding") == ["gzip"]
|
|
|
|
# The gzipped body decompresses to valid JSON.
|
|
decompressed = :zlib.gunzip(conn.resp_body)
|
|
assert {:ok, _} = Jason.decode(decompressed)
|
|
end
|
|
|
|
test "caches the gzipped payload across requests", %{conn: conn} do
|
|
conn1 =
|
|
conn
|
|
|> put_req_header("accept-encoding", "gzip")
|
|
|> get(~p"/api/contacts/map")
|
|
|
|
conn2 =
|
|
build_conn()
|
|
|> put_req_header("accept-encoding", "gzip")
|
|
|> get(~p"/api/contacts/map")
|
|
|
|
# Byte-identical bodies prove the second hit came from the cache,
|
|
# not a fresh Radio.contact_map_payload/0 + gzip round-trip.
|
|
assert conn1.resp_body == conn2.resp_body
|
|
end
|
|
end
|
|
end
|