Initial Commit
This commit is contained in:
@@ -0,0 +1,64 @@
|
||||
import { describe, expect, it } from "@suaveplan/testing/runner";
|
||||
import { SSE_BUN_CODES, SseBunError } from "../error-codes/error-codes.js";
|
||||
import { DEFAULT_MAX_EVENT_BYTES, resolveOptions } from "./options.js";
|
||||
|
||||
const authStub = async () => ({
|
||||
tenantId: "acme" as never,
|
||||
principal: null,
|
||||
});
|
||||
|
||||
describe("options.resolveOptions", () => {
|
||||
it("applies every documented default", () => {
|
||||
const r = resolveOptions({ authenticate: authStub });
|
||||
expect(r.eventBufferSize).toBe(256);
|
||||
expect(r.eventBufferMs).toBe(300_000);
|
||||
expect(r.keepAliveCommentMs).toBe(15_000);
|
||||
expect(r.maxConnectionsPerTenant).toBe(1000);
|
||||
expect(r.maxEventBytes).toBe(DEFAULT_MAX_EVENT_BYTES);
|
||||
expect(r.compressionEnabled).toBe(true);
|
||||
expect(r.retryMs).toBe(3000);
|
||||
expect(r.plugin).toBe("api-sse-bun");
|
||||
expect(typeof r.clock).toBe("function");
|
||||
expect(r.broker).toBeUndefined();
|
||||
}, 5000);
|
||||
|
||||
it("respects explicit overrides", () => {
|
||||
const clock = () => 42;
|
||||
const r = resolveOptions({
|
||||
eventBufferSize: 4,
|
||||
eventBufferMs: 1,
|
||||
keepAliveCommentMs: 7,
|
||||
maxConnectionsPerTenant: 2,
|
||||
maxEventBytes: 1024,
|
||||
compressionEnabled: false,
|
||||
retryMs: 1000,
|
||||
authenticate: authStub,
|
||||
clock,
|
||||
plugin: "demo",
|
||||
});
|
||||
expect(r.eventBufferSize).toBe(4);
|
||||
expect(r.eventBufferMs).toBe(1);
|
||||
expect(r.keepAliveCommentMs).toBe(7);
|
||||
expect(r.maxConnectionsPerTenant).toBe(2);
|
||||
expect(r.maxEventBytes).toBe(1024);
|
||||
expect(r.compressionEnabled).toBe(false);
|
||||
expect(r.retryMs).toBe(1000);
|
||||
expect(r.clock).toBe(clock);
|
||||
expect(r.plugin).toBe("demo");
|
||||
}, 5000);
|
||||
|
||||
it("throws HANDSHAKE_REJECTED on invalid primitive", () => {
|
||||
try {
|
||||
resolveOptions({
|
||||
eventBufferSize: 0,
|
||||
authenticate: authStub,
|
||||
});
|
||||
expect.fail("expected throw");
|
||||
} catch (err) {
|
||||
expect(err).toBeInstanceOf(SseBunError);
|
||||
expect((err as SseBunError).code).toBe(
|
||||
SSE_BUN_CODES.HANDSHAKE_REJECTED
|
||||
);
|
||||
}
|
||||
}, 5000);
|
||||
});
|
||||
Reference in New Issue
Block a user