defmodule ToweropsWeb.Plugs.CaptureTimezoneTest do
  use ToweropsWeb.ConnCase, async: true

  alias ToweropsWeb.Plugs.CaptureTimezone

  describe "call/2" do
    test "captures cf-timezone header and stores in session", %{conn: conn} do
      conn =
        conn
        |> init_test_session(%{})
        |> put_req_header("cf-timezone", "America/Chicago")
        |> CaptureTimezone.call([])

      assert get_session(conn, :detected_timezone) == "America/Chicago"
    end

    test "defaults to UTC when cf-timezone header is missing", %{conn: conn} do
      conn =
        conn
        |> init_test_session(%{})
        |> CaptureTimezone.call([])

      assert get_session(conn, :detected_timezone) == "UTC"
    end

    test "defaults to UTC when cf-timezone header is empty", %{conn: conn} do
      conn =
        conn
        |> init_test_session(%{})
        |> put_req_header("cf-timezone", "")
        |> CaptureTimezone.call([])

      assert get_session(conn, :detected_timezone) == "UTC"
    end
  end
end
