Something went wrong. Try again.
[READ-ONLY] Mirror of https://github.com/openstatusHQ/openstatus. ๐ซ Status page with uptime monitoring & API monitoring as code ๐ซ openstatus.dev
bun drizzle-orm monitoring monitoring-as-code nextjs observability on-call open-source shadcn-ui status-page statuspage synthetic-monitoring tinybird turso uptime uptime-checker uptime-monitor
Something went wrong. Try again.
5.2 kB ยท 166 lines
TSX
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167/** @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( <StatusReportEmail pageTitle="Test Page" reportTitle="Test Report" status="investigating" date={new Date().toISOString()} message="Test message" pageComponents={["Monitor 1"]} unsubscribeUrl={unsubscribeUrl} manageUrl={manageUrl} />, );
expect(html).toContain(unsubscribeUrl); expect(html).toContain("Unsubscribe"); });
test("should not include unsubscribe section when URL is not provided", async () => { const html = await render( <StatusReportEmail pageTitle="Test Page" reportTitle="Test Report" status="investigating" date={new Date().toISOString()} message="Test message" pageComponents={["Monitor 1"]} manageUrl={manageUrl} unsubscribeUrl="" />, );
// 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( <StatusReportEmail pageTitle="Test Page" reportTitle="Test Report" status="investigating" date={new Date().toISOString()} message="Test message" pageComponents={["Monitor 1"]} unsubscribeUrl={unsubscribeUrl} manageUrl={manageUrl} />, );
// 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( <StatusReportEmail pageTitle="Test Page" reportTitle="Test Report" status="investigating" date={new Date().toISOString()} message="Test message" pageComponents={["Monitor 1"]} unsubscribeUrl={unsubscribeUrl} manageUrl={manageUrl} />, );
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(<StatusReportEmail {...props} />);
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( <StatusReportEmail pageTitle="Test" reportTitle="Test Report" status={status} date={new Date().toISOString()} message="Test" pageComponents={[]} unsubscribeUrl="https://example.com/unsubscribe" manageUrl="https://example.com/manage" />, );
expect(html).toContain(status.toUpperCase()); } });});