Initial Commit
This commit is contained in:
56
packages/api-stack/api/api-openapi/tests/property.test.ts
Normal file
56
packages/api-stack/api/api-openapi/tests/property.test.ts
Normal file
@@ -0,0 +1,56 @@
|
||||
import { describe, expect, it } from "@suaveplan/testing/runner";
|
||||
import fc from "fast-check";
|
||||
import { mergeOpenAPIDocuments } from "../src/merger/merger.js";
|
||||
import type { OpenAPIDocument } from "../src/types/openapi.js";
|
||||
|
||||
const operationArb = fc.record({
|
||||
responses: fc.constant({}),
|
||||
});
|
||||
|
||||
const pathItemArb = fc.dictionary(
|
||||
fc.constantFrom("get", "post", "put", "patch", "delete"),
|
||||
operationArb,
|
||||
{ minKeys: 1, maxKeys: 3 }
|
||||
);
|
||||
|
||||
const pathsArb = fc.dictionary(
|
||||
fc.string({ minLength: 1, maxLength: 10 }).map((s) => `/${s}`),
|
||||
pathItemArb,
|
||||
{ minKeys: 0, maxKeys: 5 }
|
||||
);
|
||||
|
||||
const docArb = pathsArb.map<OpenAPIDocument>((paths) => ({
|
||||
openapi: "3.1.0",
|
||||
info: { title: "T", version: "1.0.0" },
|
||||
paths,
|
||||
}));
|
||||
|
||||
describe("mergeOpenAPIDocuments — associativity property", () => {
|
||||
it("merge(a, b, c) === merge(merge(a, b), c) for arbitrary path sets", {
|
||||
timeout: 30000,
|
||||
}, () => {
|
||||
fc.assert(
|
||||
fc.property(docArb, docArb, docArb, (a, b, c) => {
|
||||
const left = mergeOpenAPIDocuments(a, b, c);
|
||||
const right = mergeOpenAPIDocuments(
|
||||
mergeOpenAPIDocuments(a, b),
|
||||
c
|
||||
);
|
||||
expect(right.paths).toEqual(left.paths);
|
||||
}),
|
||||
{ numRuns: 200 }
|
||||
);
|
||||
});
|
||||
|
||||
it("merging with empty extras is idempotent on paths", {
|
||||
timeout: 30000,
|
||||
}, () => {
|
||||
fc.assert(
|
||||
fc.property(docArb, (a) => {
|
||||
const m = mergeOpenAPIDocuments(a, {}, {}, {});
|
||||
expect(m.paths).toEqual(a.paths);
|
||||
}),
|
||||
{ numRuns: 100 }
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user