prop/test/microwaveprop/propagation/untested_functions_test.exs
Graham McIntire aab3c3736c
feat: extend HRRR forecast horizon from 18h to 48h
HRRR publishes f21-f48 at 3-hourly intervals in addition to the
hourly f01-f18 we already fetch. This extends the grid_tasks seed
from 19 rows (1 analysis + 18 forecast) to 29 rows (1 analysis +
18 hourly + 10 3-hourly), and bumps the UI forecast window
constant from 18h to 48h so the map timeline and path calculator
forecast chart automatically show the extended horizon.

No Rust logic changes needed — the pipeline is data-driven and
u8 forecast_hour already handles f48.
2026-06-10 11:36:58 -05:00

126 lines
3.8 KiB
Elixir

defmodule Microwaveprop.Propagation.UntestedFunctionsTest do
use Microwaveprop.DataCase, async: true
alias Microwaveprop.Propagation
describe "hot_cache_window/0" do
test "returns a tuple of two DateTimes spanning the forecast window" do
{past, future} = Propagation.hot_cache_window()
assert %DateTime{} = past
assert %DateTime{} = future
assert DateTime.before?(past, future)
now = DateTime.utc_now()
diff_s = abs(DateTime.diff(now, past))
assert_in_delta diff_s, 3600, 60
diff_future_s = DateTime.diff(future, now)
assert_in_delta diff_future_s, 48 * 3600, 60
end
end
describe "latest_valid_time/0" do
test "returns nil when no propagation_scores exist" do
assert Propagation.latest_valid_time() == nil
end
end
describe "latest_valid_time/1" do
test "returns nil when no scores exist for a band" do
assert Propagation.latest_valid_time(10_000) == nil
assert Propagation.latest_valid_time(24_000) == nil
end
end
describe "ml_model/0" do
test "returns nil when no model is loaded" do
assert Propagation.ml_model() == nil
end
end
describe "available_valid_times/1" do
test "returns empty list when no scores exist for a band" do
assert Propagation.available_valid_times(10_000) == []
end
end
describe "scores_at/3" do
test "returns empty list when no scores exist" do
assert Propagation.scores_at(10_000, DateTime.utc_now()) == []
end
test "returns empty list with bounds" do
bounds = %{"south" => 30.0, "north" => 35.0, "west" => -100.0, "east" => -95.0}
assert Propagation.scores_at(10_000, DateTime.utc_now(), bounds) == []
end
end
describe "scores_at_fresh/3" do
test "returns empty list when no scores exist" do
assert Propagation.scores_at_fresh(10_000, DateTime.utc_now()) == []
end
end
describe "latest_scores/2" do
test "returns empty list when no scores exist" do
assert Propagation.latest_scores(10_000) == []
end
test "returns empty list with bounds" do
bounds = %{"south" => 30.0, "north" => 35.0, "west" => -100.0, "east" => -95.0}
assert Propagation.latest_scores(10_000, bounds) == []
end
end
describe "point_forecast/3" do
test "returns nil/empty when no scores exist" do
result = Propagation.point_forecast(10_000, 32.9, -97.0)
assert is_list(result) or is_nil(result) or is_map(result)
end
end
describe "list_recent_run_timings/1" do
test "returns a list (empty by default)" do
result = Propagation.list_recent_run_timings(limit: 10)
assert is_list(result)
end
test "returns a list with default opts" do
assert is_list(Propagation.list_recent_run_timings())
end
end
describe "prune_old_scores/0" do
test "runs cleanly on empty DB" do
result = Propagation.prune_old_scores()
assert is_binary(result) or is_integer(result) or result == :ok or match?({:ok, _}, result)
end
end
describe "point_detail/4" do
test "returns nil/empty when no scores exist" do
result = Propagation.point_detail(10_000, 32.9, -97.0)
assert is_nil(result) or is_map(result)
end
test "with explicit valid_time returns nil/empty" do
result = Propagation.point_detail(24_000, 32.9, -97.0, ~U[2026-05-01 12:00:00Z])
assert is_nil(result) or is_map(result)
end
end
describe "warm_cache_and_broadcast/2" do
test "runs without raising when no data" do
_ = Propagation.warm_cache_and_broadcast(10_000, ~U[2026-05-01 12:00:00Z])
assert true
end
end
describe "replace_scores/2" do
test "empty list is a no-op" do
result = Propagation.replace_scores([], ~U[2026-05-01 12:00:00Z])
assert match?({:ok, _}, result) or result == :ok or is_integer(result)
end
end
end