chore: Fix types in tests 27/N.

This commit is contained in:
cpojer
2026-02-17 14:31:55 +09:00
parent 4235435309
commit 97c8f4999e
15 changed files with 129 additions and 51 deletions

View File

@@ -6,6 +6,7 @@ import {
makeSessionStore,
setLoadConfigMock,
} from "./auto-reply.test-harness.js";
import type { WebInboundMessage } from "./inbound.js";
installWebAutoReplyTestHomeHooks();
@@ -19,7 +20,7 @@ function createRuntime() {
function startMonitorWebChannel(params: {
monitorWebChannelFn: (...args: unknown[]) => Promise<unknown>;
listenerFactory: (...args: unknown[]) => Promise<unknown>;
listenerFactory: unknown;
sleep: ReturnType<typeof vi.fn>;
signal?: AbortSignal;
reconnect?: { initialMs: number; maxMs: number; maxAttempts: number; factor: number };
@@ -43,6 +44,32 @@ function startMonitorWebChannel(params: {
return { runtime, controller, run };
}
function makeInboundMessage(params: {
body: string;
from: string;
to: string;
id?: string;
timestamp?: number;
sendComposing: ReturnType<typeof vi.fn>;
reply: ReturnType<typeof vi.fn>;
sendMedia: ReturnType<typeof vi.fn>;
}): WebInboundMessage {
return {
body: params.body,
from: params.from,
to: params.to,
id: params.id,
timestamp: params.timestamp,
conversationId: params.from,
accountId: "default",
chatType: "direct",
chatId: params.from,
sendComposing: params.sendComposing as unknown as WebInboundMessage["sendComposing"],
reply: params.reply as unknown as WebInboundMessage["reply"],
sendMedia: params.sendMedia as unknown as WebInboundMessage["sendMedia"],
};
}
describe("web auto-reply", () => {
installWebAutoReplyUnitTestHooks();
@@ -133,15 +160,17 @@ describe("web auto-reply", () => {
// The watchdog only needs `lastMessageAt` to be set. Don't await full message
// processing here since it can schedule timers and become flaky under load.
void capturedOnMessage?.({
body: "hi",
from: "+1",
to: "+2",
id: "m1",
sendComposing,
reply,
sendMedia,
});
void capturedOnMessage?.(
makeInboundMessage({
body: "hi",
from: "+1",
to: "+2",
id: "m1",
sendComposing,
reply,
sendMedia,
}),
);
await vi.advanceTimersByTimeAsync(31 * 60 * 1000);
await Promise.resolve();
@@ -174,7 +203,7 @@ describe("web auto-reply", () => {
const run = monitorWebChannel(
false,
listenerFactory,
listenerFactory as never,
true,
async () => ({ text: "ok" }),
runtime as never,
@@ -236,30 +265,34 @@ describe("web auto-reply", () => {
session: { store: store.storePath },
}));
await monitorWebChannel(false, listenerFactory, false, resolver);
await monitorWebChannel(false, listenerFactory as never, false, resolver);
expect(capturedOnMessage).toBeDefined();
// Two messages from the same sender with fixed timestamps
await capturedOnMessage?.({
body: "first",
from: "+1",
to: "+2",
id: "m1",
timestamp: 1735689600000, // Jan 1 2025 00:00:00 UTC
sendComposing,
reply,
sendMedia,
});
await capturedOnMessage?.({
body: "second",
from: "+1",
to: "+2",
id: "m2",
timestamp: 1735693200000, // Jan 1 2025 01:00:00 UTC
sendComposing,
reply,
sendMedia,
});
await capturedOnMessage?.(
makeInboundMessage({
body: "first",
from: "+1",
to: "+2",
id: "m1",
timestamp: 1735689600000, // Jan 1 2025 00:00:00 UTC
sendComposing,
reply,
sendMedia,
}),
);
await capturedOnMessage?.(
makeInboundMessage({
body: "second",
from: "+1",
to: "+2",
id: "m2",
timestamp: 1735693200000, // Jan 1 2025 01:00:00 UTC
sendComposing,
reply,
sendMedia,
}),
);
expect(resolver).toHaveBeenCalledTimes(2);
const firstArgs = resolver.mock.calls[0][0];