Skip to content
File

Blob: tests/worker/routes/page-archive-queue.test.ts

typescript23 lines
1import { describe, expect, it, vi } from "vitest";
2 
3import { enqueueIndexPageMessages } from "@/worker/routes/pages";
4 
5describe("enqueueIndexPageMessages", () => {
6 it("sends every page id in bounded batches", async () => {
7 const sendBatch = vi
8 .fn<Queue["sendBatch"]>()
9 .mockResolvedValue({ metadata: { metrics: { backlogCount: 0, backlogBytes: 0 } } });
10 const pageIds = Array.from({ length: 205 }, (_, index) => `page-${index}`);
11 
12 await enqueueIndexPageMessages({ TASKS_QUEUE: { sendBatch } as unknown as Queue }, pageIds);
13 
14 expect(sendBatch).toHaveBeenCalledTimes(3);
15 expect(sendBatch.mock.calls[0][0]).toHaveLength(100);
16 expect(sendBatch.mock.calls[1][0]).toHaveLength(100);
17 expect(sendBatch.mock.calls[2][0]).toHaveLength(5);
18 expect(
19 sendBatch.mock.calls.flatMap((call) => Array.from(call[0], (entry) => (entry.body as { pageId: string }).pageId)),
20 ).toEqual(pageIds);
21 });
22});