/** @jsxRuntime automatic @jsxImportSource react */ import "./test-preload.ts"; import { expect } from "@std/expect"; import { describe, test } from "@std/testing/bdd"; import { render } from "react-email"; import StatusReportEmail from "../emails/status-report"; import { statusReportSubject } from "./client"; describe("Status Report Email - Unsubscribe Link in Body", () => { const unsubscribeUrl = "https://openstatus.openstatus.dev/unsubscribe/test-token"; const manageUrl = "https://openstatus.openstatus.dev/manage/test-token"; test("should include unsubscribe link in email body when URL is provided", async () => { const html = await render( , ); expect(html).toContain(unsubscribeUrl); expect(html).toContain("Unsubscribe"); }); test("should not include unsubscribe section when URL is not provided", async () => { const html = await render( , ); // Should not contain the unsubscribe text when no URL provided expect(html).not.toContain("Unsubscribe"); }); test("should render unsubscribe link as clickable", async () => { const html = await render( , ); // Check that the URL is in an href attribute expect(html).toContain(`href="${unsubscribeUrl}"`); }); test("should render the unsubscribe link in the footer, outside the card", async () => { const html = await render( , ); expect(html.indexOf("Test message")).toBeLessThan( html.indexOf(unsubscribeUrl), ); expect(html).toContain("Manage notifications"); }); }); describe("Status Report Email - Subject Line", () => { const reportTitle = "API Outage"; test('prepends "RESOLVED:" only when status is "resolved"', () => { expect(statusReportSubject({ status: "resolved", reportTitle })).toBe( `RESOLVED: ${reportTitle}`, ); }); test("uses the bare report title for ongoing report statuses", () => { const ongoing = ["investigating", "identified", "monitoring"] as const; for (const status of ongoing) { const subject = statusReportSubject({ status, reportTitle }); expect(subject).toBe(reportTitle); expect(subject).not.toContain("RESOLVED:"); } }); test('prepends "Planned Maintenance:" when status is "maintenance"', () => { expect(statusReportSubject({ status: "maintenance", reportTitle })).toBe( `Planned Maintenance: ${reportTitle}`, ); }); }); describe("Status Report Email - Email Content Validation", () => { test("should include all required email fields", async () => { const props = { pageTitle: "openstatus", reportTitle: "API Outage", status: "investigating" as const, date: "2024-01-15T10:00:00.000Z", message: "We are investigating the issue", pageComponents: ["API", "Web"], unsubscribeUrl: "https://openstatus.openstatus.dev/unsubscribe/test", manageUrl: "https://openstatus.openstatus.dev/manage/test", }; const html = await render(); expect(html).toContain(props.pageTitle); expect(html).toContain(props.reportTitle); expect(html).toContain(props.message); expect(html).toContain("API"); expect(html).toContain("Web"); expect(html).toContain(props.unsubscribeUrl); }); test("should handle all status types correctly", async () => { const statuses = [ "investigating", "identified", "monitoring", "resolved", "maintenance", ] as const; for (const status of statuses) { const html = await render( , ); expect(html).toContain(status.toUpperCase()); } }); });