test: improve sitemap controller test coverage

Assign response body once to fix the double call, rename the test,
and assert all 6 public URLs plus the exact <loc> count.
This commit is contained in:
Graham McIntire 2026-04-17 14:00:57 -05:00
parent 3f82c1c110
commit 20df4df566

View file

@ -2,17 +2,20 @@ defmodule ToweropsWeb.SitemapControllerTest do
use ToweropsWeb.ConnCase, async: true
describe "GET /sitemap.xml" do
test "returns valid XML with public pages", %{conn: conn} do
test "returns valid XML with all public pages", %{conn: conn} do
conn = get(conn, "/sitemap.xml")
assert response(conn, 200)
assert get_resp_header(conn, "content-type") == ["text/xml; charset=utf-8"]
body = response(conn, 200)
assert get_resp_header(conn, "content-type") == ["text/xml; charset=utf-8"]
assert body =~ ~r/<\?xml/
assert body =~ "<urlset"
assert body =~ "<loc>"
assert body =~ "/privacy"
assert body =~ "/terms"
assert body =~ ~r|<loc>http[^<]+/</loc>|
assert body =~ "/privacy</loc>"
assert body =~ "/terms</loc>"
assert body =~ "/docs/api</loc>"
assert body =~ "/docs/graphql</loc>"
assert body =~ "/help</loc>"
assert length(Regex.scan(~r/<loc>/, body)) == 6
end
end
end