feat: add application productivity foundations
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
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");
|
||||
});
|
||||
Reference in New Issue
Block a user