Backend modules from tastefully 8bd93d15: core-libs, core-session, api-gateway, mobile-api, services-auth, services-system, services-counter, services-member, services-log, services-email. solvway-admin-portal from babyboo f64d096ea, solvway-customer-portal from tastefully 8bd93d15. Copied as tracked files only. Literal secrets replaced with environment placeholders: - services-email: SMTP_PASSWORD, MAILGUN_API_KEY, SENDGRID_API_KEY, MAILJET_API_KEY, MAILJET_SECRET_KEY (optional, empty default) - services-system: JUMIO_TOKEN, JUMIO_SECRET (optional) - services-auth: USER_AUTH_API_SECRET (required); commented JWT secret removed - core-libs: JWT_TOKEN default removed (required), XXL_JOB_TOKEN default removed, ipgeolocation key read from IPGEOLOCATION_API_KEY - services-system EkycAppConfig: commented Jumio credentials removed Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfj5akPxyikzGc2iAHM
78 lines
3.3 KiB
TypeScript
78 lines
3.3 KiB
TypeScript
import { describe, it, expect } from "vitest";
|
|
import { BLOCK_LABELS, BLOCK_TYPES, emptyBlock, emptyPage, moveBlock, pageAddress, pageBody, withTitle } from "./cmsPages";
|
|
|
|
// add-cms-pages: pure helpers behind the page editor.
|
|
|
|
describe("pageAddress", () => {
|
|
it("gives the four help pages their short address and everything else /pages/{slug}", () => {
|
|
expect(pageAddress("help")).toBe("/help");
|
|
expect(pageAddress("contact")).toBe("/contact");
|
|
expect(pageAddress("delivery-returns")).toBe("/delivery-returns");
|
|
expect(pageAddress("warranty")).toBe("/warranty");
|
|
expect(pageAddress("about-us")).toBe("/pages/about-us");
|
|
});
|
|
});
|
|
|
|
describe("withTitle", () => {
|
|
it("fills the slug from the title until the slug was edited by hand", () => {
|
|
const draft = withTitle(emptyPage(), "About Us & Our Story!");
|
|
expect(draft.slug).toBe("about-us-our-story");
|
|
const edited = { ...draft, slug: "our-story", slugTouched: true };
|
|
expect(withTitle(edited, "Something else").slug).toBe("our-story");
|
|
});
|
|
});
|
|
|
|
describe("blocks", () => {
|
|
// localise-admin-content: labels are message codes, translated with t() where they render.
|
|
it("labels all seven block types (FORM added by add-cms-forms)", () => {
|
|
expect(BLOCK_TYPES).toEqual(["HERO", "RICH_TEXT", "IMAGE_TEXT", "FEATURED_PRODUCTS", "COLLECTION_LIST", "FAQ", "FORM"]);
|
|
expect(BLOCK_LABELS).toEqual({
|
|
HERO: "CmsBlockHero",
|
|
RICH_TEXT: "CmsBlockRichText",
|
|
IMAGE_TEXT: "CmsBlockImageText",
|
|
FEATURED_PRODUCTS: "CmsBlockFeaturedProducts",
|
|
COLLECTION_LIST: "CmsBlockCollectionList",
|
|
FAQ: "CmsBlockFaq",
|
|
FORM: "CmsBlockForm",
|
|
});
|
|
});
|
|
|
|
it("creates empty blocks with sensible defaults", () => {
|
|
expect(emptyBlock("FAQ")).toEqual({ type: "FAQ", heading: "", items: [{ question: "", answer: "" }] });
|
|
expect(emptyBlock("IMAGE_TEXT")).toMatchObject({ type: "IMAGE_TEXT", imagePosition: "LEFT", imageUrl: "", html: "" });
|
|
expect(emptyBlock("FEATURED_PRODUCTS")).toMatchObject({ type: "FEATURED_PRODUCTS", collectionId: null, limit: 8 });
|
|
expect(emptyBlock("COLLECTION_LIST")).toMatchObject({ type: "COLLECTION_LIST", collectionIds: [] });
|
|
});
|
|
|
|
it("moves a block up or down and does nothing at either end", () => {
|
|
const blocks = [emptyBlock("HERO"), emptyBlock("RICH_TEXT"), emptyBlock("FAQ")];
|
|
expect(moveBlock(blocks, 1, -1).map((b) => b.type)).toEqual(["RICH_TEXT", "HERO", "FAQ"]);
|
|
expect(moveBlock(blocks, 1, 1).map((b) => b.type)).toEqual(["HERO", "FAQ", "RICH_TEXT"]);
|
|
expect(moveBlock(blocks, 0, -1)).toEqual(blocks);
|
|
expect(moveBlock(blocks, 2, 1)).toEqual(blocks);
|
|
expect(blocks.map((b) => b.type)).toEqual(["HERO", "RICH_TEXT", "FAQ"]);
|
|
});
|
|
});
|
|
|
|
describe("pageBody", () => {
|
|
it("sends only the saved fields, trimmed, with blank optional texts dropped", () => {
|
|
const body = pageBody({
|
|
...emptyPage(),
|
|
id: 4,
|
|
title: " About us ",
|
|
slug: "about-us",
|
|
metaDescription: " ",
|
|
status: "N",
|
|
blocks: [{ ...emptyBlock("HERO"), imageUrl: "https://cdn/x.png", heading: " Hi ", text: "", buttonLabel: "", buttonUrl: "" }],
|
|
});
|
|
expect(body).toEqual({
|
|
id: 4,
|
|
title: "About us",
|
|
slug: "about-us",
|
|
metaDescription: null,
|
|
status: "N",
|
|
blocks: [{ type: "HERO", imageUrl: "https://cdn/x.png", heading: "Hi" }],
|
|
});
|
|
});
|
|
});
|