22 lines
1 KiB
TypeScript
22 lines
1 KiB
TypeScript
|
|
import { describe, expect, it } from "vitest";
|
||
|
|
|
||
|
|
import { PdfPathError, resolvePublicPdfPath } from "@/lib/server-pdf";
|
||
|
|
|
||
|
|
// PLAN-STAGED.md D4 — guard ปฏิเสธ sentinel staged: ชัด ๆ (defense in depth)
|
||
|
|
// ก่อนหน้านี้ "staged:x.pdf" ผ่าน resolve ตกใน publicDir แล้วตายด้วย ENOENT เป็น 500 ดิบ
|
||
|
|
describe("resolvePublicPdfPath — sentinel staged: (N11)", () => {
|
||
|
|
it("โยน PdfPathError ไม่ใช่ ENOENT ทะลุเป็น 500", () => {
|
||
|
|
expect(() =>
|
||
|
|
resolvePublicPdfPath("staged:0d7e6a52-9a71-4d40-bd1c-b2e1a44ab133.pdf"),
|
||
|
|
).toThrow(PdfPathError);
|
||
|
|
expect(() =>
|
||
|
|
resolvePublicPdfPath("staged:0d7e6a52-9a71-4d40-bd1c-b2e1a44ab133.tif"),
|
||
|
|
).toThrow(PdfPathError);
|
||
|
|
});
|
||
|
|
|
||
|
|
it("path ปกติ (สัมพัทธ์ public/note) ยัง resolve ได้ตามเดิม", () => {
|
||
|
|
const p = resolvePublicPdfPath("/samples/demo.pdf");
|
||
|
|
expect(p.replace(/\\/g, "/")).toContain("public/note/samples/demo.pdf");
|
||
|
|
});
|
||
|
|
});
|