mirror of https://github.com/openclaw/openclaw.git
test: share whatsapp outbound poll fixtures
This commit is contained in:
parent
1ec6b012f8
commit
66de7311c7
|
|
@ -1,5 +1,8 @@
|
|||
import type { OpenClawConfig } from "openclaw/plugin-sdk/whatsapp";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
createWhatsAppPollFixture,
|
||||
expectWhatsAppPollSent,
|
||||
} from "../../../src/test-helpers/whatsapp-outbound.js";
|
||||
|
||||
const hoisted = vi.hoisted(() => ({
|
||||
sendPollWhatsApp: vi.fn(async () => ({ messageId: "wa-poll-1", toJid: "1555@s.whatsapp.net" })),
|
||||
|
|
@ -22,25 +25,16 @@ import { whatsappPlugin } from "./channel.js";
|
|||
|
||||
describe("whatsappPlugin outbound sendPoll", () => {
|
||||
it("threads cfg into runtime sendPollWhatsApp call", async () => {
|
||||
const cfg = { marker: "resolved-cfg" } as OpenClawConfig;
|
||||
const poll = {
|
||||
question: "Lunch?",
|
||||
options: ["Pizza", "Sushi"],
|
||||
maxSelections: 1,
|
||||
};
|
||||
const { cfg, poll, to, accountId } = createWhatsAppPollFixture();
|
||||
|
||||
const result = await whatsappPlugin.outbound!.sendPoll!({
|
||||
cfg,
|
||||
to: "+1555",
|
||||
to,
|
||||
poll,
|
||||
accountId: "work",
|
||||
accountId,
|
||||
});
|
||||
|
||||
expect(hoisted.sendPollWhatsApp).toHaveBeenCalledWith("+1555", poll, {
|
||||
verbose: false,
|
||||
accountId: "work",
|
||||
cfg,
|
||||
});
|
||||
expectWhatsAppPollSent(hoisted.sendPollWhatsApp, { cfg, poll, to, accountId });
|
||||
expect(result).toEqual({ messageId: "wa-poll-1", toJid: "1555@s.whatsapp.net" });
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
import { describe, expect, it, vi } from "vitest";
|
||||
import type { OpenClawConfig } from "../../../config/config.js";
|
||||
import {
|
||||
createWhatsAppPollFixture,
|
||||
expectWhatsAppPollSent,
|
||||
} from "../../../test-helpers/whatsapp-outbound.js";
|
||||
|
||||
const hoisted = vi.hoisted(() => ({
|
||||
sendPollWhatsApp: vi.fn(async () => ({ messageId: "poll-1", toJid: "1555@s.whatsapp.net" })),
|
||||
|
|
@ -17,25 +20,16 @@ import { whatsappOutbound } from "./whatsapp.js";
|
|||
|
||||
describe("whatsappOutbound sendPoll", () => {
|
||||
it("threads cfg through poll send options", async () => {
|
||||
const cfg = { marker: "resolved-cfg" } as OpenClawConfig;
|
||||
const poll = {
|
||||
question: "Lunch?",
|
||||
options: ["Pizza", "Sushi"],
|
||||
maxSelections: 1,
|
||||
};
|
||||
const { cfg, poll, to, accountId } = createWhatsAppPollFixture();
|
||||
|
||||
const result = await whatsappOutbound.sendPoll!({
|
||||
cfg,
|
||||
to: "+1555",
|
||||
to,
|
||||
poll,
|
||||
accountId: "work",
|
||||
accountId,
|
||||
});
|
||||
|
||||
expect(hoisted.sendPollWhatsApp).toHaveBeenCalledWith("+1555", poll, {
|
||||
verbose: false,
|
||||
accountId: "work",
|
||||
cfg,
|
||||
});
|
||||
expectWhatsAppPollSent(hoisted.sendPollWhatsApp, { cfg, poll, to, accountId });
|
||||
expect(result).toEqual({ messageId: "poll-1", toJid: "1555@s.whatsapp.net" });
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -0,0 +1,33 @@
|
|||
import { expect, type MockInstance } from "vitest";
|
||||
import type { OpenClawConfig } from "../config/config.js";
|
||||
|
||||
export function createWhatsAppPollFixture() {
|
||||
const cfg = { marker: "resolved-cfg" } as OpenClawConfig;
|
||||
const poll = {
|
||||
question: "Lunch?",
|
||||
options: ["Pizza", "Sushi"],
|
||||
maxSelections: 1,
|
||||
};
|
||||
return {
|
||||
cfg,
|
||||
poll,
|
||||
to: "+1555",
|
||||
accountId: "work",
|
||||
};
|
||||
}
|
||||
|
||||
export function expectWhatsAppPollSent(
|
||||
sendPollWhatsApp: MockInstance,
|
||||
params: {
|
||||
cfg: OpenClawConfig;
|
||||
poll: { question: string; options: string[]; maxSelections: number };
|
||||
to?: string;
|
||||
accountId?: string;
|
||||
},
|
||||
) {
|
||||
expect(sendPollWhatsApp).toHaveBeenCalledWith(params.to ?? "+1555", params.poll, {
|
||||
verbose: false,
|
||||
accountId: params.accountId ?? "work",
|
||||
cfg: params.cfg,
|
||||
});
|
||||
}
|
||||
Loading…
Reference in New Issue