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
82 lines
3.5 KiB
TypeScript
82 lines
3.5 KiB
TypeScript
import { describe, expect, it } from "vitest";
|
|
import { emptySku, emptySkuVariant, setOptionValues, type SkuDraft, type SkuVariantDraft } from "./catalogSetup";
|
|
|
|
// Option value chips on the product page (simplify-product-setup): editing an option's values adds the
|
|
// missing combinations and removes rows whose value was taken away, except locked (sold) rows.
|
|
|
|
const row = (options: string[], over: Partial<SkuVariantDraft> = {}): SkuVariantDraft => ({ ...emptySkuVariant(), options, ...over });
|
|
const bra = (over: Partial<SkuDraft> = {}): SkuDraft => ({
|
|
...emptySku(),
|
|
code: "YELLOW-002",
|
|
name: "Nursing Bra",
|
|
optionNames: ["Size"],
|
|
optionValues: ["M"],
|
|
variants: [row(["M"], { variant: "Size", variantName: "M", code: "YELLOW-002-M" })],
|
|
...over,
|
|
});
|
|
const values = (sku: SkuDraft) => sku.variants.map((v) => v.options.join("/"));
|
|
|
|
describe("setOptionValues", () => {
|
|
it("adding a value adds its row with a suggested code", () => {
|
|
const next = setOptionValues(bra(), 0, ["M", "L"], new Set());
|
|
expect(values(next)).toEqual(["M", "L"]);
|
|
expect(next.optionValues[0]).toBe("M, L");
|
|
expect(next.variants[1].code).toBe("YELLOW-002-L");
|
|
});
|
|
|
|
it("removing a value removes its unsaved row", () => {
|
|
const sku = setOptionValues(bra(), 0, ["M", "L"], new Set());
|
|
expect(values(setOptionValues(sku, 0, ["L"], new Set()))).toEqual(["L"]);
|
|
});
|
|
|
|
it("removing a value keeps a locked saved row", () => {
|
|
const sku = bra({ optionValues: ["M, L"], variants: [row(["M"], { id: 7 }), row(["L"])] });
|
|
expect(values(setOptionValues(sku, 0, ["L"], new Set([7])))).toEqual(["M", "L"]);
|
|
});
|
|
|
|
it("matches removed values ignoring case", () => {
|
|
const sku = bra({ optionValues: ["M, L"], variants: [row(["M"]), row(["l"])] });
|
|
expect(values(setOptionValues(sku, 0, ["M"], new Set()))).toEqual(["M"]);
|
|
});
|
|
|
|
it("a value added on a second option keeps the first rows' typed fields", () => {
|
|
const sku = bra({
|
|
optionNames: ["Size", "Colour"],
|
|
optionValues: ["M", "Black"],
|
|
variants: [row(["M", "Black"], { weight: "0.3" })],
|
|
});
|
|
const next = setOptionValues(sku, 1, ["Black", "Nude"], new Set());
|
|
expect(values(next)).toEqual(["M/Black", "M/Nude"]);
|
|
expect(next.variants[0].weight).toBe("0.3");
|
|
});
|
|
|
|
it("a second option's first value fills the existing rows instead of adding new ones", () => {
|
|
const sku = bra({
|
|
optionNames: ["Size", "Colour"],
|
|
optionValues: ["M, L", ""],
|
|
variants: [row(["M", ""], { weight: "0.3" }), row(["L", ""], { weight: "0.4" })],
|
|
});
|
|
const next = setOptionValues(sku, 1, ["Black"], new Set());
|
|
expect(values(next)).toEqual(["M/Black", "L/Black"]);
|
|
expect(next.variants.map((v) => v.weight)).toEqual(["0.3", "0.4"]);
|
|
});
|
|
|
|
it("clearing every value of one option blanks it on the rows and keeps the rest", () => {
|
|
const sku = bra({
|
|
optionNames: ["Size", "Colour"],
|
|
optionValues: ["M", "Black, Nude"],
|
|
variants: [row(["M", "Black"], { weight: "0.3" }), row(["M", "Nude"], { weight: "0.3" })],
|
|
});
|
|
const next = setOptionValues(sku, 1, [], new Set());
|
|
expect(values(next)).toEqual(["M/", "M/"]);
|
|
expect(next.variants.map((v) => v.weight)).toEqual(["0.3", "0.3"]);
|
|
});
|
|
|
|
it("removing every value leaves one empty row, never none", () => {
|
|
const next = setOptionValues(bra(), 0, [], new Set());
|
|
expect(next.variants).toHaveLength(1);
|
|
expect(next.variants[0].options).toEqual([""]);
|
|
expect(next.optionValues[0]).toBe("");
|
|
});
|
|
});
|