test: guard zalo lifecycle mock calls

This commit is contained in:
Peter Steinberger
2026-05-12 00:55:27 +01:00
parent 3b15e11052
commit 6ac981f044

View File

@@ -60,6 +60,15 @@ describe("Zalo reply-once lifecycle", () => {
});
}
function requireRecordInboundSessionArgs() {
const [call] = recordInboundSessionMock.mock.calls;
if (!call) {
throw new Error("expected inbound session record call");
}
const [recordArgs] = call;
return recordArgs;
}
it("routes one accepted webhook event to one visible reply across duplicate replay", async () => {
dispatchReplyWithBufferedBlockDispatcherMock.mockImplementation(
async ({ dispatcherOptions }) => {
@@ -95,7 +104,7 @@ describe("Zalo reply-once lifecycle", () => {
);
expect(recordInboundSessionMock).toHaveBeenCalledTimes(1);
const [recordArgs] = recordInboundSessionMock.mock.calls[0] ?? [];
const recordArgs = requireRecordInboundSessionArgs();
expect(recordArgs?.sessionKey).toBe("agent:main:zalo:direct:dm-chat-1");
expect(recordArgs?.ctx?.AccountId).toBe("acct-zalo-lifecycle");
expect(recordArgs?.ctx?.SessionKey).toBe("agent:main:zalo:direct:dm-chat-1");