towerops/test/towerops_web/controllers/page_controller_test.exs
Graham McIntire ca041fe5aa feat: add Accept: text/markdown content negotiation for agent compatibility
Intercepts requests with Accept: text/markdown at endpoint level (before
the router's :accepts plug rejects them) and returns hardcoded markdown
representations for /, /privacy, and /terms.
2026-04-17 14:14:31 -05:00

82 lines
2.4 KiB
Elixir

defmodule ToweropsWeb.PageControllerTest do
use ToweropsWeb.ConnCase
import Towerops.AccountsFixtures
test "GET / renders marketing page when not authenticated", %{conn: conn} do
conn = get(conn, ~p"/")
assert html_response(conn, 200) =~ "business impact"
assert html_response(conn, 200) =~ "network event"
end
test "homepage includes RFC 8288 Link discovery headers", %{conn: conn} do
conn = get(conn, ~p"/")
link_header = conn |> get_resp_header("link") |> List.first()
assert link_header =~ ~s(rel="api-catalog")
assert link_header =~ ~s(rel="service-doc")
assert link_header =~ ~s(rel="status")
assert link_header =~ "/.well-known/api-catalog"
assert link_header =~ "/docs/api"
assert link_header =~ "/health"
end
test "GET / redirects to organizations when authenticated", %{conn: conn} do
user = user_fixture()
conn = log_in_user(conn, user)
conn = get(conn, ~p"/")
assert redirected_to(conn) == ~p"/dashboard"
end
test "GET /privacy renders privacy policy page", %{conn: conn} do
conn = get(conn, ~p"/privacy")
response = html_response(conn, 200)
assert response =~ "Privacy Policy"
# Should render the privacy policy template
assert response
end
test "GET /privacy renders for authenticated users", %{conn: conn} do
user = user_fixture()
conn = log_in_user(conn, user)
conn = get(conn, ~p"/privacy")
response = html_response(conn, 200)
assert response =~ "Privacy Policy"
end
test "GET /terms renders terms of service page", %{conn: conn} do
conn = get(conn, ~p"/terms")
response = html_response(conn, 200)
assert response =~ "Terms of Service"
# Should render the terms template
assert response
end
test "GET /terms renders for authenticated users", %{conn: conn} do
user = user_fixture()
conn = log_in_user(conn, user)
conn = get(conn, ~p"/terms")
response = html_response(conn, 200)
assert response =~ "Terms of Service"
end
describe "GET / with Accept: text/markdown" do
test "returns markdown content when markdown is requested", %{conn: conn} do
conn =
conn
|> put_req_header("accept", "text/markdown")
|> get(~p"/")
assert response(conn, 200)
assert get_resp_header(conn, "content-type") == ["text/markdown; charset=utf-8"]
body = response(conn, 200)
assert body =~ "# TowerOps"
end
end
end