defmodule ToweropsWeb.Api.MobileAuthControllerTest do
  use ToweropsWeb.ConnCase, async: true

  describe "verify_qr_token" do
    test "returns error for missing token", %{conn: conn} do
      conn = post(conn, ~p"/api/v1/mobile/auth/qr/verify", %{})

      assert json_response(conn, 400)["error"] == "Missing token parameter"
    end

    test "returns error for invalid token", %{conn: conn} do
      conn = post(conn, ~p"/api/v1/mobile/auth/qr/verify", %{"token" => "invalid"})

      assert json_response(conn, 401)["valid"] == false
    end
  end

  describe "complete_qr_login" do
    test "returns error for missing token", %{conn: conn} do
      conn = post(conn, ~p"/api/v1/mobile/auth/qr/complete", %{})

      assert json_response(conn, 400)["error"] == "Missing token parameter"
    end

    test "returns error for invalid token", %{conn: conn} do
      conn =
        post(conn, ~p"/api/v1/mobile/auth/qr/complete", %{
          "token" => "invalid",
          "device_name" => "Test Phone"
        })

      assert json_response(conn, 401)["error"] == "Invalid or expired token"
    end
  end
end
