feat: add PDF options validation to demo route (TDD)
All checks were successful
Build & Deploy to Staging / Build & Deploy to Staging (push) Successful in 14m58s

This commit is contained in:
Hoid 2026-03-01 08:06:55 +01:00
parent a91b4c53a9
commit ecc7b9640c
2 changed files with 68 additions and 4 deletions

View file

@ -83,6 +83,42 @@ describe("POST /v1/demo/html", () => {
expect(calledHtml).toContain("DEMO");
expect(calledHtml).toContain("docfast.dev");
});
it("returns 400 for invalid scale", async () => {
const res = await request(app)
.post("/v1/demo/html")
.set("content-type", "application/json")
.send({ html: "<h1>Hello</h1>", scale: 99 });
expect(res.status).toBe(400);
expect(res.body.error).toMatch(/scale/);
});
it("returns 400 for invalid format", async () => {
const res = await request(app)
.post("/v1/demo/html")
.set("content-type", "application/json")
.send({ html: "<h1>Hello</h1>", format: "INVALID" });
expect(res.status).toBe(400);
expect(res.body.error).toMatch(/format/);
});
it("returns 400 for non-boolean landscape", async () => {
const res = await request(app)
.post("/v1/demo/html")
.set("content-type", "application/json")
.send({ html: "<h1>Hello</h1>", landscape: "yes" });
expect(res.status).toBe(400);
expect(res.body.error).toMatch(/landscape/);
});
it("returns 400 for invalid margin", async () => {
const res = await request(app)
.post("/v1/demo/html")
.set("content-type", "application/json")
.send({ html: "<h1>Hello</h1>", margin: "10px" });
expect(res.status).toBe(400);
expect(res.body.error).toMatch(/margin/);
});
});
describe("POST /v1/demo/markdown", () => {
@ -145,4 +181,22 @@ describe("POST /v1/demo/markdown", () => {
expect(calledHtml).toContain("DEMO");
expect(calledHtml).toContain("docfast.dev");
});
it("returns 400 for invalid scale", async () => {
const res = await request(app)
.post("/v1/demo/markdown")
.set("content-type", "application/json")
.send({ markdown: "# Hello", scale: 99 });
expect(res.status).toBe(400);
expect(res.body.error).toMatch(/scale/);
});
it("returns 400 for invalid format", async () => {
const res = await request(app)
.post("/v1/demo/markdown")
.set("content-type", "application/json")
.send({ markdown: "# Hello", format: "INVALID" });
expect(res.status).toBe(400);
expect(res.body.error).toMatch(/format/);
});
});