diff --git a/extensions/feishu/src/docx-batch-insert.test.ts b/extensions/feishu/src/docx-batch-insert.test.ts index 2b3f9f39db0..a2177744538 100644 --- a/extensions/feishu/src/docx-batch-insert.test.ts +++ b/extensions/feishu/src/docx-batch-insert.test.ts @@ -31,6 +31,20 @@ function createCountingIterable(values: T[]) { }; } +function createSuccessfulDocxDescendantCreateMock() { + return vi.fn( + async (params?: DocxDescendantCreateParams): Promise => ({ + code: 0, + data: { + children: (params?.data?.children_id ?? []).map((id) => ({ + block_id: id, + block_type: 2, + })), + }, + }), + ); +} + describe("insertBlocksInBatches", () => { it("builds the source block map once for large flat trees", async () => { const blockCount = BATCH_SIZE + 200; @@ -39,17 +53,7 @@ describe("insertBlocksInBatches", () => { block_type: 2, })); const counting = createCountingIterable(blocks); - const createMock = vi.fn( - async (params?: DocxDescendantCreateParams): Promise => ({ - code: 0, - data: { - children: (params?.data?.children_id ?? []).map((id) => ({ - block_id: id, - block_type: 2, - })), - }, - }), - ); + const createMock = createSuccessfulDocxDescendantCreateMock(); const client = createDocxDescendantClient((params) => createMock(params)); const result = await insertBlocksInBatches( @@ -67,17 +71,7 @@ describe("insertBlocksInBatches", () => { }); it("keeps nested descendants grouped with their root blocks", async () => { - const createMock = vi.fn( - async (params?: DocxDescendantCreateParams): Promise => ({ - code: 0, - data: { - children: (params?.data?.children_id ?? []).map((id) => ({ - block_id: id, - block_type: 2, - })), - }, - }), - ); + const createMock = createSuccessfulDocxDescendantCreateMock(); const client = createDocxDescendantClient((params) => createMock(params)); const blocks: FeishuDocxBlock[] = [ { block_id: "root_a", block_type: 1, children: ["child_a"] },