mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 14:00:47 +00:00
test(extensions): split outbound payload contracts
This commit is contained in:
38
extensions/discord/src/outbound-payload.contract.test.ts
Normal file
38
extensions/discord/src/outbound-payload.contract.test.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import {
|
||||
installChannelOutboundPayloadContractSuite,
|
||||
primeChannelOutboundSendMock,
|
||||
type OutboundPayloadHarnessParams,
|
||||
} from "openclaw/plugin-sdk/testing";
|
||||
import { describe, vi } from "vitest";
|
||||
import { discordOutbound } from "./outbound-adapter.js";
|
||||
|
||||
function createDiscordHarness(params: OutboundPayloadHarnessParams) {
|
||||
const sendDiscord = vi.fn();
|
||||
primeChannelOutboundSendMock(
|
||||
sendDiscord,
|
||||
{ messageId: "dc-1", channelId: "123456" },
|
||||
params.sendResults,
|
||||
);
|
||||
const ctx = {
|
||||
cfg: {},
|
||||
to: "channel:123456",
|
||||
text: "",
|
||||
payload: params.payload,
|
||||
deps: {
|
||||
sendDiscord,
|
||||
},
|
||||
};
|
||||
return {
|
||||
run: async () => await discordOutbound.sendPayload!(ctx),
|
||||
sendMock: sendDiscord,
|
||||
to: ctx.to,
|
||||
};
|
||||
}
|
||||
|
||||
describe("Discord outbound payload contract", () => {
|
||||
installChannelOutboundPayloadContractSuite({
|
||||
channel: "discord",
|
||||
chunking: { mode: "passthrough", longTextLength: 3000 },
|
||||
createHarness: createDiscordHarness,
|
||||
});
|
||||
});
|
||||
11
extensions/slack/src/outbound-payload.contract.test.ts
Normal file
11
extensions/slack/src/outbound-payload.contract.test.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
import { installChannelOutboundPayloadContractSuite } from "openclaw/plugin-sdk/testing";
|
||||
import { describe } from "vitest";
|
||||
import { createSlackOutboundPayloadHarness } from "./outbound-payload.test-harness.js";
|
||||
|
||||
describe("Slack outbound payload contract", () => {
|
||||
installChannelOutboundPayloadContractSuite({
|
||||
channel: "slack",
|
||||
chunking: { mode: "passthrough", longTextLength: 5000 },
|
||||
createHarness: createSlackOutboundPayloadHarness,
|
||||
});
|
||||
});
|
||||
34
extensions/whatsapp/src/outbound-payload.contract.test.ts
Normal file
34
extensions/whatsapp/src/outbound-payload.contract.test.ts
Normal file
@@ -0,0 +1,34 @@
|
||||
import {
|
||||
installChannelOutboundPayloadContractSuite,
|
||||
primeChannelOutboundSendMock,
|
||||
type OutboundPayloadHarnessParams,
|
||||
} from "openclaw/plugin-sdk/testing";
|
||||
import { describe, vi } from "vitest";
|
||||
import { whatsappOutbound } from "./outbound-adapter.js";
|
||||
|
||||
function createWhatsAppHarness(params: OutboundPayloadHarnessParams) {
|
||||
const sendWhatsApp = vi.fn();
|
||||
primeChannelOutboundSendMock(sendWhatsApp, { messageId: "wa-1" }, params.sendResults);
|
||||
const ctx = {
|
||||
cfg: {},
|
||||
to: "5511999999999@c.us",
|
||||
text: "",
|
||||
payload: params.payload,
|
||||
deps: {
|
||||
whatsapp: sendWhatsApp,
|
||||
},
|
||||
};
|
||||
return {
|
||||
run: async () => await whatsappOutbound.sendPayload!(ctx),
|
||||
sendMock: sendWhatsApp,
|
||||
to: ctx.to,
|
||||
};
|
||||
}
|
||||
|
||||
describe("WhatsApp outbound payload contract", () => {
|
||||
installChannelOutboundPayloadContractSuite({
|
||||
channel: "whatsapp",
|
||||
chunking: { mode: "split", longTextLength: 5000, maxChunkLength: 4000 },
|
||||
createHarness: createWhatsAppHarness,
|
||||
});
|
||||
});
|
||||
45
extensions/zalo/src/outbound-payload.contract.test.ts
Normal file
45
extensions/zalo/src/outbound-payload.contract.test.ts
Normal file
@@ -0,0 +1,45 @@
|
||||
import {
|
||||
installChannelOutboundPayloadContractSuite,
|
||||
primeChannelOutboundSendMock,
|
||||
type OutboundPayloadHarnessParams,
|
||||
} from "openclaw/plugin-sdk/testing";
|
||||
import { describe, vi } from "vitest";
|
||||
import { zaloPlugin } from "./channel.js";
|
||||
|
||||
const { sendZaloTextMock } = vi.hoisted(() => ({
|
||||
sendZaloTextMock: vi.fn(),
|
||||
}));
|
||||
|
||||
vi.mock("./channel.runtime.js", () => ({
|
||||
sendZaloText: sendZaloTextMock,
|
||||
}));
|
||||
|
||||
function createZaloHarness(params: OutboundPayloadHarnessParams) {
|
||||
const sendZalo = vi.fn();
|
||||
primeChannelOutboundSendMock(sendZalo, { ok: true, messageId: "zl-1" }, params.sendResults);
|
||||
sendZaloTextMock.mockReset().mockImplementation(
|
||||
async (nextCtx: { to: string; text: string; mediaUrl?: string }) =>
|
||||
await sendZalo(nextCtx.to, nextCtx.text, {
|
||||
mediaUrl: nextCtx.mediaUrl,
|
||||
}),
|
||||
);
|
||||
const ctx = {
|
||||
cfg: {},
|
||||
to: "123456789",
|
||||
text: "",
|
||||
payload: params.payload,
|
||||
};
|
||||
return {
|
||||
run: async () => await zaloPlugin.outbound!.sendPayload!(ctx),
|
||||
sendMock: sendZalo,
|
||||
to: ctx.to,
|
||||
};
|
||||
}
|
||||
|
||||
describe("Zalo outbound payload contract", () => {
|
||||
installChannelOutboundPayloadContractSuite({
|
||||
channel: "zalo",
|
||||
chunking: { mode: "split", longTextLength: 3000, maxChunkLength: 2000 },
|
||||
createHarness: createZaloHarness,
|
||||
});
|
||||
});
|
||||
@@ -1,4 +1,8 @@
|
||||
import { primeChannelOutboundSendMock } from "openclaw/plugin-sdk/testing";
|
||||
import {
|
||||
installChannelOutboundPayloadContractSuite,
|
||||
primeChannelOutboundSendMock,
|
||||
type OutboundPayloadHarnessParams,
|
||||
} from "openclaw/plugin-sdk/testing";
|
||||
import { beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import "./accounts.test-mocks.js";
|
||||
import "./zalo-js.test-mocks.js";
|
||||
@@ -109,6 +113,38 @@ describe("zalouserPlugin outbound sendPayload", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("zalouserPlugin outbound payload contract", () => {
|
||||
function createZalouserHarness(params: OutboundPayloadHarnessParams) {
|
||||
const mockedSend = vi.mocked(sendModule.sendMessageZalouser);
|
||||
setZalouserRuntime({
|
||||
channel: {
|
||||
text: {
|
||||
resolveChunkMode: vi.fn(() => "length"),
|
||||
resolveTextChunkLimit: vi.fn(() => 1200),
|
||||
},
|
||||
},
|
||||
} as never);
|
||||
primeChannelOutboundSendMock(mockedSend, { ok: true, messageId: "zlu-1" }, params.sendResults);
|
||||
const ctx = {
|
||||
cfg: {},
|
||||
to: "user:987654321",
|
||||
text: "",
|
||||
payload: params.payload,
|
||||
};
|
||||
return {
|
||||
run: async () => await zalouserPlugin.outbound!.sendPayload!(ctx),
|
||||
sendMock: mockedSend,
|
||||
to: "987654321",
|
||||
};
|
||||
}
|
||||
|
||||
installChannelOutboundPayloadContractSuite({
|
||||
channel: "zalouser",
|
||||
chunking: { mode: "passthrough", longTextLength: 3000 },
|
||||
createHarness: createZalouserHarness,
|
||||
});
|
||||
});
|
||||
|
||||
describe("zalouserPlugin messaging target normalization", () => {
|
||||
it("normalizes user/group aliases to canonical targets", () => {
|
||||
const normalize = zalouserPlugin.messaging?.normalizeTarget;
|
||||
|
||||
Reference in New Issue
Block a user