refactor(catalog): unify commands and embed guarded catalog workspace
This commit is contained in:
1 parent
16f35568f5
commit
193b6686a9
57 files changed
+3268
-728
No files matched your search
@@ -1,5 +1,10 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
|
||||
const commands = vi.hoisted(() => ({
|
||||
updatePageCommand: vi.fn(),
|
||||
deletePageCommand: vi.fn(),
|
||||
}));
|
||||
vi.mock("@/features/catalog/server/page-commands", () => commands);
|
||||
const insertValues = vi.hoisted(() => vi.fn());
|
||||
const selectLimit = vi.hoisted(() => vi.fn());
|
||||
const updateSetData = vi.hoisted(() => vi.fn());
|
||||
@@ -168,22 +173,11 @@ describe("createPage", () => {
|
||||
});
|
||||
|
||||
describe("movePage", () => {
|
||||
it("throws on circular hierarchy", async () => {
|
||||
selectLimit.mockResolvedValue([{ parentId: 1 }]);
|
||||
await expect(movePage(1, 2)).rejects.toThrow("circular hierarchy");
|
||||
});
|
||||
|
||||
it("allows valid move to root", async () => {
|
||||
updateWhere.mockResolvedValue([{ affectedRows: 1 }]);
|
||||
await movePage(1, 0);
|
||||
expect(updateSetData.mock.calls[0][0]).toEqual({ parentId: 0 });
|
||||
});
|
||||
|
||||
it("allows valid move to other parent", async () => {
|
||||
selectLimit.mockResolvedValue([{ parentId: 0 }]);
|
||||
updateWhere.mockResolvedValue([{ affectedRows: 1 }]);
|
||||
it("uses the shared structural command", async () => {
|
||||
await movePage(1, 2);
|
||||
expect(updateSetData.mock.calls[0][0]).toEqual({ parentId: 2 });
|
||||
expect(commands.updatePageCommand).toHaveBeenCalledWith("normal", 1, {
|
||||
parentId: 2,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -208,13 +202,19 @@ describe("getAncestors", () => {
|
||||
});
|
||||
|
||||
describe("deletePage", () => {
|
||||
it("reparent mode moves children to parent", async () => {
|
||||
selectLimit.mockResolvedValue([{ parentId: 1 }]);
|
||||
updateWhere.mockResolvedValue([{ affectedRows: 2 }]);
|
||||
deleteWhere.mockResolvedValue([{ affectedRows: 1 }]);
|
||||
|
||||
const result = await deletePage(5, "reparent");
|
||||
expect(result).toEqual({ deletedPages: 1, movedChildren: 2 });
|
||||
expect(updateSetData.mock.calls[0][0]).toEqual({ parentId: 1 });
|
||||
it("uses the shared transactional delete", async () => {
|
||||
commands.deletePageCommand.mockResolvedValue({
|
||||
deletedPages: 1,
|
||||
movedChildren: 2,
|
||||
});
|
||||
expect(await deletePage(5, "reparent")).toEqual({
|
||||
deletedPages: 1,
|
||||
movedChildren: 2,
|
||||
});
|
||||
expect(commands.deletePageCommand).toHaveBeenCalledWith(
|
||||
"normal",
|
||||
5,
|
||||
"reparent",
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user