mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-23 23:22:32 +00:00
refactor: drop heavy channel outbound test imports
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { slackOutbound } from "../../../test/channel-outbounds.js";
|
||||
import type { ChannelOutboundAdapter } from "../../channels/plugins/types.js";
|
||||
import type { CliDeps } from "../../cli/outbound-send-deps.js";
|
||||
import type { OpenClawConfig } from "../../config/config.js";
|
||||
import { setActivePluginRegistry } from "../../plugins/runtime.js";
|
||||
@@ -10,6 +10,14 @@ import type { AgentCommandOpts } from "./types.js";
|
||||
type NormalizeParams = Parameters<typeof normalizeAgentCommandReplyPayloads>[0];
|
||||
type RunResult = NormalizeParams["result"];
|
||||
|
||||
const slackOutboundForTest: ChannelOutboundAdapter = {
|
||||
deliveryMode: "direct",
|
||||
sendText: async ({ to, text }) => ({
|
||||
channel: "slack",
|
||||
messageId: `${to}:${text}`,
|
||||
}),
|
||||
};
|
||||
|
||||
const emptyRegistry = createTestRegistry([]);
|
||||
const slackRegistry = createTestRegistry([
|
||||
{
|
||||
@@ -17,7 +25,7 @@ const slackRegistry = createTestRegistry([
|
||||
source: "test",
|
||||
plugin: createOutboundTestPlugin({
|
||||
id: "slack",
|
||||
outbound: slackOutbound,
|
||||
outbound: slackOutboundForTest,
|
||||
messaging: {
|
||||
enableInteractiveReplies: ({ cfg }) =>
|
||||
(cfg.channels?.slack as { capabilities?: { interactiveReplies?: boolean } } | undefined)
|
||||
|
||||
@@ -1,16 +1,7 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { telegramOutbound, whatsappOutbound } from "../../../test/channel-outbounds.js";
|
||||
import type { OpenClawConfig } from "../../config/config.js";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { normalizeIMessageMessagingTarget } from "./normalize/imessage.js";
|
||||
import { looksLikeSignalTargetId, normalizeSignalMessagingTarget } from "./normalize/signal.js";
|
||||
|
||||
function expectWhatsAppTargetResolutionError(result: unknown) {
|
||||
expect(result).toEqual({
|
||||
ok: false,
|
||||
error: expect.any(Error),
|
||||
});
|
||||
}
|
||||
|
||||
describe("imessage target normalization", () => {
|
||||
it("preserves service prefixes for handles", () => {
|
||||
expect(normalizeIMessageMessagingTarget("sms:+1 (555) 222-3333")).toBe("sms:+15552223333");
|
||||
@@ -68,121 +59,3 @@ describe("signal target normalization", () => {
|
||||
expect(looksLikeSignalTargetId("uuid:not-a-uuid")).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe("telegramOutbound.sendPayload", () => {
|
||||
it("sends text payload with buttons", async () => {
|
||||
const sendTelegram = vi.fn(async () => ({ messageId: "m1", chatId: "c1" }));
|
||||
|
||||
const result = await telegramOutbound.sendPayload?.({
|
||||
cfg: {} as OpenClawConfig,
|
||||
to: "telegram:123",
|
||||
text: "ignored",
|
||||
payload: {
|
||||
text: "Hello",
|
||||
channelData: {
|
||||
telegram: {
|
||||
buttons: [[{ text: "Option", callback_data: "/option" }]],
|
||||
},
|
||||
},
|
||||
},
|
||||
deps: { telegram: sendTelegram },
|
||||
});
|
||||
|
||||
expect(sendTelegram).toHaveBeenCalledTimes(1);
|
||||
expect(sendTelegram).toHaveBeenCalledWith(
|
||||
"telegram:123",
|
||||
"Hello",
|
||||
expect.objectContaining({
|
||||
buttons: [[{ text: "Option", callback_data: "/option" }]],
|
||||
textMode: "html",
|
||||
}),
|
||||
);
|
||||
expect(result).toEqual({ channel: "telegram", messageId: "m1", chatId: "c1" });
|
||||
});
|
||||
|
||||
it("sends media payloads and attaches buttons only to first", async () => {
|
||||
const sendTelegram = vi
|
||||
.fn()
|
||||
.mockResolvedValueOnce({ messageId: "m1", chatId: "c1" })
|
||||
.mockResolvedValueOnce({ messageId: "m2", chatId: "c1" });
|
||||
|
||||
const result = await telegramOutbound.sendPayload?.({
|
||||
cfg: {} as OpenClawConfig,
|
||||
to: "telegram:123",
|
||||
text: "ignored",
|
||||
payload: {
|
||||
text: "Caption",
|
||||
mediaUrls: ["https://example.com/a.png", "https://example.com/b.png"],
|
||||
channelData: {
|
||||
telegram: {
|
||||
buttons: [[{ text: "Go", callback_data: "/go" }]],
|
||||
},
|
||||
},
|
||||
},
|
||||
deps: { telegram: sendTelegram },
|
||||
});
|
||||
|
||||
expect(sendTelegram).toHaveBeenCalledTimes(2);
|
||||
expect(sendTelegram).toHaveBeenNthCalledWith(
|
||||
1,
|
||||
"telegram:123",
|
||||
"Caption",
|
||||
expect.objectContaining({
|
||||
mediaUrl: "https://example.com/a.png",
|
||||
buttons: [[{ text: "Go", callback_data: "/go" }]],
|
||||
}),
|
||||
);
|
||||
const secondOpts = sendTelegram.mock.calls[1]?.[2] as { buttons?: unknown } | undefined;
|
||||
expect(sendTelegram).toHaveBeenNthCalledWith(
|
||||
2,
|
||||
"telegram:123",
|
||||
"",
|
||||
expect.objectContaining({
|
||||
mediaUrl: "https://example.com/b.png",
|
||||
}),
|
||||
);
|
||||
expect(secondOpts?.buttons).toBeUndefined();
|
||||
expect(result).toEqual({ channel: "telegram", messageId: "m2", chatId: "c1" });
|
||||
});
|
||||
});
|
||||
|
||||
describe("whatsappOutbound.resolveTarget", () => {
|
||||
it("returns error when no target is provided even with allowFrom", () => {
|
||||
const result = whatsappOutbound.resolveTarget?.({
|
||||
to: undefined,
|
||||
allowFrom: ["+15551234567"],
|
||||
mode: "implicit",
|
||||
});
|
||||
|
||||
expectWhatsAppTargetResolutionError(result);
|
||||
});
|
||||
|
||||
it("returns error when implicit target is not in allowFrom", () => {
|
||||
const result = whatsappOutbound.resolveTarget?.({
|
||||
to: "+15550000000",
|
||||
allowFrom: ["+15551234567"],
|
||||
mode: "implicit",
|
||||
});
|
||||
|
||||
expectWhatsAppTargetResolutionError(result);
|
||||
if (!result || result.ok) {
|
||||
throw new Error("expected WhatsApp target resolution to fail");
|
||||
}
|
||||
expect(result.error.message).toBe(
|
||||
'Target "+15550000000" is not listed in the configured WhatsApp allowFrom policy.',
|
||||
);
|
||||
});
|
||||
|
||||
it("keeps group JID targets even when allowFrom does not contain them", () => {
|
||||
const result = whatsappOutbound.resolveTarget?.({
|
||||
to: "120363401234567890@g.us",
|
||||
allowFrom: ["+15551234567"],
|
||||
mode: "implicit",
|
||||
});
|
||||
|
||||
expect(result).toEqual({
|
||||
ok: true,
|
||||
to: "120363401234567890@g.us",
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user