Files
WRNexusJS/packages/email-renderer/test/create.test.ts
T
Clintchiz 16d804e16f
Quality / quality (ubuntu-latest) (push) Failing after 1s
Quality / quality (windows-latest) (push) Canceled after 0s
Centralize palette block creation in the email framework
2026-09-05 18:59:28 +05:30

19 lines
1.1 KiB
TypeScript

import { expect, test } from "bun:test";
import { createEmailBlock } from "../src/create.ts";
import { emailCoreBlocks } from "../src/blocks.ts";
test("palette factory produces schema-valid independent blocks with injected IDs and time", () => {
let sequence = 0;
for (const definition of emailCoreBlocks.filter(block => /^(content|commerce)\./.test(block.manifest.type))) {
const context = { id: () => `node-${++sequence}`, now: Date.parse("2026-09-05T00:00:00Z") };
const first = createEmailBlock(definition.manifest.type, context), second = createEmailBlock(definition.manifest.type, context);
expect(definition.manifest.props.parse(first.props).ok).toBe(true);
expect(first.id).not.toBe(second.id);
expect(first.props).toEqual(second.props);
expect(first.props).not.toBe(second.props);
expect(first.version).toBe(definition.manifest.version);
if (first.type === "content.countdown") expect(first.props.deadline).toBe("2026-09-06T00:00:00.000Z");
}
expect(() => createEmailBlock("untrusted.block", { id: () => "id" })).toThrow();
});