mirror of
https://github.com/moltbot/moltbot.git
synced 2026-05-21 21:56:46 +00:00
test: tighten whatsapp ack reaction assertions
This commit is contained in:
@@ -73,16 +73,17 @@ const runAckReaction = (overrides: Partial<AckReactionParams> = {}) =>
|
||||
...overrides,
|
||||
});
|
||||
|
||||
const expectAckReactionSent = (accountId: string) => {
|
||||
const expectAckReactionSent = (accountId: string, cfg: OpenClawConfig = createConfig("ack")) => {
|
||||
expect(hoisted.sendReactionWhatsApp).toHaveBeenCalledWith(
|
||||
"15551234567@s.whatsapp.net",
|
||||
"msg-1",
|
||||
"👀",
|
||||
expect.objectContaining({
|
||||
{
|
||||
verbose: false,
|
||||
fromMe: false,
|
||||
accountId,
|
||||
}),
|
||||
cfg,
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
@@ -94,13 +95,14 @@ describe("maybeSendAckReaction", () => {
|
||||
it.each(["ack", "minimal", "extensive"] as const)(
|
||||
"sends ack reactions when reactionLevel is %s",
|
||||
async (reactionLevel) => {
|
||||
const cfg = createConfig(reactionLevel);
|
||||
const ackReaction = await runAckReaction({
|
||||
cfg: createConfig(reactionLevel),
|
||||
cfg,
|
||||
});
|
||||
|
||||
expect(ackReaction?.ackReactionValue).toBe("👀");
|
||||
await expect(ackReaction?.ackReactionPromise).resolves.toBe(true);
|
||||
expectAckReactionSent("default");
|
||||
expectAckReactionSent("default", cfg);
|
||||
},
|
||||
);
|
||||
|
||||
@@ -114,14 +116,15 @@ describe("maybeSendAckReaction", () => {
|
||||
});
|
||||
|
||||
it("uses the active account reactionLevel override for ack gating", async () => {
|
||||
const ackReaction = await runAckReaction({
|
||||
cfg: createConfig("off", {
|
||||
accounts: {
|
||||
work: {
|
||||
reactionLevel: "ack",
|
||||
},
|
||||
const cfg = createConfig("off", {
|
||||
accounts: {
|
||||
work: {
|
||||
reactionLevel: "ack",
|
||||
},
|
||||
}),
|
||||
},
|
||||
});
|
||||
const ackReaction = await runAckReaction({
|
||||
cfg,
|
||||
msg: createMessage({
|
||||
accountId: "work",
|
||||
}),
|
||||
@@ -130,11 +133,12 @@ describe("maybeSendAckReaction", () => {
|
||||
});
|
||||
|
||||
expect(ackReaction?.ackReactionValue).toBe("👀");
|
||||
expectAckReactionSent("work");
|
||||
expectAckReactionSent("work", cfg);
|
||||
});
|
||||
|
||||
it("returns a handle that removes the ack with an empty reaction", async () => {
|
||||
const ackReaction = await runAckReaction();
|
||||
const cfg = createConfig("ack");
|
||||
const ackReaction = await runAckReaction({ cfg });
|
||||
|
||||
await ackReaction?.remove();
|
||||
|
||||
@@ -142,27 +146,29 @@ describe("maybeSendAckReaction", () => {
|
||||
"15551234567@s.whatsapp.net",
|
||||
"msg-1",
|
||||
"",
|
||||
expect.objectContaining({
|
||||
{
|
||||
verbose: false,
|
||||
fromMe: false,
|
||||
accountId: "default",
|
||||
}),
|
||||
cfg,
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
it("records ack send failures on the handle", async () => {
|
||||
const cfg = createConfig("ack");
|
||||
const warn = vi.fn();
|
||||
hoisted.sendReactionWhatsApp.mockRejectedValueOnce(new Error("session down"));
|
||||
|
||||
const ackReaction = await runAckReaction({ warn });
|
||||
const ackReaction = await runAckReaction({ cfg, warn });
|
||||
|
||||
await expect(ackReaction?.ackReactionPromise).resolves.toBe(false);
|
||||
expect(warn).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
{
|
||||
error: "session down",
|
||||
chatId: "15551234567@s.whatsapp.net",
|
||||
messageId: "msg-1",
|
||||
}),
|
||||
},
|
||||
"failed to send ack reaction",
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user