27 lines
1.5 KiB
TypeScript
27 lines
1.5 KiB
TypeScript
import { describe, expect, it } from "bun:test";
|
|
import { searchDimensions, resolveDimension } from "./tools.js";
|
|
|
|
describe("Dimension Domain - 自定义档案目录", () => {
|
|
it("loads preset and custom dimension catalogs and filters by name", async () => {
|
|
const client = {
|
|
get: async () => new Response(JSON.stringify({ items: [{ id: "org-1" }] })),
|
|
post: async (_path: string, options: any) => new Response(JSON.stringify({ items: [
|
|
options.json.filterBy === "preset==0" ? { id: "dim-custom", name: "项目", code: "DA001", type: "normal", active: true } : { id: "dim-system", name: "法人实体", code: "FRST", type: "legal_entity", active: true },
|
|
] })),
|
|
} as any;
|
|
const result = await searchDimensions(client, "corp-dimension", { name: "项目" });
|
|
expect(result).toHaveLength(1);
|
|
expect(result[0]?.code).toBe("DA001");
|
|
});
|
|
|
|
it("loads dimension items by catalog ID", async () => {
|
|
const client = {
|
|
get: async () => new Response(JSON.stringify({ items: [{ id: "org-2" }] })),
|
|
post: async (path: string) => new Response(JSON.stringify(path.includes("dimensionItems") ? { items: [{ id: "item-1", name: "研发项目", code: "P001", parentId: "", active: true }] } : { items: [{ id: "dim-project", name: "项目", code: "DA001", type: "normal", active: true }] })),
|
|
} as any;
|
|
const result = await resolveDimension(client, "corp-items", "项目");
|
|
expect(result?.dimension.id).toBe("dim-project");
|
|
expect(result?.items[0]?.name).toBe("研发项目");
|
|
});
|
|
});
|