57,186 prod contacts stored pos1/pos2 with 'lng'; 1,133 used 'lon'. Every Elixir caller carried a `pos["lon"] || pos["lng"]` fallback — which just caused a SQL widget to silently miscount 98% of contacts (count_narr_done used `pos1->>'lon'` directly, no fallback, so every lng-keyed row returned NULL and failed the coverage check). - Migration rewrites every pos1/pos2 JSONB in place, renaming 'lng' to 'lon' and dropping 'lng'. - Removes all 20+ `|| pos["lng"]` fallbacks across lib/, workers, scorer, weather, radio.ex, contact show view, and recalibrator. - lib_ml/propagation_analyze.ex SQL now reads pos1->>'lon' directly (was reading 'lng' only, which would have broken after migration). - priv/repo/import_contacts.exs one-time seed script now emits 'lon' with string keys, matching production shape. - Test fixtures in 4 test files normalized to 'lon'. - Two lng-characterization tests deleted — nonsensical post-normalize. - Updated notebook + old import_weather script to match. - JS hook contact_map_hook.ts TypeScript type narrowed to 'lon'.
46 lines
1.4 KiB
Elixir
46 lines
1.4 KiB
Elixir
defmodule Microwaveprop.Radio.ContactTest do
|
|
use Microwaveprop.DataCase, async: true
|
|
|
|
alias Microwaveprop.Radio.Contact
|
|
|
|
@valid_attrs %{
|
|
station1: "W1AW",
|
|
station2: "K3LR",
|
|
qso_timestamp: ~U[2026-03-28 12:00:00Z],
|
|
grid1: "FN31pr",
|
|
grid2: "EN91jm",
|
|
pos1: %{lat: 41.714, lon: -72.727},
|
|
pos2: %{lat: 41.049, lon: -80.166},
|
|
mode: "SSB",
|
|
band: Decimal.new("144.2"),
|
|
distance_km: Decimal.new("623.4")
|
|
}
|
|
|
|
describe "changeset/2" do
|
|
test "valid attributes" do
|
|
changeset = Contact.changeset(%Contact{}, @valid_attrs)
|
|
assert changeset.valid?
|
|
end
|
|
|
|
test "requires station1, station2, qso_timestamp, and band (mode is optional)" do
|
|
changeset = Contact.changeset(%Contact{}, %{})
|
|
|
|
errors = errors_on(changeset)
|
|
assert errors.station1 == ["can't be blank"]
|
|
assert errors.station2 == ["can't be blank"]
|
|
assert errors.qso_timestamp == ["can't be blank"]
|
|
assert errors.band == ["can't be blank"]
|
|
refute Map.has_key?(errors, :mode)
|
|
end
|
|
|
|
test "persists to the database" do
|
|
changeset = Contact.changeset(%Contact{}, @valid_attrs)
|
|
assert {:ok, contact} = Repo.insert(changeset)
|
|
assert contact.station1 == "W1AW"
|
|
assert contact.station2 == "K3LR"
|
|
assert contact.mode == "SSB"
|
|
assert Decimal.equal?(contact.band, Decimal.new("144.2"))
|
|
assert Decimal.equal?(contact.distance_km, Decimal.new("623.4"))
|
|
end
|
|
end
|
|
end
|