From d7ce507d6f2b6984e976e96cad198d9faec0a57c Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Fri, 8 May 2026 18:35:20 +0100 Subject: [PATCH] test: require feishu outbound fixtures --- extensions/feishu/src/outbound.test.ts | 56 +++++++++++++++++++++++--- 1 file changed, 50 insertions(+), 6 deletions(-) diff --git a/extensions/feishu/src/outbound.test.ts b/extensions/feishu/src/outbound.test.ts index 0c1edf5c9eb..a7aa30593f8 100644 --- a/extensions/feishu/src/outbound.test.ts +++ b/extensions/feishu/src/outbound.test.ts @@ -75,7 +75,48 @@ vi.mock("./comment-reaction.js", () => ({ import { feishuPlugin } from "./channel.js"; import { feishuOutbound } from "./outbound.js"; import { createFeishuSendReceipt } from "./send-result.js"; -const sendText = feishuOutbound.sendText!; + +type FeishuSendText = NonNullable; +type FeishuMessageAdapter = NonNullable; +type FeishuMessageSender = NonNullable; + +function requireFeishuSendText(): FeishuSendText { + const sendText = feishuOutbound.sendText; + if (!sendText) { + throw new Error("Expected Feishu outbound sendText"); + } + return sendText; +} + +function requireFeishuMessageAdapter(): FeishuMessageAdapter { + const adapter = feishuPlugin.message; + if (!adapter) { + throw new Error("Expected Feishu message adapter"); + } + return adapter; +} + +function requireFeishuTextSender( + adapter: FeishuMessageAdapter, +): NonNullable { + const text = adapter.send?.text; + if (!text) { + throw new Error("Expected Feishu message adapter text sender"); + } + return text; +} + +function requireFeishuMediaSender( + adapter: FeishuMessageAdapter, +): NonNullable { + const media = adapter.send?.media; + if (!media) { + throw new Error("Expected Feishu message adapter media sender"); + } + return media; +} + +const sendText = requireFeishuSendText(); const emptyConfig: ClawdbotConfig = {}; const cardRenderConfig: ClawdbotConfig = { channels: { @@ -133,14 +174,17 @@ describe("feishuOutbound.sendText local-image auto-convert", () => { kind: "media", }), }); + const adapter = requireFeishuMessageAdapter(); + const adapterSendText = requireFeishuTextSender(adapter); + const adapterSendMedia = requireFeishuMediaSender(adapter); await expect( verifyChannelMessageAdapterCapabilityProofs({ adapterName: "feishu", - adapter: feishuPlugin.message!, + adapter, proofs: { text: async () => { - const result = await feishuPlugin.message?.send?.text?.({ + const result = await adapterSendText({ cfg: emptyConfig, to: "chat:chat-1", text: "hello", @@ -153,10 +197,10 @@ describe("feishuOutbound.sendText local-image auto-convert", () => { accountId: "default", }), ); - expect(result?.receipt.platformMessageIds).toEqual(["feishu-text-1"]); + expect(result.receipt.platformMessageIds).toEqual(["feishu-text-1"]); }, media: async () => { - const result = await feishuPlugin.message?.send?.media?.({ + const result = await adapterSendMedia({ cfg: emptyConfig, to: "chat:chat-1", text: "", @@ -170,7 +214,7 @@ describe("feishuOutbound.sendText local-image auto-convert", () => { accountId: "default", }), ); - expect(result?.receipt.platformMessageIds).toEqual(["feishu-media-1"]); + expect(result.receipt.platformMessageIds).toEqual(["feishu-media-1"]); }, }, }),