1import { toConsumerSettings } from "@/Cloudflare/Queues/EventSource.ts";
2import * as Duration from "effect/Duration";
3import { describe, expect, it } from "alchemy-test";
4
5describe(
6 "toConsumerSettings",
7 {
8 tags: ["unit", "provider:cloudflare", "provider:cloudflare:queue", "local"],
9 },
10 () => {
11 it("passes scalar fields through unchanged", () => {
12 expect(
13 toConsumerSettings({
14 batchSize: 25,
15 maxConcurrency: 4,
16 maxRetries: 3,
17 }),
18 ).toEqual({
19 batchSize: 25,
20 maxConcurrency: 4,
21 maxRetries: 3,
22 maxWaitTimeMs: undefined,
23 retryDelay: undefined,
24 });
25 });
26
27 it("converts maxWaitTime to whole milliseconds", () => {
28 expect(
29 toConsumerSettings({ maxWaitTime: Duration.seconds(5) }).maxWaitTimeMs,
30 ).toBe(5_000);
31 expect(
32 toConsumerSettings({ maxWaitTime: "250 millis" }).maxWaitTimeMs,
33 ).toBe(250);
34 expect(toConsumerSettings({ maxWaitTime: 1500 }).maxWaitTimeMs).toBe(
35 1500,
36 );
37 });
38
39 it("rounds sub-millisecond maxWaitTime up", () => {
40 expect(
41 toConsumerSettings({ maxWaitTime: Duration.nanos(1n) }).maxWaitTimeMs,
42 ).toBe(1);
43 });
44
45 it("converts retryDelay to whole seconds", () => {
46 expect(
47 toConsumerSettings({ retryDelay: Duration.minutes(2) }).retryDelay,
48 ).toBe(120);
49 expect(toConsumerSettings({ retryDelay: "30 seconds" }).retryDelay).toBe(
50 30,
51 );
52 });
53
54 it("rounds partial-second retryDelay up", () => {
55 expect(
56 toConsumerSettings({ retryDelay: Duration.millis(1500) }).retryDelay,
57 ).toBe(2);
58 });
59
60 it("leaves missing time fields undefined", () => {
61 const result = toConsumerSettings({ batchSize: 10 });
62 expect(result.maxWaitTimeMs).toBeUndefined();
63 expect(result.retryDelay).toBeUndefined();
64 });
65 },
66);