mirror of
https://github.com/moltbot/moltbot.git
synced 2026-05-13 23:56:07 +00:00
test: dedupe feishu comment mock reads
This commit is contained in:
@@ -212,6 +212,18 @@ async function setupCommentMonitorHandler(): Promise<(data: unknown) => Promise<
|
||||
});
|
||||
}
|
||||
|
||||
function mockCallAt(
|
||||
mock: { mock: { calls: Array<readonly unknown[]> } },
|
||||
index: number,
|
||||
label: string,
|
||||
): readonly unknown[] {
|
||||
const call = mock.mock.calls[index];
|
||||
if (!call) {
|
||||
throw new Error(`expected ${label} call`);
|
||||
}
|
||||
return call;
|
||||
}
|
||||
|
||||
describe("resolveDriveCommentEventTurn", () => {
|
||||
it("builds a real comment-turn prompt for add_comment notices", async () => {
|
||||
const client = makeOpenApiClient({ includeTargetReplyInBatch: true });
|
||||
@@ -828,7 +840,7 @@ describe("drive.notice.comment_add_v1 monitor handler", () => {
|
||||
await onComment(makeDriveCommentEvent());
|
||||
|
||||
expect(handleFeishuCommentEventMock).toHaveBeenCalledTimes(1);
|
||||
const handleArgs = handleFeishuCommentEventMock.mock.calls.at(0)?.[0] as
|
||||
const handleArgs = mockCallAt(handleFeishuCommentEventMock, 0, "Feishu comment handler")[0] as
|
||||
| {
|
||||
accountId?: string;
|
||||
botOpenId?: string;
|
||||
@@ -880,12 +892,16 @@ describe("drive.notice.comment_add_v1 monitor handler", () => {
|
||||
await vi.waitFor(() => {
|
||||
expect(handleFeishuCommentEventMock).toHaveBeenCalledTimes(2);
|
||||
});
|
||||
const firstCallArgs = handleFeishuCommentEventMock.mock.calls.at(0) as
|
||||
| [{ event?: { event_id?: string } }]
|
||||
| undefined;
|
||||
const secondCallArgs = handleFeishuCommentEventMock.mock.calls.at(1) as
|
||||
| [{ event?: { event_id?: string } }]
|
||||
| undefined;
|
||||
const firstCallArgs = mockCallAt(
|
||||
handleFeishuCommentEventMock,
|
||||
0,
|
||||
"first Feishu comment handler",
|
||||
) as [{ event?: { event_id?: string } }] | undefined;
|
||||
const secondCallArgs = mockCallAt(
|
||||
handleFeishuCommentEventMock,
|
||||
1,
|
||||
"second Feishu comment handler",
|
||||
) as [{ event?: { event_id?: string } }] | undefined;
|
||||
const firstCall = firstCallArgs?.[0];
|
||||
const secondCall = secondCallArgs?.[0];
|
||||
expect(firstCall?.event?.event_id).toBe("evt_1");
|
||||
@@ -917,8 +933,11 @@ describe("drive.notice.comment_add_v1 monitor handler", () => {
|
||||
"feishu[default]: error handling drive comment notice: Error: post-send failure",
|
||||
);
|
||||
});
|
||||
const [recordedMessageId, recordedNamespace, recordedLogger] =
|
||||
(dedup.recordProcessedFeishuMessage as ReturnType<typeof vi.fn>).mock.calls.at(0) ?? [];
|
||||
const [recordedMessageId, recordedNamespace, recordedLogger] = mockCallAt(
|
||||
dedup.recordProcessedFeishuMessage as ReturnType<typeof vi.fn>,
|
||||
0,
|
||||
"Feishu processed-message record",
|
||||
);
|
||||
expect(recordedMessageId).toBe("drive-comment:10d9d60b990db39f96a4c2fd357fb877");
|
||||
expect(recordedNamespace).toBe("default");
|
||||
expect(typeof recordedLogger).toBe("function");
|
||||
|
||||
Reference in New Issue
Block a user