Initial Commit

This commit is contained in:
2026-05-27 23:29:53 +01:00
commit fbc70f96e6
10000 changed files with 1102152 additions and 0 deletions

View File

@@ -0,0 +1,66 @@
import { describe, expect, it } from "@suaveplan/testing/runner";
import {
OPENAPI_UI_REDOC_CODES,
OpenapiUiRedocError,
} from "../error-codes/error-codes.js";
import { parseRedocUiOptions, redocUiOptionsSchema } from "./options.js";
describe("parseRedocUiOptions", () => {
it("defaults are applied when no input is given", { timeout: 5000 }, () => {
const parsed = parseRedocUiOptions(undefined);
expect(parsed.openapiUrl).toBe("/openapi.json");
expect(parsed.title).toBe("API Reference");
expect(parsed.theme).toBe("light");
expect(parsed.uiAssets).toBe("cdn");
expect(parsed.hideDownloadButton).toBe(false);
expect(parsed.nativeScrollbars).toBe(false);
expect(parsed.expandResponses).toBeUndefined();
});
it("passes valid expandResponses values", { timeout: 5000 }, () => {
expect(
parseRedocUiOptions({ expandResponses: "200,201" }).expandResponses
).toBe("200,201");
expect(
parseRedocUiOptions({ expandResponses: "all" }).expandResponses
).toBe("all");
expect(
parseRedocUiOptions({ expandResponses: "2xx" }).expandResponses
).toBe("2xx");
});
it("invalid expandResponses rejected", { timeout: 5000 }, () => {
try {
parseRedocUiOptions({ expandResponses: "blahblah" });
throw new Error("expected throw");
} catch (err) {
expect(err).toBeInstanceOf(OpenapiUiRedocError);
expect((err as OpenapiUiRedocError).redocCode).toBe(
OPENAPI_UI_REDOC_CODES.INVALID_OPTIONS
);
}
});
it("unknown keys are refused by the strict schema", {
timeout: 5000,
}, () => {
expect(() =>
parseRedocUiOptions({
// @ts-expect-error — deliberate
bogus: "field",
})
).toThrow(OpenapiUiRedocError);
});
it("schema is exported and accepts a partial input", {
timeout: 5000,
}, () => {
const result = redocUiOptionsSchema.safeParse({});
expect(result.success).toBe(true);
});
it("returned options object is frozen", { timeout: 5000 }, () => {
const parsed = parseRedocUiOptions({});
expect(Object.isFrozen(parsed)).toBe(true);
});
});