Skip to content

Rallly is an open-source scheduling and collaboration tool designed to make organizing events and meetings easier.

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

import { recipientDomains, scrubAddresses } from "./send";

test("returns the domain of a bare address", () => {
  expect(recipientDomains("[email protected]")).toEqual(["example.com"]);
});

test("strips a display-name wrapper and lowercases", () => {
  expect(recipientDomains("Jessie Smith <[email protected]>")).toEqual([
    "example.com",
  ]);
});

test("returns one domain per recipient without leaking later addresses", () => {
  expect(recipientDomains("[email protected],[email protected]; C <[email protected]>")).toEqual([
    "one.test",
    "two.test",
  ]);
});

test("returns nothing when there is no address", () => {
  expect(recipientDomains("not-an-address")).toEqual([]);
});

test("scrubs addresses out of SMTP replies", () => {
  expect(
    scrubAddresses(
      "550 5.1.1 <[email protected]>: Recipient address rejected: [email protected]",
    ),
  ).toBe("550 5.1.1 <[redacted]>: Recipient address rejected: [redacted]");
  expect(
    scrubAddresses('Rejected "support team"@example.com and [email protected]'),
  ).toBe("Rejected [redacted] and [redacted]");
  expect(scrubAddresses('Rejected "a\\"b"@example.com')).toBe(
    "Rejected [redacted]",
  );
  expect(scrubAddresses("connect ECONNREFUSED 127.0.0.1:1")).toBe(
    "connect ECONNREFUSED 127.0.0.1:1",
  );
});