Files
WRNexusJS/packages/mail/test/mail.test.ts
T
Clintchiz 64ab20cc95
Quality / quality (ubuntu-latest) (push) Failing after 22s
Quality / quality (windows-latest) (push) Canceled after 0s
feat: add application productivity foundations
2026-08-23 11:13:03 +05:30

19 lines
783 B
TypeScript

import { expect, test } from "bun:test";
import { defineMail, defineMailTemplate } from "../src/index.ts";
test("mail templates render and sandbox blocks accidental recipients", async () => {
const sent: unknown[] = [];
const mail = defineMail({
from: "hello@example.com",
sandbox: { enabled: true, allowlist: ["dev@example.com"] },
driver: { send: async (message) => void sent.push(message) },
});
const welcome = defineMailTemplate<{ name: string }>({
subject: ({ name }) => `Hello ${name}`,
html: ({ name }) => `<b>${name}</b>`,
});
await mail.send(await mail.render(welcome, { name: "Ada" }, "dev@example.com"));
expect(sent).toHaveLength(1);
await expect(mail.send({ to: "real@example.com", subject: "no" })).rejects.toThrow("SANDBOX");
});