TASK22224: modernize generatepdf handlers

This commit is contained in:
2026-03-23 18:39:44 +00:00
parent 411190e403
commit cc4fb36439
4 changed files with 250 additions and 133 deletions
@@ -1350,6 +1350,78 @@ test("generateappealpdfcopy catch path returns APPEAL_PDF_COPY_GENERATION_FAILED
);
});
test("generatepdf catch path returns GENERATE_PDF_FAILED", async () => {
const { Readable } = require("stream");
const mod = loadModule("pages/api/file/generatepdf.js", {
respondError: respondErrorMock,
respondSuccess: respondSuccessMock,
hashAPIPath: () => "&hash=expected",
consoleLogger: () => {},
ReactPDF: {
renderToStream: async () => Readable.from(["pdf"])
},
createRepPDFBlob: async () => {
throw new Error("pdf write failed");
},
other_pdf: () => ({ type: "other" })
});
const req = {
query: { hash: "expected", download: "true" },
body: {
representationType: "Other",
repfile_name: "rep-file",
containerID: "c1",
casefolderID: "f1",
caseRef: "CAS-1"
}
};
const res = createRes();
await mod.default(req, res);
assert.strictEqual(res.state.statusCode, 400);
assert.strictEqual(res.state.jsonBody.error.code, "GENERATE_PDF_FAILED");
});
test("generateappealpdf catch path returns GENERATE_APPEAL_PDF_FAILED", async () => {
const mod = loadModule("pages/api/file/generateappealpdf.js", {
respondError: respondErrorMock,
respondSuccess: respondSuccessMock,
hashAPIPath: () => "&hash=expected",
getTempCaseBlob: async () => ({ ticketnumber: "CAS-1" }),
getProgressBlobs: async () => ({ path: "CAS-1/progress.json" }),
downloadProgressFile: async () => {
throw new Error("progress failed");
},
getPickLists: async () => ({}),
planningappeals78_pdf: () => ({ type: "planning" }),
other_pdf: () => ({ type: "other" }),
ReactPDF: {
renderToStream: async () => {
throw new Error("render failed");
}
}
});
const req = {
query: { hash: "expected", appealType: "846040000" },
body: {
containerID: "c1",
casefolderID: "f1",
caseRef: "CAS-1",
filesList: []
}
};
const res = createRes();
await mod.default(req, res);
assert.strictEqual(res.state.statusCode, 400);
assert.strictEqual(
res.state.jsonBody.error.code,
"GENERATE_APPEAL_PDF_FAILED"
);
});
const run = async () => {
let passed = 0;
for (const currentTest of tests) {