fix: heartbeat falls back to last session contact

This commit is contained in:
Peter Steinberger
2025-11-26 17:08:43 +01:00
parent 3998933b30
commit 0d5e5f8dee
2 changed files with 75 additions and 9 deletions

View File

@@ -105,6 +105,37 @@ describe("runWebHeartbeatOnce", () => {
});
expect(sender).toHaveBeenCalledWith("+1555", "ALERT", { verbose: false });
});
it("falls back to most recent session when no to is provided", async () => {
const sender: typeof sendMessageWeb = vi
.fn()
.mockResolvedValue({ messageId: "m1", toJid: "jid" });
const resolver = vi.fn(async () => ({ text: "ALERT" }));
// Seed session store
const now = Date.now();
const store = {
"+1222": { sessionId: "s1", updatedAt: now - 1000 },
"+1333": { sessionId: "s2", updatedAt: now },
};
const storePath = resolveStorePath();
await fs.mkdir(resolveStorePath().replace("sessions.json", ""), {
recursive: true,
});
await fs.writeFile(storePath, JSON.stringify(store));
setLoadConfigMock({
inbound: {
allowFrom: ["+1999"],
reply: { mode: "command", session: {} },
},
});
await runWebHeartbeatOnce({
to: "+1999",
verbose: false,
sender,
replyResolver: resolver,
});
expect(sender).toHaveBeenCalledWith("+1333", "ALERT", { verbose: false });
});
});
describe("web auto-reply", () => {