test: share feishu docx batch fixture

This commit is contained in:
Peter Steinberger
2026-04-20 21:25:28 +01:00
parent 1a4917c3d3
commit 03b10e97d3

View File

@@ -31,6 +31,20 @@ function createCountingIterable<T>(values: T[]) {
};
}
function createSuccessfulDocxDescendantCreateMock() {
return vi.fn(
async (params?: DocxDescendantCreateParams): Promise<DocxDescendantCreateResponse> => ({
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<DocxDescendantCreateResponse> => ({
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<DocxDescendantCreateResponse> => ({
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"] },