Files
chess-endgame-trainer/test/chesstrainer_web/controllers/health_controller_test.exs
T
owenrees fa1fef7b62 Launch amendments: one login, crawler policy, and asset caching (#180)
* lesson library shown as com,ing soon. re-enable learngin strip

* replace learning strip text with a lasker quote

* remove admin login endpoint

* fix crawler directives and prelaunch login

- noindex the authenticated scope and the 404 catch-all, and cover the
  mailing-list confirmation redirect
- emit noindex, nofollow from the robots meta and /health, and assert
  public pages stay indexable and followable
- stop inventing lastmod values in the sitemap
- log in through /users/log-in during prelaunch now that the admin login
  endpoint is gone; drop create_admin/2 and its orphaned tests

* update caching length to 1 year - name change will invalidate cache

* remove logger

* fix tablebase path breaking tests

* test: check cache headers without requiring built assets

CI's test job does not run mix assets.build, so /assets/css/app.css is a
404 there. Committed piece art is already content-hashed and takes the same
Plug.Static cache option, so the test no longer needs a build step and
passes on a fresh checkout.
2026-11-17 12:55:47 +01:00

63 lines
2.3 KiB
Elixir

defmodule ChesstrainerWeb.HealthControllerTest do
use ChesstrainerWeb.ConnCase, async: false
describe "GET /health" do
test "returns ok with all four fields", %{conn: conn} do
conn = get(conn, ~p"/health")
body = json_response(conn, 200)
assert body["status"] == "ok"
assert body["db"] == "ok"
assert body["tablebase"] == "local"
assert body["process"] == "ok"
assert get_resp_header(conn, "x-robots-tag") == ["noindex, nofollow"]
end
test "returns degraded when local tablebases are not configured", %{conn: conn} do
previous = Application.get_env(:chesstrainer, :tablebase_path)
on_exit(fn -> restore_env(:tablebase_path, previous) end)
Application.delete_env(:chesstrainer, :tablebase_path)
conn = get(conn, ~p"/health")
body = json_response(conn, 200)
assert body["status"] == "degraded"
assert body["db"] == "ok"
assert body["tablebase"] == "not_configured"
assert body["process"] == "ok"
end
test "returns degraded when local tablebases are misconfigured", %{conn: conn} do
previous = Application.get_env(:chesstrainer, :tablebase_path)
on_exit(fn -> restore_env(:tablebase_path, previous) end)
Application.put_env(:chesstrainer, :tablebase_path, "/definitely/not/a/tablebase")
conn = get(conn, ~p"/health")
body = json_response(conn, 200)
assert body["status"] == "degraded"
assert body["db"] == "ok"
assert body["tablebase"] == "fallback"
assert body["process"] == "ok"
end
test "returns 503 when the database is down", %{conn: conn} do
previous = Application.get_env(:chesstrainer, :health_database_check)
on_exit(fn -> restore_env(:health_database_check, previous) end)
Application.put_env(:chesstrainer, :health_database_check, fn -> false end)
conn = get(conn, ~p"/health")
body = json_response(conn, 503)
assert body["status"] == "down"
assert body["db"] == "down"
assert body["tablebase"] == "local"
assert body["process"] == "ok"
assert get_resp_header(conn, "x-robots-tag") == ["noindex, nofollow"]
end
end
defp restore_env(key, nil), do: Application.delete_env(:chesstrainer, key)
defp restore_env(key, value), do: Application.put_env(:chesstrainer, key, value)
end