prop/test/microwaveprop/rover_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

100 lines
3.4 KiB
Elixir

defmodule Microwaveprop.RoverTest do
use Microwaveprop.DataCase, async: true
import Microwaveprop.AccountsFixtures
alias Microwaveprop.Rover
alias Microwaveprop.Rover.FixedStation
describe "list_stations/1" do
test "returns user's stations ordered by position asc" do
user = user_fixture()
{:ok, _b} = Rover.create_station(user, %{callsign: "B5BBB", lat: 33.0, lon: -96.0})
{:ok, _a} = Rover.create_station(user, %{callsign: "A5AAA", lat: 33.0, lon: -96.0})
stations = Rover.list_stations(user)
assert Enum.map(stations, & &1.callsign) == ["B5BBB", "A5AAA"]
assert Enum.map(stations, & &1.position) == [0, 1]
end
end
describe "create_station/2" do
test "derives lat/lon from grid only" do
user = user_fixture()
{:ok, station} = Rover.create_station(user, %{callsign: "W5LUA", grid: "EM13qc"})
assert_in_delta station.lat, 33.10, 0.05
assert_in_delta station.lon, -96.625, 0.05
end
test "errors with neither grid nor lat/lon" do
user = user_fixture()
assert {:error, %Ecto.Changeset{}} = Rover.create_station(user, %{callsign: "W5LUA"})
end
test "unique constraint surfaces as changeset error" do
user = user_fixture()
{:ok, _} = Rover.create_station(user, %{callsign: "W5LUA", lat: 33.0, lon: -96.0})
assert {:error, %Ecto.Changeset{}} =
Rover.create_station(user, %{callsign: "W5LUA", lat: 34.0, lon: -97.0})
end
end
describe "update_station/3" do
test "foreign user returns :not_found" do
user = user_fixture()
other = user_fixture()
{:ok, station} = Rover.create_station(user, %{callsign: "W5LUA", lat: 33.0, lon: -96.0})
assert {:error, :not_found} = Rover.update_station(other, station.id, %{selected: false})
end
end
describe "delete_station/2" do
test "foreign user returns :not_found" do
user = user_fixture()
other = user_fixture()
{:ok, station} = Rover.create_station(user, %{callsign: "W5LUA", lat: 33.0, lon: -96.0})
assert {:error, :not_found} = Rover.delete_station(other, station.id)
end
test "owner deletes" do
user = user_fixture()
{:ok, station} = Rover.create_station(user, %{callsign: "W5LUA", lat: 33.0, lon: -96.0})
assert {:ok, %FixedStation{}} = Rover.delete_station(user, station.id)
assert Rover.list_stations(user) == []
end
end
describe "toggle_selected/2" do
test "flips boolean" do
user = user_fixture()
{:ok, station} = Rover.create_station(user, %{callsign: "W5LUA", lat: 33.0, lon: -96.0})
assert station.selected == true
assert {:ok, updated} = Rover.toggle_selected(user, station.id)
assert updated.selected == false
assert {:ok, again} = Rover.toggle_selected(user, station.id)
assert again.selected == true
end
end
describe "default_stations/0" do
test "returns 3 hardcoded NTMS stations" do
stations = Rover.default_stations()
assert Enum.count_until(stations, 4) == 3
callsigns = Enum.map(stations, & &1.callsign)
assert "W5LUA" in callsigns
assert "W5HN" in callsigns
assert "N5XU" in callsigns
assert Enum.all?(stations, & &1.selected)
assert Enum.map(stations, & &1.position) == [0, 1, 2]
Enum.each(stations, fn s ->
assert is_float(s.lat)
assert is_float(s.lon)
end)
end
end
end