defmodule AprsmeWeb.TestHelpersTest do
  use Aprsme.DataCase, async: true

  alias AprsmeWeb.TestHelpers

  describe "create_test_packet/1" do
    test "creates a packet with defaults" do
      {:ok, packet} = TestHelpers.create_test_packet()
      assert packet.sender == "TEST-1"
      assert packet.base_callsign == "TEST"
    end

    test "overrides with attrs" do
      {:ok, packet} = TestHelpers.create_test_packet(%{sender: "CUSTOM-9"})
      assert packet.sender == "CUSTOM-9"
    end

    test "creates packet with weather attrs" do
      {:ok, packet} =
        TestHelpers.create_test_packet(%{
          sender: "WXHELPER",
          temperature: 72.0,
          humidity: 50.0,
          wind_speed: 5.0
        })

      assert packet.temperature == 72.0
      assert packet.humidity == 50.0
      assert packet.wind_speed == 5.0
    end
  end

  describe "bounds helpers" do
    test "texas_bounds returns a map with all four directions" do
      bounds = TestHelpers.texas_bounds()
      assert %{"north" => _, "south" => _, "east" => _, "west" => _} = bounds
    end

    test "restrictive_bounds returns a map with all four directions" do
      bounds = TestHelpers.restrictive_bounds()
      assert %{"north" => _, "south" => _, "east" => _, "west" => _} = bounds
    end
  end

  describe "time helpers" do
    test "hours_ago returns a DateTime earlier than now" do
      then_dt = AprsmeWeb.TimeUtils.hours_ago(2)
      assert DateTime.before?(then_dt, DateTime.utc_now())
    end

    test "days_ago returns a DateTime earlier than now" do
      then_dt = AprsmeWeb.TimeUtils.days_ago(3)
      assert DateTime.before?(then_dt, DateTime.utc_now())
    end
  end
end
