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 }) => `${name}`, }); 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"); });