Some checks failed
Build and Push / Build and Push Docker Image (push) Failing after 4m38s
- 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>
61 lines
1.8 KiB
Elixir
61 lines
1.8 KiB
Elixir
defmodule Microwaveprop.Weather.IemreObservationTest do
|
|
use Microwaveprop.DataCase, async: true
|
|
|
|
alias Microwaveprop.Weather.IemreObservation
|
|
|
|
@valid_attrs %{
|
|
lat: 32.875,
|
|
lon: -97.0,
|
|
date: ~D[2026-03-28],
|
|
hourly: [
|
|
%{"hour" => 0, "p01m_mm" => 0.0},
|
|
%{"hour" => 1, "p01m_mm" => 0.5}
|
|
]
|
|
}
|
|
|
|
describe "changeset/2" do
|
|
test "valid attributes produce a valid changeset" do
|
|
changeset = IemreObservation.changeset(%IemreObservation{}, @valid_attrs)
|
|
assert changeset.valid?
|
|
end
|
|
|
|
test "requires lat, lon, and date" do
|
|
changeset = IemreObservation.changeset(%IemreObservation{}, %{})
|
|
|
|
assert %{
|
|
lat: ["can't be blank"],
|
|
lon: ["can't be blank"],
|
|
date: ["can't be blank"]
|
|
} = errors_on(changeset)
|
|
end
|
|
|
|
test "hourly is optional" do
|
|
attrs = Map.delete(@valid_attrs, :hourly)
|
|
changeset = IemreObservation.changeset(%IemreObservation{}, attrs)
|
|
assert changeset.valid?
|
|
end
|
|
|
|
test "persists to the database" do
|
|
changeset = IemreObservation.changeset(%IemreObservation{}, @valid_attrs)
|
|
assert {:ok, obs} = Repo.insert(changeset)
|
|
assert obs.lat == 32.875
|
|
assert obs.lon == -97.0
|
|
assert obs.date == ~D[2026-03-28]
|
|
assert Enum.count_until(obs.hourly, 3) == 2
|
|
end
|
|
|
|
test "enforces unique constraint on lat, lon, date" do
|
|
assert {:ok, _} =
|
|
%IemreObservation{}
|
|
|> IemreObservation.changeset(@valid_attrs)
|
|
|> Repo.insert()
|
|
|
|
assert {:error, changeset} =
|
|
%IemreObservation{}
|
|
|> IemreObservation.changeset(@valid_attrs)
|
|
|> Repo.insert()
|
|
|
|
assert %{lat: ["has already been taken"]} = errors_on(changeset)
|
|
end
|
|
end
|
|
end
|