mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-30 01:01:59 +00:00
test(hooks): cover claimed inbound observer delivery
This commit is contained in:
@@ -1759,7 +1759,8 @@ describe("dispatchReplyFromConfig", () => {
|
|||||||
it("lets a plugin claim inbound traffic before core commands and agent dispatch", async () => {
|
it("lets a plugin claim inbound traffic before core commands and agent dispatch", async () => {
|
||||||
setNoAbort();
|
setNoAbort();
|
||||||
hookMocks.runner.hasHooks.mockImplementation(
|
hookMocks.runner.hasHooks.mockImplementation(
|
||||||
((hookName?: string) => hookName === "inbound_claim") as () => boolean,
|
((hookName?: string) =>
|
||||||
|
hookName === "inbound_claim" || hookName === "message_received") as () => boolean,
|
||||||
);
|
);
|
||||||
hookMocks.runner.runInboundClaim.mockResolvedValue({ handled: true } as never);
|
hookMocks.runner.runInboundClaim.mockResolvedValue({ handled: true } as never);
|
||||||
const cfg = emptyConfig;
|
const cfg = emptyConfig;
|
||||||
@@ -1780,6 +1781,7 @@ describe("dispatchReplyFromConfig", () => {
|
|||||||
RawBody: "who are you",
|
RawBody: "who are you",
|
||||||
Body: "who are you",
|
Body: "who are you",
|
||||||
MessageSid: "msg-claim-1",
|
MessageSid: "msg-claim-1",
|
||||||
|
SessionKey: "agent:main:telegram:group:-10099:77",
|
||||||
});
|
});
|
||||||
const replyResolver = vi.fn(async () => ({ text: "should not run" }) satisfies ReplyPayload);
|
const replyResolver = vi.fn(async () => ({ text: "should not run" }) satisfies ReplyPayload);
|
||||||
|
|
||||||
@@ -1806,6 +1808,32 @@ describe("dispatchReplyFromConfig", () => {
|
|||||||
messageId: "msg-claim-1",
|
messageId: "msg-claim-1",
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
expect(hookMocks.runner.runMessageReceived).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
from: ctx.From,
|
||||||
|
content: "who are you",
|
||||||
|
metadata: expect.objectContaining({
|
||||||
|
messageId: "msg-claim-1",
|
||||||
|
originatingChannel: "telegram",
|
||||||
|
originatingTo: "telegram:-10099",
|
||||||
|
senderId: "user-9",
|
||||||
|
senderUsername: "ada",
|
||||||
|
threadId: 77,
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
expect.objectContaining({
|
||||||
|
channelId: "telegram",
|
||||||
|
accountId: "default",
|
||||||
|
conversationId: "telegram:-10099",
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
expect(internalHookMocks.triggerInternalHook).toHaveBeenCalledWith(
|
||||||
|
expect.objectContaining({
|
||||||
|
type: "message",
|
||||||
|
action: "received",
|
||||||
|
sessionKey: "agent:main:telegram:group:-10099:77",
|
||||||
|
}),
|
||||||
|
);
|
||||||
expect(replyResolver).not.toHaveBeenCalled();
|
expect(replyResolver).not.toHaveBeenCalled();
|
||||||
expect(dispatcher.sendFinalReply).not.toHaveBeenCalled();
|
expect(dispatcher.sendFinalReply).not.toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user