mirror of https://github.com/openclaw/openclaw.git
test: reset line webhook mocks between cases
This commit is contained in:
parent
69b9e44762
commit
08b5ba1a12
|
|
@ -74,6 +74,16 @@ type LineWebhookContext = Parameters<typeof import("./bot-handlers.js").handleLi
|
|||
|
||||
const createRuntime = () => ({ log: vi.fn(), error: vi.fn(), exit: vi.fn() });
|
||||
|
||||
function buildDefaultLineMessageContext() {
|
||||
return {
|
||||
ctxPayload: { From: "line:group:group-1" },
|
||||
replyToken: "reply-token",
|
||||
route: { agentId: "default" },
|
||||
isGroup: true,
|
||||
accountId: "default",
|
||||
};
|
||||
}
|
||||
|
||||
function createReplayMessageEvent(params: {
|
||||
messageId: string;
|
||||
groupId: string;
|
||||
|
|
@ -200,14 +210,15 @@ async function startInflightReplayDuplicate(params: {
|
|||
|
||||
describe("handleLineWebhookEvents", () => {
|
||||
beforeAll(async () => {
|
||||
vi.resetModules();
|
||||
({ handleLineWebhookEvents, createLineWebhookReplayCache } = await import("./bot-handlers.js"));
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
buildLineMessageContextMock.mockClear();
|
||||
buildLinePostbackContextMock.mockClear();
|
||||
readAllowFromStoreMock.mockClear();
|
||||
upsertPairingRequestMock.mockClear();
|
||||
buildLineMessageContextMock.mockReset().mockResolvedValue(buildDefaultLineMessageContext());
|
||||
buildLinePostbackContextMock.mockReset().mockResolvedValue(null as unknown);
|
||||
readAllowFromStoreMock.mockReset().mockResolvedValue([]);
|
||||
upsertPairingRequestMock.mockReset().mockResolvedValue({ code: "CODE", created: true });
|
||||
});
|
||||
|
||||
it("blocks group messages when groupPolicy is disabled", async () => {
|
||||
|
|
@ -573,10 +584,11 @@ describe("handleLineWebhookEvents", () => {
|
|||
isRedelivery: true,
|
||||
});
|
||||
const { firstRun, secondRun } = await startInflightReplayDuplicate({ event, processMessage });
|
||||
const firstFailure = expect(firstRun).rejects.toThrow("transient inflight failure");
|
||||
const secondFailure = expect(secondRun).rejects.toThrow("transient inflight failure");
|
||||
rejectFirst?.(new Error("transient inflight failure"));
|
||||
|
||||
await expect(firstRun).rejects.toThrow("transient inflight failure");
|
||||
await expect(secondRun).rejects.toThrow("transient inflight failure");
|
||||
await Promise.all([firstFailure, secondFailure]);
|
||||
expect(processMessage).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue