prop/test/microwaveprop/weather/hrrr_profile_test.exs
Graham McIntire 079346a1b9
Some checks failed
Build and Push / Build and Push Docker Image (push) Failing after 4m38s
fix: resolve all 281 credo issues across source and test files
- F-level (228): replace length/1 with Enum.count_until/2 or pattern
  matching; convert Enum.flat_map+if to Enum.filter+Enum.map; fix
  identity case in narr_client
- W-level (46): normalize dual atom/string key access in weather_layers,
  beacon_measurements, surface, skewt_live, contact_live/show; add
  :data_provider and weather-map assigns to ignored_assigns in credo
  config (consumed by child components credo can't trace); remove
  weak is_list assertion; remove explicit assert_receive timeout
- R-level (6): replace 'This module provides...' moduledocs with
  meaningful descriptions
- Also fix 4 compile-connected xref issues by deferring
  BandConfig.band_options() from module attribute to runtime

Co-Authored-By: Claude <noreply@anthropic.com>
2026-07-29 09:04:21 -05:00

84 lines
2.7 KiB
Elixir

defmodule Microwaveprop.Weather.HrrrProfileTest do
use Microwaveprop.DataCase, async: true
alias Microwaveprop.Weather.HrrrProfile
@sample_profile [
%{"pres" => 1000.0, "hght" => 110, "tmpc" => 25.0, "dwpc" => 18.0},
%{"pres" => 975.0, "hght" => 350, "tmpc" => 23.0, "dwpc" => 16.0},
%{"pres" => 950.0, "hght" => 590, "tmpc" => 21.0, "dwpc" => 14.0}
]
@valid_attrs %{
valid_time: ~U[2026-03-28 18:00:00Z],
lat: 32.90,
lon: -97.04,
run_time: ~U[2026-03-28 18:00:00Z],
profile: @sample_profile,
hpbl_m: 1500.0,
pwat_mm: 25.0,
surface_temp_c: 25.0,
surface_dewpoint_c: 18.0,
surface_pressure_mb: 1013.0,
surface_refractivity: 320.5,
min_refractivity_gradient: -45.0,
ducting_detected: false,
duct_characteristics: nil
}
describe "changeset/2" do
test "valid attributes" do
changeset = HrrrProfile.changeset(%HrrrProfile{}, @valid_attrs)
assert changeset.valid?
end
test "requires valid_time, lat, lon" do
changeset = HrrrProfile.changeset(%HrrrProfile{}, %{})
assert %{
valid_time: ["can't be blank"],
lat: ["can't be blank"],
lon: ["can't be blank"]
} = errors_on(changeset)
end
test "derived params are optional" do
attrs = %{valid_time: ~U[2026-03-28 18:00:00Z], lat: 32.90, lon: -97.04}
changeset = HrrrProfile.changeset(%HrrrProfile{}, attrs)
assert changeset.valid?
end
test "persists to the database with JSONB profile" do
changeset = HrrrProfile.changeset(%HrrrProfile{}, @valid_attrs)
assert {:ok, profile} = Repo.insert(changeset)
assert Enum.count_until(profile.profile, 4) == 3
assert hd(profile.profile)["pres"] == 1000.0
assert profile.ducting_detected == false
assert profile.hpbl_m == 1500.0
end
test "persists duct_characteristics as JSONB" do
duct_chars = [%{"base" => 200, "top" => 500, "strength" => 5.2}]
attrs =
@valid_attrs
|> Map.put(:ducting_detected, true)
|> Map.put(:duct_characteristics, duct_chars)
changeset = HrrrProfile.changeset(%HrrrProfile{}, attrs)
assert {:ok, profile} = Repo.insert(changeset)
assert profile.ducting_detected == true
assert [%{"base" => 200, "top" => 500}] = profile.duct_characteristics
end
test "enforces unique lat + lon + valid_time" do
assert {:ok, _} =
%HrrrProfile{} |> HrrrProfile.changeset(@valid_attrs) |> Repo.insert()
# Partitioned tables raise ConstraintError directly
assert_raise Ecto.ConstraintError, fn ->
%HrrrProfile{} |> HrrrProfile.changeset(@valid_attrs) |> Repo.insert!()
end
end
end
end