prop/test/microwaveprop/propagation/untested_functions_test.exs
Graham McIntire fd976b0cd5
fix: resolve 391 Credo issues across codebase
- Add jump_credo_checks ~> 0.4 with all 20 checks enabled
- Fix all standard Credo issues: 139 @spec (113 done, 26 remain),
  4 refactoring, 3 alias usage, 9 System.cmd env, 5 unsafe_to_atom,
  2 max line length, 9 assert_receive timeout
- Fix 170+ jump_credo_checks warnings:
  - 117 TopLevelAliasImportRequire: move nested alias/import to module top
  - 32 UseObanProWorker: switch to Oban.Pro.Worker
  - 4 DoctestIExExamples: add doctests / create test file
  - ~20 WeakAssertion: strengthen type-check assertions
  - Various ConditionalAssertion, AssertReceiveTimeout fixes
- Exclude vendor/ from Credo analysis
- Remaining: 175 warnings (mostly opinionated WeakAssertion,
  AvoidSocketAssignsInTest), 26 @spec annotations
2026-06-12 13:51:32 -05:00

126 lines
3.6 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_nil(result) or 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 result == []
end
test "returns a list with default opts" do
assert 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 result == :ok
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)
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)
end
end
describe "warm_cache_and_broadcast/2" do
test "runs without raising when no data" do
result = Propagation.warm_cache_and_broadcast(10_000, ~U[2026-05-01 12:00:00Z])
assert result == {:error, :enoent}
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 result == {:ok, 0}
end
end
end