mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-10 00:31:22 +00:00
fix(feishu): restore tsgo test typing
This commit is contained in:
@@ -3,20 +3,19 @@ import { describe, expect, it, vi } from "vitest";
|
||||
import { BATCH_SIZE, insertBlocksInBatches } from "./docx-batch-insert.js";
|
||||
import type { FeishuDocxBlock } from "./docx-types.js";
|
||||
|
||||
type InsertBlocksClient = Parameters<typeof insertBlocksInBatches>[0];
|
||||
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"> {
|
||||
function createDocxDescendantClient(create: DocxDescendantCreate): InsertBlocksClient {
|
||||
return {
|
||||
docx: {
|
||||
documentBlockDescendant: {
|
||||
create,
|
||||
},
|
||||
},
|
||||
};
|
||||
} as InsertBlocksClient;
|
||||
}
|
||||
|
||||
function createCountingIterable<T>(values: T[]) {
|
||||
@@ -40,13 +39,18 @@ describe("insertBlocksInBatches", () => {
|
||||
block_type: 2,
|
||||
}));
|
||||
const counting = createCountingIterable(blocks);
|
||||
const createMock = vi.fn(async ({ data }: { data: { children_id: string[] } }) => ({
|
||||
code: 0,
|
||||
data: {
|
||||
children: data.children_id.map((id) => ({ block_id: id })),
|
||||
},
|
||||
}));
|
||||
const client = createDocxDescendantClient(createMock);
|
||||
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 client = createDocxDescendantClient((params) => createMock(params));
|
||||
|
||||
const result = await insertBlocksInBatches(
|
||||
client,
|
||||
@@ -64,18 +68,17 @@ describe("insertBlocksInBatches", () => {
|
||||
|
||||
it("keeps nested descendants grouped with their root blocks", async () => {
|
||||
const createMock = vi.fn(
|
||||
async ({
|
||||
data,
|
||||
}: {
|
||||
data: { children_id: string[]; descendants: Array<{ block_id: string }> };
|
||||
}) => ({
|
||||
async (params?: DocxDescendantCreateParams): Promise<DocxDescendantCreateResponse> => ({
|
||||
code: 0,
|
||||
data: {
|
||||
children: data.children_id.map((id) => ({ block_id: id })),
|
||||
children: (params?.data?.children_id ?? []).map((id) => ({
|
||||
block_id: id,
|
||||
block_type: 2,
|
||||
})),
|
||||
},
|
||||
}),
|
||||
);
|
||||
const client = createDocxDescendantClient(createMock);
|
||||
const client = createDocxDescendantClient((params) => createMock(params));
|
||||
const blocks: FeishuDocxBlock[] = [
|
||||
{ block_id: "root_a", block_type: 1, children: ["child_a"] },
|
||||
{ block_id: "child_a", block_type: 2 },
|
||||
@@ -88,9 +91,7 @@ describe("insertBlocksInBatches", () => {
|
||||
expect(createMock).toHaveBeenCalledTimes(1);
|
||||
expect(createMock.mock.calls[0]?.[0]?.data.children_id).toEqual(["root_a", "root_b"]);
|
||||
expect(
|
||||
createMock.mock.calls[0]?.[0]?.data.descendants.map(
|
||||
(block: { block_id: string }) => block.block_id,
|
||||
),
|
||||
createMock.mock.calls[0]?.[0]?.data.descendants.map((block) => block.block_id ?? ""),
|
||||
).toEqual(["root_a", "child_a", "root_b", "child_b"]);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user