defmodule MicrowavepropWeb.Api.V1.ProfileControllerTest do use MicrowavepropWeb.ConnCase, async: true alias Microwaveprop.AccountsFixtures alias Microwaveprop.Beacons alias Microwaveprop.Radio alias MicrowavepropWeb.Api.RateLimiter setup do RateLimiter.reset() :ok end describe "GET /api/v1/profiles/:callsign" do test "returns the profile + contacts + approved beacons", %{conn: conn} do user = AccountsFixtures.user_fixture(%{callsign: "W5TEST"}) {:ok, _contact} = Radio.create_contact( %{ "station1" => "W5TEST", "station2" => "K5OK", "qso_timestamp" => "2026-01-02T00:00:00Z", "band" => "10000", "grid1" => "EM12", "grid2" => "EM13", "mode" => "CW", "submitter_email" => "fixture@example.com" }, user.id ) {:ok, beacon} = Beacons.create_beacon(user, %{ frequency_mhz: 10_368.1, callsign: "W5HN", lat: 32.897, lon: -97.038, power_mw: 1000.0, height_ft: 100, keying: "on_off" }) {:ok, _approved} = Beacons.approve_beacon(beacon) body = conn |> get(~p"/api/v1/profiles/W5TEST") |> json_response(200) assert body["user"]["callsign"] == "W5TEST" refute Map.has_key?(body["user"], "email") assert body["contacts"] != [] assert body["beacons"] != [] end test "case-insensitive lookup", %{conn: conn} do _user = AccountsFixtures.user_fixture(%{callsign: "W5LOWER"}) body = conn |> get(~p"/api/v1/profiles/w5lower") |> json_response(200) assert body["user"]["callsign"] == "W5LOWER" end test "404 when callsign is not registered", %{conn: conn} do conn = get(conn, ~p"/api/v1/profiles/Z9NOPE") assert json_response(conn, 404) end end end