mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-05 13:21:43 +00:00
feat(feishu): add chat info/member tool (openclaw#14674)
* feat(feishu): add chat members/info tool support * Feishu: harden chat tool schema and coverage --------- Co-authored-by: Nereo <nereo@Nereos-Mac-mini.local> Co-authored-by: Tak Hoffman <781889+Takhoffman@users.noreply.github.com>
This commit is contained in:
89
extensions/feishu/src/chat.test.ts
Normal file
89
extensions/feishu/src/chat.test.ts
Normal file
@@ -0,0 +1,89 @@
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { registerFeishuChatTools } from "./chat.js";
|
||||
|
||||
const createFeishuClientMock = vi.hoisted(() => vi.fn());
|
||||
|
||||
vi.mock("./client.js", () => ({
|
||||
createFeishuClient: createFeishuClientMock,
|
||||
}));
|
||||
|
||||
describe("registerFeishuChatTools", () => {
|
||||
const chatGetMock = vi.hoisted(() => vi.fn());
|
||||
const chatMembersGetMock = vi.hoisted(() => vi.fn());
|
||||
|
||||
beforeEach(() => {
|
||||
vi.clearAllMocks();
|
||||
createFeishuClientMock.mockReturnValue({
|
||||
im: {
|
||||
chat: { get: chatGetMock },
|
||||
chatMembers: { get: chatMembersGetMock },
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
it("registers feishu_chat and handles info/members actions", async () => {
|
||||
const registerTool = vi.fn();
|
||||
registerFeishuChatTools({
|
||||
config: {
|
||||
channels: {
|
||||
feishu: {
|
||||
enabled: true,
|
||||
appId: "app_id",
|
||||
appSecret: "app_secret",
|
||||
tools: { chat: true },
|
||||
},
|
||||
},
|
||||
} as any,
|
||||
logger: { debug: vi.fn(), info: vi.fn() } as any,
|
||||
registerTool,
|
||||
} as any);
|
||||
|
||||
expect(registerTool).toHaveBeenCalledTimes(1);
|
||||
const tool = registerTool.mock.calls[0]?.[0];
|
||||
expect(tool?.name).toBe("feishu_chat");
|
||||
|
||||
chatGetMock.mockResolvedValueOnce({
|
||||
code: 0,
|
||||
data: { name: "group name", user_count: 3 },
|
||||
});
|
||||
const infoResult = await tool.execute("tc_1", { action: "info", chat_id: "oc_1" });
|
||||
expect(infoResult.details).toEqual(
|
||||
expect.objectContaining({ chat_id: "oc_1", name: "group name", user_count: 3 }),
|
||||
);
|
||||
|
||||
chatMembersGetMock.mockResolvedValueOnce({
|
||||
code: 0,
|
||||
data: {
|
||||
has_more: false,
|
||||
page_token: "",
|
||||
items: [{ member_id: "ou_1", name: "member1", member_id_type: "open_id" }],
|
||||
},
|
||||
});
|
||||
const membersResult = await tool.execute("tc_2", { action: "members", chat_id: "oc_1" });
|
||||
expect(membersResult.details).toEqual(
|
||||
expect.objectContaining({
|
||||
chat_id: "oc_1",
|
||||
members: [expect.objectContaining({ member_id: "ou_1", name: "member1" })],
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
it("skips registration when chat tool is disabled", () => {
|
||||
const registerTool = vi.fn();
|
||||
registerFeishuChatTools({
|
||||
config: {
|
||||
channels: {
|
||||
feishu: {
|
||||
enabled: true,
|
||||
appId: "app_id",
|
||||
appSecret: "app_secret",
|
||||
tools: { chat: false },
|
||||
},
|
||||
},
|
||||
} as any,
|
||||
logger: { debug: vi.fn(), info: vi.fn() } as any,
|
||||
registerTool,
|
||||
} as any);
|
||||
expect(registerTool).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user