test(feishu): type tool harness fixtures

This commit is contained in:
Ayaan Zaidi
2026-03-27 11:53:58 +05:30
parent 1042710e3b
commit 6ad50ce474
4 changed files with 111 additions and 94 deletions

View File

@@ -1,5 +1,23 @@
import type * as Lark from "@larksuiteoapi/node-sdk";
import { describe, expect, it, vi } from "vitest";
import { BATCH_SIZE, insertBlocksInBatches } from "./docx-batch-insert.js";
import type { FeishuDocxBlock } from "./docx-types.js";
type DocxDescendantCreate = Lark.Client["docx"]["documentBlockDescendant"]["create"];
type DocxDescendantCreateParams = Parameters<DocxDescendantCreate>[0];
type DocxDescendantCreateResponse = Awaited<ReturnType<DocxDescendantCreate>>;
function createDocxDescendantClient(
create: (params: DocxDescendantCreateParams) => Promise<DocxDescendantCreateResponse>,
): Pick<Lark.Client, "docx"> {
return {
docx: {
documentBlockDescendant: {
create,
},
},
};
}
function createCountingIterable<T>(values: T[]) {
let iterations = 0;
@@ -28,18 +46,12 @@ describe("insertBlocksInBatches", () => {
children: data.children_id.map((id) => ({ block_id: id })),
},
}));
const client = {
docx: {
documentBlockDescendant: {
create: createMock,
},
},
} as any;
const client = createDocxDescendantClient(createMock);
const result = await insertBlocksInBatches(
client,
"doc_1",
counting.values as any[],
Array.from(counting.values),
blocks.map((block) => block.block_id),
);
@@ -63,21 +75,15 @@ describe("insertBlocksInBatches", () => {
},
}),
);
const client = {
docx: {
documentBlockDescendant: {
create: createMock,
},
},
} as any;
const blocks = [
const client = createDocxDescendantClient(createMock);
const blocks: FeishuDocxBlock[] = [
{ block_id: "root_a", block_type: 1, children: ["child_a"] },
{ block_id: "child_a", block_type: 2 },
{ block_id: "root_b", block_type: 1, children: ["child_b"] },
{ block_id: "child_b", block_type: 2 },
];
await insertBlocksInBatches(client, "doc_1", blocks as any[], ["root_a", "root_b"]);
await insertBlocksInBatches(client, "doc_1", blocks, ["root_a", "root_b"]);
expect(createMock).toHaveBeenCalledTimes(1);
expect(createMock.mock.calls[0]?.[0]?.data.children_id).toEqual(["root_a", "root_b"]);