feat(catalog): add saved packages, preview and bulk price editing
This commit is contained in:
1 parent
867113d5d4
commit
047cd9f3dd
48 files changed
+7712
No files matched your search
@@ -0,0 +1,127 @@
|
||||
import { expect, it } from "vitest";
|
||||
import type {
|
||||
PackageOffer,
|
||||
PackageSnapshot,
|
||||
} from "@/features/catalog/domain/packages";
|
||||
import {
|
||||
packageBulkPrices,
|
||||
packageChanges,
|
||||
packagePublicationIsCurrent,
|
||||
} from "./package-editor-helpers";
|
||||
|
||||
const offer: PackageOffer = {
|
||||
id: 1,
|
||||
pageId: 10,
|
||||
catalogName: "Chair",
|
||||
itemIds: "42",
|
||||
costCredits: 100,
|
||||
costPoints: 20,
|
||||
pointsType: 5,
|
||||
amount: 1,
|
||||
};
|
||||
it("previews only selected draft offers and preserves furniture references without mutating the snapshot", () => {
|
||||
const rows = [offer, { ...offer, id: 2, costCredits: 200 }];
|
||||
const result = packageBulkPrices(rows, [1], {
|
||||
costCredits: { mode: "percent", value: -25 },
|
||||
});
|
||||
expect(result).toEqual([
|
||||
{ before: offer, after: { ...offer, costCredits: 75 } },
|
||||
]);
|
||||
expect(rows[0].costCredits).toBe(100);
|
||||
expect(rows[1].costCredits).toBe(200);
|
||||
expect(result[0].after.itemIds).toBe("42");
|
||||
expect(result[0].after.pageId).toBe(10);
|
||||
});
|
||||
it("supports absolute and additive prices, rejecting invalid selection and negative results", () => {
|
||||
expect(
|
||||
packageBulkPrices([offer], [1], {
|
||||
costPoints: { mode: "set", value: 7 },
|
||||
})[0].after.costPoints,
|
||||
).toBe(7);
|
||||
expect(
|
||||
packageBulkPrices([offer], [1], {
|
||||
costCredits: { mode: "add", value: 5 },
|
||||
})[0].after.costCredits,
|
||||
).toBe(105);
|
||||
expect(() =>
|
||||
packageBulkPrices([offer], [1], {
|
||||
costCredits: { mode: "add", value: -101 },
|
||||
}),
|
||||
).toThrow();
|
||||
expect(() =>
|
||||
packageBulkPrices([offer], [2], { costCredits: { mode: "set", value: 1 } }),
|
||||
).toThrow();
|
||||
expect(() =>
|
||||
packageBulkPrices([offer], [], { costCredits: { mode: "set", value: 1 } }),
|
||||
).toThrow();
|
||||
expect(() =>
|
||||
packageBulkPrices([offer], [1, 1], {
|
||||
costCredits: { mode: "set", value: 1 },
|
||||
}),
|
||||
).toThrow();
|
||||
});
|
||||
it("binds publication eligibility to the saved version and rejects dirty or conflicting reviews", () => {
|
||||
const saved = { status: "draft" as const, version: 3 };
|
||||
const review = {
|
||||
version: 3,
|
||||
fingerprint: "a".repeat(64),
|
||||
changedPages: 1,
|
||||
changedOffers: 1,
|
||||
conflicts: [],
|
||||
};
|
||||
expect(packagePublicationIsCurrent(saved, review, false)).toBe(true);
|
||||
expect(
|
||||
packagePublicationIsCurrent(saved, { ...review, version: 4 }, false),
|
||||
).toBe(false);
|
||||
expect(packagePublicationIsCurrent(saved, review, true)).toBe(false);
|
||||
expect(
|
||||
packagePublicationIsCurrent(
|
||||
saved,
|
||||
{ ...review, conflicts: ["Changed live data"] },
|
||||
false,
|
||||
),
|
||||
).toBe(false);
|
||||
expect(
|
||||
packagePublicationIsCurrent(
|
||||
{ ...saved, status: "published" },
|
||||
review,
|
||||
false,
|
||||
),
|
||||
).toBe(false);
|
||||
});
|
||||
it("shows precise category and offer changes against the original snapshot", () => {
|
||||
const original: PackageSnapshot = {
|
||||
pages: [
|
||||
{
|
||||
id: 10,
|
||||
parentId: -1,
|
||||
caption: "Rooms",
|
||||
enabled: "1",
|
||||
visible: "1",
|
||||
iconImage: 1,
|
||||
minRank: 1,
|
||||
clubOnly: "0",
|
||||
vipOnly: "0",
|
||||
orderNum: 1,
|
||||
pageLayout: "default_3x3",
|
||||
},
|
||||
],
|
||||
offers: [offer],
|
||||
};
|
||||
const draft: PackageSnapshot = {
|
||||
pages: [{ ...original.pages[0], caption: "Chairs", visible: "0" }],
|
||||
offers: [{ ...offer, costCredits: 50 }],
|
||||
};
|
||||
expect(
|
||||
packageChanges(original, draft).map((row) => [
|
||||
row.field,
|
||||
row.before,
|
||||
row.after,
|
||||
]),
|
||||
).toEqual([
|
||||
["caption", "Rooms", "Chairs"],
|
||||
["visible", "1", "0"],
|
||||
["costCredits", "100", "50"],
|
||||
]);
|
||||
expect(packageChanges(original, original)).toEqual([]);
|
||||
});
|
||||
Reference in new issue
Block a user