import { describe, expect, test } from "vitest"; import { renderReactEmail } from "../render-helpers.js"; import { defaultMailBrand, withBrandDefaults } from "../_layout/theme.js"; import { InvalidActionUrlError } from "../_layout/Button.js"; import { WelcomeEmail } from "./Welcome.js"; describe("WelcomeEmail", () => { test("renders default-brand named welcome (snapshot)", () => { const result = renderReactEmail(); expect(result.html).toMatchSnapshot("html"); expect(result.text).toMatchSnapshot("text"); }); test("falls back to anonymous greeting when name missing", () => { const { html } = renderReactEmail(); expect(html).toContain("Welcome!"); expect(html).not.toContain("Welcome, "); }); test("applies safe tenant copy and color overrides without replacing the HiveGrid logo", () => { const brand = withBrandDefaults({ productName: "Acme", primaryColor: "#123456", logoUrl: "https://cdn.acme.test/l.png" }); const { html } = renderReactEmail(); expect(html).toContain("Welcome to Acme, Ada!"); expect(html).toContain("#123456"); expect(html).toContain("https://hivegrid.de/hivegrid-logo.png"); expect(html).not.toContain("https://cdn.acme.test/l.png"); }); test("escapes user content via React (XSS-safe)", () => { const { html } = renderReactEmail( ); expect(html).not.toContain(""); expect(html).toContain("<script>"); }); test("rejects insecure action URLs", () => { expect(() => renderReactEmail()).toThrow(InvalidActionUrlError); }); });