import { describe, expect, it, vi } from "vitest"; import { createSignedCreateMessageRequest } from "./monitor.test-fixtures.js"; import { startWebhookServer } from "./monitor.test-harness.js"; import type { NextcloudTalkInboundMessage } from "./types.js"; describe("createNextcloudTalkWebhookServer replay handling", () => { it("acknowledges replayed requests and skips onMessage side effects", async () => { const seen = new Set(); const onMessage = vi.fn(async () => {}); const shouldProcessMessage = vi.fn(async (message: NextcloudTalkInboundMessage) => { if (seen.has(message.messageId)) { return false; } seen.add(message.messageId); return true; }); const harness = await startWebhookServer({ path: "/nextcloud-replay", shouldProcessMessage, onMessage, }); const { body, headers } = createSignedCreateMessageRequest(); const first = await fetch(harness.webhookUrl, { method: "POST", headers, body, }); const second = await fetch(harness.webhookUrl, { method: "POST", headers, body, }); expect(first.status).toBe(200); expect(second.status).toBe(200); expect(shouldProcessMessage).toHaveBeenCalledTimes(2); expect(onMessage).toHaveBeenCalledTimes(1); }); });