29 lines
922 B
TypeScript
29 lines
922 B
TypeScript
import { expect, test } from "bun:test";
|
|
import { hasRequestSection, parseApiEntries, parseApiSections } from "../src/api-sections.ts";
|
|
|
|
test("api section scanning ignores keywords in literals, comments, and nested objects", () => {
|
|
const source = `
|
|
// request { body { forged: string } }
|
|
response {
|
|
return { label: "request { not a section }", nested: { body: true } }
|
|
}
|
|
`;
|
|
expect(hasRequestSection(source)).toBe(false);
|
|
expect(parseApiSections(source)?.response).toContain("nested");
|
|
});
|
|
|
|
test("api entries normalize methods and reject malformed request fields", () => {
|
|
expect(
|
|
parseApiEntries(`lookup get /users/:id {
|
|
response { return data }
|
|
}`)[0],
|
|
).toMatchObject({
|
|
name: "lookup",
|
|
method: "GET",
|
|
path: "/users/:id",
|
|
});
|
|
expect(() =>
|
|
parseApiSections("request { body { missingType } } response { return data }"),
|
|
).toThrow('Expected "name: type"');
|
|
});
|