Transactional mail, crawler metadata, and asset measurement (#179)

* Send transactional email from no-reply@mail.innersquare.app

Centralise the sender identity, reply-to address and SES configuration set in Chesstrainer.Mail so no notifier can drift. Add MAIL_REDIRECT_TO for smoke tests and a mix mail.check task that exercises the SES mailbox simulators, and document the setup in the deploy guide and .env.example.

* Tighten crawler metadata and keep play pages out of search

Canonical URLs no longer carry query strings, public pages get an OG image, WebSite JSON-LD and a per-page language, and the sitemap dates the landing page only. Play and guest-training routes are marked noindex so tens of thousands of near-identical pages stay out of the index.

* Measure built asset sizes with mix assets.sizes

Report raw, gzip and brotli sizes for built JS and CSS, and record the current numbers plus the board-code split recommendation in docs/assets.md.
This commit is contained in:
2026-11-17 10:29:45 +01:00
committed by GitHub
parent b33c5e334a
commit 37e0ac8e56
24 changed files with 666 additions and 44 deletions
+72
View File
@@ -0,0 +1,72 @@
defmodule Chesstrainer.MailTest do
use ExUnit.Case, async: false
import Swoosh.TestAssertions
alias Chesstrainer.Branding
alias Chesstrainer.Mail
setup do
previous_redirect = Application.get_env(:chesstrainer, :mail_redirect_to)
previous_set = Application.get_env(:chesstrainer, :ses_configuration_set)
on_exit(fn ->
restore_env(:mail_redirect_to, previous_redirect)
restore_env(:ses_configuration_set, previous_set)
end)
:ok
end
defp simple_email(recipient \\ "player@example.com") do
Swoosh.Email.new()
|> Swoosh.Email.to(recipient)
|> Swoosh.Email.subject("Confirmation instructions")
|> Swoosh.Email.text_body("Hello")
end
test "sends from the no-reply address on the mail subdomain" do
{:ok, email} = Mail.deliver(simple_email())
assert email.from == {Branding.name(), "no-reply@mail.innersquare.app"}
assert email.reply_to == {"", "support@innersquare.app"}
end
test "stamps the SES configuration set on the provider options" do
{:ok, email} = Mail.deliver(simple_email())
assert email.provider_options[:configuration_set_name] == "my-first-configuration-set"
end
test "the configuration set can be overridden by config" do
Application.put_env(:chesstrainer, :ses_configuration_set, "staging-set")
{:ok, email} = Mail.deliver(simple_email())
assert email.provider_options[:configuration_set_name] == "staging-set"
end
test "redirects every recipient when a test address is configured" do
Application.put_env(:chesstrainer, :mail_redirect_to, "ops@example.com")
email = simple_email("player@example.com")
{:ok, sent} = Mail.deliver(email)
assert sent.to == [{"", "ops@example.com"}]
assert sent.bcc == []
assert sent.cc == []
assert sent.subject == "[→ player@example.com] Confirmation instructions"
assert {"X-Original-To", "player@example.com"} in sent.headers
end
test "delivers the message it returns" do
{:ok, email} = Mail.deliver(simple_email())
assert_email_sent(to: "player@example.com", subject: "Confirmation instructions")
assert email.to == [{"", "player@example.com"}]
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
@@ -86,7 +86,11 @@ defmodule ChesstrainerWeb.PageControllerTest do
{~s(meta[property="og:title"]), Branding.home_title()},
{~s(meta[property="og:description"]), @description},
{~s(meta[property="og:url"]), canonical},
{~s(meta[name="twitter:card"]), "summary"},
{~s(meta[property="og:image"]), ChesstrainerWeb.SEO.og_image_url()},
{~s(meta[property="og:image:width"]), "1200"},
{~s(meta[property="og:image:height"]), "630"},
{~s(meta[name="twitter:card"]), "summary_large_image"},
{~s(meta[name="twitter:image"]), ChesstrainerWeb.SEO.og_image_url()},
{~s(meta[name="twitter:title"]), Branding.home_title()},
{~s(meta[name="twitter:description"]), @description}
] do
@@ -94,6 +98,36 @@ defmodule ChesstrainerWeb.PageControllerTest do
end
end
test "canonical URL drops query parameters", %{conn: conn} do
html = conn |> get("/?utm_source=newsletter&utm_medium=email") |> html_response(200)
document = LazyHTML.from_document(html)
assert [canonical] =
LazyHTML.attribute(LazyHTML.query(document, ~s(link[rel="canonical"])), "href")
assert canonical == ChesstrainerWeb.Endpoint.url() <> "/"
assert LazyHTML.attribute(LazyHTML.query(document, ~s(meta[property="og:url"])), "content") ==
[canonical]
end
test "home page publishes WebSite structured data", %{conn: conn} do
html = conn |> get(~p"/") |> html_response(200)
document = LazyHTML.from_document(html)
json =
document
|> LazyHTML.query(~s(script[type="application/ld+json"]))
|> LazyHTML.text()
|> Jason.decode!()
assert json["@context"] == "https://schema.org"
types = Enum.map(json["@graph"], & &1["@type"])
assert "WebSite" in types
assert "Organization" in types
end
test "GET /privacy renders the privacy policy", %{conn: conn} do
html = conn |> get(~p"/privacy") |> html_response(200)
document = LazyHTML.from_document(html)
@@ -150,6 +184,7 @@ defmodule ChesstrainerWeb.PageControllerTest do
document = LazyHTML.from_document(html)
assert LazyHTML.text(LazyHTML.query(document, "h1")) == "Mentions légales"
assert html =~ ~s(lang="fr")
assert html =~ "Owen REES"
assert html =~ "929"
assert html =~ "293 B"
@@ -11,12 +11,19 @@ defmodule ChesstrainerWeb.SitemapControllerTest do
assert body =~ ~s(<?xml version="1.0" encoding="UTF-8"?>)
assert body =~ ~s(<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">)
assert body =~ "<loc>#{base_url}/</loc>"
assert body =~ "<lastmod>#{Date.utc_today() |> Date.to_iso8601()}</lastmod>"
assert body =~ "<loc>#{base_url}/privacy</loc>"
assert body =~ "<loc>#{base_url}/terms-conditions</loc>"
assert body =~ "<loc>#{base_url}/mentions-legales</loc>"
assert length(:binary.matches(body, "<url>")) == 4
end
test "only dates the landing page", %{conn: conn} do
body = conn |> get(~p"/sitemap.xml") |> response(200)
assert length(:binary.matches(body, "<lastmod>")) == 1
end
test "is served as XML", %{conn: conn} do
conn = get(conn, ~p"/sitemap.xml")
@@ -59,6 +59,15 @@ defmodule ChesstrainerWeb.EndgameLive.GuestTrainTest do
end
describe "access" do
test "is marked noindex for crawlers", %{conn: conn} do
endgame = endgame_fixture()
seed_tablebase(endgame.fen, moves: grading_moves())
conn = get(conn, ~p"/guest-train")
assert get_resp_header(conn, "x-robots-tag") == ["noindex, nofollow"]
end
test "lets an anonymous visitor play a random puzzle", %{conn: conn} do
endgame = endgame_fixture()
seed_tablebase(endgame.fen, moves: grading_moves())
@@ -135,6 +135,15 @@ defmodule ChesstrainerWeb.EndgameLive.PlayTest do
end
describe "mount" do
test "is marked noindex for crawlers", %{conn: conn} do
endgame = endgame_fixture()
seed_tablebase(endgame.fen)
conn = get(conn, ~p"/endgames/#{endgame.public_code}/play")
assert get_resp_header(conn, "x-robots-tag") == ["noindex, nofollow"]
end
test "renders the chessboard hook div and pushes init_board", %{conn: conn} do
endgame = endgame_fixture(color: :white)
seed_tablebase(endgame.fen)