x
This commit is contained in:
1 parent
9237c0eded
commit
f5893c3fad
16 files changed
+1230
-114
No files matched your search
@@ -34,10 +34,42 @@ const websiteBlockTypes = [
|
||||
"CONTACT_FORM",
|
||||
"HERO_V2",
|
||||
"USP_BAR",
|
||||
"HERO_MINIMAL",
|
||||
"HERO_SPLIT_MINIMAL",
|
||||
"HERO_VIDEO_MINIMAL",
|
||||
"BANNER_MINIMAL",
|
||||
"ANNOUNCEMENT_BAR_MINIMAL",
|
||||
"USP_MINIMAL",
|
||||
"CUSTOM",
|
||||
] as const;
|
||||
|
||||
const minimalBlockTypes = [
|
||||
"HERO_MINIMAL",
|
||||
"HERO_SPLIT_MINIMAL",
|
||||
"HERO_VIDEO_MINIMAL",
|
||||
"BANNER_MINIMAL",
|
||||
"ANNOUNCEMENT_BAR_MINIMAL",
|
||||
"USP_MINIMAL",
|
||||
] as const;
|
||||
|
||||
describe("Page Builder block contracts", () => {
|
||||
test("reusable payload examples do not carry another tenant's identity", () => {
|
||||
for (const type of websiteBlockTypes) {
|
||||
const schema = getPageBlockSchema(type);
|
||||
const examples = JSON.stringify({
|
||||
minimalPayload: schema.minimalPayload,
|
||||
recommendedPayload: schema.recommendedPayload,
|
||||
legacyExample: schema.legacyExample,
|
||||
});
|
||||
|
||||
expect(examples).not.toMatch(/homaroma|ddc|kitizone|pkh|@homaroma|hello@homaroma\.shop/i);
|
||||
}
|
||||
|
||||
const contact = getPageBlockSchema("CONTACT_INFO");
|
||||
expect(contact.warnings).toContain("Replace sample contact details with the active tenant's verified address, email, LINE ID, and business hours before writing.");
|
||||
expect(contact.recommendedPayload).toMatchObject({ email: "hello@example.com", line: "@your-line-id" });
|
||||
});
|
||||
|
||||
for (const type of websiteBlockTypes) {
|
||||
test(`${type} exposes a valid recommended payload`, () => {
|
||||
const schema = getPageBlockSchema(type);
|
||||
@@ -48,6 +80,48 @@ describe("Page Builder block contracts", () => {
|
||||
});
|
||||
}
|
||||
|
||||
test("minimal blocks accept backend-valid payloads with optional copy omitted", () => {
|
||||
expect(validatePayloadAgainstMetadata("HERO_MINIMAL", { imageUrl: "/hero.jpg", title: { th: "Hero" } }).valid).toBe(true);
|
||||
expect(validatePayloadAgainstMetadata("HERO_SPLIT_MINIMAL", { imageUrl: "/hero.jpg", title: { th: "Hero" } }).valid).toBe(true);
|
||||
expect(validatePayloadAgainstMetadata("HERO_VIDEO_MINIMAL", { videoUrl: "/hero.mp4" }).valid).toBe(true);
|
||||
expect(validatePayloadAgainstMetadata("BANNER_MINIMAL", { title: { th: "Banner" } }).valid).toBe(true);
|
||||
expect(validatePayloadAgainstMetadata("ANNOUNCEMENT_BAR_MINIMAL", { slides: [{ th: "Announcement" }] }).valid).toBe(true);
|
||||
expect(validatePayloadAgainstMetadata("USP_MINIMAL", { items: [{ th: "Benefit" }] }).valid).toBe(true);
|
||||
});
|
||||
|
||||
test("minimal blocks reject missing required fields and malformed items", () => {
|
||||
for (const type of minimalBlockTypes) {
|
||||
expect(validatePayloadAgainstMetadata(type, {}).valid).toBe(false);
|
||||
}
|
||||
expect(validatePayloadAgainstMetadata("USP_MINIMAL", { items: [{ icon: "leaf", title: { th: "Benefit" } }] }).valid).toBe(false);
|
||||
expect(validatePayloadAgainstMetadata("ANNOUNCEMENT_BAR_MINIMAL", { slides: [] }).valid).toBe(false);
|
||||
});
|
||||
|
||||
test("minimal blocks pass page creation and section addition preflight", async () => {
|
||||
const calls: Array<{ url: string; payload: any }> = [];
|
||||
const api = {
|
||||
post: async (url: string, payload: any) => {
|
||||
calls.push({ url, payload });
|
||||
return { data: { pageId: 50, sectionId: 120, section: { id: 120, type: payload.section?.type ?? payload.type } } };
|
||||
},
|
||||
} as any;
|
||||
|
||||
for (const type of minimalBlockTypes) {
|
||||
const payload = getPageBlockSchema(type).recommendedPayload;
|
||||
const create = await handleSectionTool(api, "create_page_with_section", {
|
||||
title: "Minimal page", slug: `minimal-${type.toLowerCase()}`, type, payload,
|
||||
});
|
||||
const add = await handleSectionTool(api, "add_page_section", { pageId: 50, type, payload });
|
||||
|
||||
expect(create && "isError" in create ? create.isError : false).toBe(false);
|
||||
expect(add && "isError" in add ? add.isError : false).toBe(false);
|
||||
}
|
||||
|
||||
expect(calls).toHaveLength(minimalBlockTypes.length * 2);
|
||||
expect(calls.filter((call) => call.url === "/pages/with-section")).toHaveLength(minimalBlockTypes.length);
|
||||
expect(calls.filter((call) => call.url === "/pages/50/sections")).toHaveLength(minimalBlockTypes.length);
|
||||
});
|
||||
|
||||
test("HERO_V2 rejects the legacy empty payload before backend writes", () => {
|
||||
const result = validatePayloadAgainstMetadata("HERO_V2", {});
|
||||
|
||||
|
||||
Reference in new issue
Block a user