prop/test/microwaveprop/rover_planning/path_test.exs
Graham McIntire f644d1796f
test: push coverage 79.64% -> 80.04% across multiple modules
New test files: RoverPlanning.Station, LiveStashGuard, RebatchAsos,
RoverMissionReconcileWorker, RoverPathProfileWorker. Extended existing
suites for PathCompute (resolve_location, build_ionosphere_readout),
HrdpsClient (DEPR fallback, missing-level skip), NexradClient
(fetch_rain_cells HTTP error paths), UserHomeQthLookupWorker (error +
Maidenhead-fallback paths), RoverPlanning.Path (statuses/0 + schema).

3512 tests passing.
2026-05-08 08:42:03 -05:00

120 lines
3.4 KiB
Elixir

defmodule Microwaveprop.RoverPlanning.PathTest do
use Microwaveprop.DataCase, async: true
alias Microwaveprop.RoverPlanning.Path
describe "statuses/0" do
test "returns the full enum list" do
assert Path.statuses() == [:pending, :computing, :complete, :failed]
end
end
describe "schema metadata" do
test "has the expected fields" do
fields = Path.__schema__(:fields)
assert :band_mhz in fields
assert :status in fields
assert :result in fields
assert :error in fields
assert :computed_at in fields
assert :mission_id in fields
assert :rover_location_id in fields
assert :station_id in fields
end
end
describe "changeset/2" do
test "valid attrs produce a valid changeset" do
attrs = %{
mission_id: Ecto.UUID.generate(),
rover_location_id: Ecto.UUID.generate(),
station_id: Ecto.UUID.generate(),
band_mhz: 10_000,
status: :pending
}
changeset = Path.changeset(%Path{}, attrs)
assert changeset.valid?
end
test "missing required fields makes changeset invalid" do
changeset = Path.changeset(%Path{}, %{})
refute changeset.valid?
assert "can't be blank" in errors_on(changeset).mission_id
assert "can't be blank" in errors_on(changeset).rover_location_id
assert "can't be blank" in errors_on(changeset).station_id
assert "can't be blank" in errors_on(changeset).band_mhz
end
test "rejects invalid status" do
attrs = %{
mission_id: Ecto.UUID.generate(),
rover_location_id: Ecto.UUID.generate(),
station_id: Ecto.UUID.generate(),
band_mhz: 10_000,
status: :invalid_status
}
changeset = Path.changeset(%Path{}, attrs)
refute changeset.valid?
assert "is invalid" in errors_on(changeset).status
end
test "rejects zero or negative band_mhz" do
attrs = %{
mission_id: Ecto.UUID.generate(),
rover_location_id: Ecto.UUID.generate(),
station_id: Ecto.UUID.generate(),
band_mhz: 0,
status: :pending
}
changeset = Path.changeset(%Path{}, attrs)
refute changeset.valid?
assert "must be greater than 0" in errors_on(changeset).band_mhz
end
test "accepts complete and failed statuses" do
for status <- [:complete, :failed] do
attrs = %{
mission_id: Ecto.UUID.generate(),
rover_location_id: Ecto.UUID.generate(),
station_id: Ecto.UUID.generate(),
band_mhz: 10_000,
status: status
}
changeset = Path.changeset(%Path{}, attrs)
assert changeset.valid?, "status :#{status} should be valid"
end
end
test "accepts :computing status" do
attrs = %{
mission_id: Ecto.UUID.generate(),
rover_location_id: Ecto.UUID.generate(),
station_id: Ecto.UUID.generate(),
band_mhz: 10_000,
status: :computing
}
changeset = Path.changeset(%Path{}, attrs)
assert changeset.valid?
end
test "accepts optional result and error fields" do
attrs = %{
mission_id: Ecto.UUID.generate(),
rover_location_id: Ecto.UUID.generate(),
station_id: Ecto.UUID.generate(),
band_mhz: 10_000,
status: :failed,
result: nil,
error: "timeout"
}
changeset = Path.changeset(%Path{}, attrs)
assert changeset.valid?
end
end
end