diff --git a/src/auto-reply/reply.heartbeat-typing.test.ts b/src/auto-reply/reply.heartbeat-typing.test.ts index eaac90a087..41da12974c 100644 --- a/src/auto-reply/reply.heartbeat-typing.test.ts +++ b/src/auto-reply/reply.heartbeat-typing.test.ts @@ -49,43 +49,34 @@ afterEach(() => { }); describe("getReplyFromConfig typing (heartbeat)", () => { + async function runReplyFlow(isHeartbeat: boolean): Promise> { + const onReplyStart = vi.fn(); + await withTempHome(async (home) => { + runEmbeddedPiAgentMock.mockResolvedValueOnce({ + payloads: [{ text: "ok" }], + meta: {}, + }); + + await getReplyFromConfig( + { Body: "hi", From: "+1000", To: "+2000", Provider: "whatsapp" }, + { onReplyStart, isHeartbeat }, + makeReplyConfig(home) as unknown as OpenClawConfig, + ); + }); + return onReplyStart; + } + beforeEach(() => { vi.stubEnv("OPENCLAW_TEST_FAST", "1"); }); it("starts typing for normal runs", async () => { - await withTempHome(async (home) => { - runEmbeddedPiAgentMock.mockResolvedValueOnce({ - payloads: [{ text: "ok" }], - meta: {}, - }); - const onReplyStart = vi.fn(); - - await getReplyFromConfig( - { Body: "hi", From: "+1000", To: "+2000", Provider: "whatsapp" }, - { onReplyStart, isHeartbeat: false }, - makeReplyConfig(home) as unknown as OpenClawConfig, - ); - - expect(onReplyStart).toHaveBeenCalled(); - }); + const onReplyStart = await runReplyFlow(false); + expect(onReplyStart).toHaveBeenCalled(); }); it("does not start typing for heartbeat runs", async () => { - await withTempHome(async (home) => { - runEmbeddedPiAgentMock.mockResolvedValueOnce({ - payloads: [{ text: "ok" }], - meta: {}, - }); - const onReplyStart = vi.fn(); - - await getReplyFromConfig( - { Body: "hi", From: "+1000", To: "+2000", Provider: "whatsapp" }, - { onReplyStart, isHeartbeat: true }, - makeReplyConfig(home) as unknown as OpenClawConfig, - ); - - expect(onReplyStart).not.toHaveBeenCalled(); - }); + const onReplyStart = await runReplyFlow(true); + expect(onReplyStart).not.toHaveBeenCalled(); }); });