feat: validate PDF options with TDD tests
Some checks failed
Build & Deploy to Staging / Build & Deploy to Staging (push) Failing after 9m38s

This commit is contained in:
OpenClaw 2026-02-28 14:05:32 +01:00
parent 0e03e39ec7
commit f89a3181f7
4 changed files with 335 additions and 0 deletions

View file

@ -182,3 +182,66 @@ describe("POST /v1/convert/url", () => {
expect(res.headers["content-type"]).toMatch(/application\/pdf/);
});
});
describe("PDF option validation (all endpoints)", () => {
const endpoints = [
{ path: "/v1/convert/html", body: { html: "<h1>Hi</h1>" } },
{ path: "/v1/convert/markdown", body: { markdown: "# Hi" } },
];
for (const { path, body } of endpoints) {
it(`${path} returns 400 for invalid scale`, async () => {
const res = await request(app)
.post(path)
.set("content-type", "application/json")
.send({ ...body, scale: 5 });
expect(res.status).toBe(400);
expect(res.body.error).toContain("scale");
});
it(`${path} returns 400 for invalid format`, async () => {
const res = await request(app)
.post(path)
.set("content-type", "application/json")
.send({ ...body, format: "B5" });
expect(res.status).toBe(400);
expect(res.body.error).toContain("format");
});
it(`${path} returns 400 for non-boolean landscape`, async () => {
const res = await request(app)
.post(path)
.set("content-type", "application/json")
.send({ ...body, landscape: "yes" });
expect(res.status).toBe(400);
expect(res.body.error).toContain("landscape");
});
it(`${path} returns 400 for invalid pageRanges`, async () => {
const res = await request(app)
.post(path)
.set("content-type", "application/json")
.send({ ...body, pageRanges: "abc" });
expect(res.status).toBe(400);
expect(res.body.error).toContain("pageRanges");
});
it(`${path} returns 400 for invalid margin`, async () => {
const res = await request(app)
.post(path)
.set("content-type", "application/json")
.send({ ...body, margin: "1cm" });
expect(res.status).toBe(400);
expect(res.body.error).toContain("margin");
});
}
it("/v1/convert/url returns 400 for invalid scale", async () => {
const res = await request(app)
.post("/v1/convert/url")
.set("content-type", "application/json")
.send({ url: "https://example.com", scale: 5 });
expect(res.status).toBe(400);
expect(res.body.error).toContain("scale");
});
});