defmodule ToweropsWeb.ApiDocsControllerTest do use ToweropsWeb.ConnCase, async: true import Towerops.AccountsFixtures import Towerops.OrganizationsFixtures alias Towerops.Accounts.Scope alias Towerops.ApiTokens describe "GET /docs/api" do test "renders index without login", %{conn: conn} do conn = get(conn, "/docs/api") assert html_response(conn, 200) =~ "API" end test "renders index for logged-in user without API tokens", %{conn: conn} do user = user_fixture() org = organization_fixture(user.id) # /docs/api is unscoped — manually inject a scope-with-organization so the # controller exercises the "user with org" branch (sample_token via tokens list). scope = user |> Scope.for_user() |> Scope.put_organization(org) conn = conn |> log_in_user(user) |> Plug.Conn.assign(:current_scope, scope) |> get("/docs/api") assert html_response(conn, 200) =~ "API" end test "renders index for logged-in user with API tokens", %{conn: conn} do user = user_fixture() org = organization_fixture(user.id) {:ok, {_token, _raw}} = ApiTokens.create_api_token(%{ organization_id: org.id, user_id: user.id, name: "Test Token" }) scope = user |> Scope.for_user() |> Scope.put_organization(org) conn = conn |> log_in_user(user) |> Plug.Conn.assign(:current_scope, scope) |> get("/docs/api") assert html_response(conn, 200) =~ "API" end end end