Skip to content

Open-source status page, incident response and uptime monitoring

1.4 KB
Raw Blame
import { describe, expect, test } from "vitest";

import { statusPageFrom } from "./sender";

describe("statusPageFrom", () => {
  test("quotes the page title", () => {
    expect(statusPageFrom("Acme")).toBe(
      '"Acme" <[email protected]>',
    );
  });

  test("keeps commas inside the quoted name", () => {
    expect(statusPageFrom("Acme, Inc.")).toBe(
      '"Acme, Inc." <[email protected]>',
    );
  });

  test("strips characters that would break the header", () => {
    expect(statusPageFrom('Acme "EU" <status>\r\nBcc: x\\y')).toBe(
      '"Acme EU status Bcc: x y" <[email protected]>',
    );
  });

  test("strips @ so the name can't pose as an address", () => {
    expect(statusPageFrom("[email protected]")).toBe(
      '"security paypal.com" <[email protected]>',
    );
  });

  test("caps the length without splitting characters", () => {
    const from = statusPageFrom(`${"a".repeat(59)}πŸš€πŸš€`);
    expect(from).toBe(
      `"${"a".repeat(59)}πŸš€" <[email protected]>`,
    );
  });

  test("falls back to openstatus when nothing is left", () => {
    expect(statusPageFrom(' "<>" ')).toBe(
      '"openstatus" <[email protected]>',
    );
    expect(statusPageFrom(null)).toBe(
      '"openstatus" <[email protected]>',
    );
  });
});