Files
owenrees 37e0ac8e56 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.
2026-11-17 10:29:45 +01:00

73 lines
2.3 KiB
Elixir

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