prop/test/microwaveprop_web/live/skewt_location_resolver_test.exs
Graham McIntire 888701e627
test: bump coverage 80% -> 81.3% via more LiveView + module tests
- Pskr.Client: 0% -> 18% (init/standby/handle_info/terminate)
- RoverPlanningLive.PathShow: 0% -> 82% (mount/load_path)
- Rover.CandidateDetail: 0% -> partial (summarize/5 with stations)
- Mix.Tasks.Weather.RebatchAsos: 0% -> covered (wrapper run/1)
- HrrrNativeClient: 57% -> 67% (fetch_native_duct_grid error paths)
- RoverLive: 40% -> 48% (toggle/delete/update_station_grid logged-in)
- PathLive: 62% -> 63% (path_forecast_detail + rover_path_id branches)
- PathCompute: 64% -> 64% (compute/4 full pipeline + resolve_location)
- SkewtLive: 29% -> 31% (search/select_time event no-ops)
- SkewtLocationResolver: 38% -> 60%+ (callsign cache + error paths)

3557 tests passing.
2026-05-08 09:10:34 -05:00

77 lines
2.7 KiB
Elixir

defmodule MicrowavepropWeb.SkewtLocationResolverTest do
use Microwaveprop.DataCase, async: false
alias Microwaveprop.CallsignLocation.Location
alias MicrowavepropWeb.SkewtLocationResolver
describe "classify/1" do
test "recognises 4/6/8-character Maidenhead grid squares" do
assert SkewtLocationResolver.classify("EM12") == :grid
assert SkewtLocationResolver.classify("EM12kp") == :grid
assert SkewtLocationResolver.classify("EM12kp37") == :grid
end
test "recognises typical US/foreign callsigns" do
assert SkewtLocationResolver.classify("W5ISP") == :callsign
assert SkewtLocationResolver.classify("KM5PO") == :callsign
assert SkewtLocationResolver.classify("VE3ABC") == :callsign
assert SkewtLocationResolver.classify("G0ABC") == :callsign
end
test "anything else is treated as an address" do
assert SkewtLocationResolver.classify("Dallas, TX") == :address
assert SkewtLocationResolver.classify("123 Main St, Plano TX") == :address
assert SkewtLocationResolver.classify("Eiffel Tower") == :address
end
test "is whitespace and case tolerant" do
assert SkewtLocationResolver.classify(" em12 ") == :grid
assert SkewtLocationResolver.classify("w5isp") == :callsign
end
end
describe "resolve/1 — callsign branch" do
test "resolves a cached callsign via CallsignLocation lookup" do
# Seed the cache so the resolver doesn't hit QRZ.
%Location{}
|> Location.changeset(%{
callsign: "W5ISP",
latitude: 33.0,
longitude: -97.0,
gridsquare: "EM13QC"
})
|> Microwaveprop.Repo.insert!()
assert {:ok, resolved} = SkewtLocationResolver.resolve("W5ISP")
assert resolved.source == :callsign
assert resolved.lat == 33.0
assert resolved.lon == -97.0
assert resolved.label =~ "W5ISP"
end
test "surfaces the lookup error message for an unknown callsign" do
# No cached row + a QRZ stub that 404s.
Req.Test.stub(Microwaveprop.Qrz.Client, fn conn ->
Plug.Conn.send_resp(conn, 404, "Not Found")
end)
assert {:error, msg} = SkewtLocationResolver.resolve("XX9XYZ")
assert msg =~ "callsign lookup failed"
end
end
describe "resolve/1 — grid square branch" do
test "returns lat/lon for a valid grid square" do
assert {:ok, %{lat: lat, lon: lon, label: "EM12KP", source: :grid}} =
SkewtLocationResolver.resolve("EM12kp")
assert_in_delta lat, 32.646, 0.01
assert_in_delta lon, -97.125, 0.01
end
test "round-trips a 4-char grid" do
assert {:ok, %{label: "EM12", source: :grid}} =
SkewtLocationResolver.resolve("EM12")
end
end
end