TASK22224: harden file/static endpoint contracts and phase21 coverage
This commit is contained in:
@@ -3688,6 +3688,37 @@ test("getsipsmedia returns success contract", async () => {
|
||||
assert.strictEqual(res.state.jsonBody["@odata.count"], 4);
|
||||
});
|
||||
|
||||
test("getsipsmedia returns METHOD_NOT_ALLOWED for non-GET methods", async () => {
|
||||
const mod = loadModule("pages/api/endpoint/getsipsmedia_api.js", {
|
||||
respondSuccess: respondSuccessMock,
|
||||
respondError: respondErrorMock
|
||||
});
|
||||
|
||||
const req = { method: "POST", query: {} };
|
||||
const res = createRes();
|
||||
await mod.default(req, res);
|
||||
|
||||
assert.strictEqual(res.state.statusCode, 405);
|
||||
assert.strictEqual(res.state.jsonBody.error.code, "METHOD_NOT_ALLOWED");
|
||||
});
|
||||
|
||||
test("getappealtypesfornewappeal returns METHOD_NOT_ALLOWED for non-GET methods", async () => {
|
||||
const mod = loadModule(
|
||||
"pages/api/endpoint/getappealtypesfornewappeal_api.js",
|
||||
{
|
||||
respondSuccess: respondSuccessMock,
|
||||
respondError: respondErrorMock
|
||||
}
|
||||
);
|
||||
|
||||
const req = { method: "POST", query: {} };
|
||||
const res = createRes();
|
||||
await mod.default(req, res);
|
||||
|
||||
assert.strictEqual(res.state.statusCode, 405);
|
||||
assert.strictEqual(res.state.jsonBody.error.code, "METHOD_NOT_ALLOWED");
|
||||
});
|
||||
|
||||
const run = async () => {
|
||||
let passed = 0;
|
||||
for (const currentTest of tests) {
|
||||
|
||||
@@ -263,6 +263,175 @@ test("setupcontainer dependency failure returns SETUP_CONTAINER_FAILED", async (
|
||||
assert.strictEqual(res.state.jsonBody.error.code, "SETUP_CONTAINER_FAILED");
|
||||
});
|
||||
|
||||
test("downloadblob dependency failure returns DOWNLOAD_BLOB_FAILED", async () => {
|
||||
const mod = loadModule("pages/api/file/downloadblob.js", {
|
||||
nextConnect: createNextConnectMock(),
|
||||
middleware: () => {},
|
||||
hashAPIPath: () => "&hash=expected",
|
||||
respondError: respondErrorMock,
|
||||
downloadFile: async () => {
|
||||
throw new Error("download failed");
|
||||
}
|
||||
});
|
||||
|
||||
const req = {
|
||||
query: {
|
||||
container: "c1",
|
||||
casefolderID: "f1",
|
||||
blobname: "doc.pdf",
|
||||
hash: "expected"
|
||||
}
|
||||
};
|
||||
const res = createRes();
|
||||
await mod.default.handler(req, res);
|
||||
|
||||
assert.strictEqual(res.state.statusCode, 400);
|
||||
assert.strictEqual(res.state.jsonBody.error.code, "DOWNLOAD_BLOB_FAILED");
|
||||
});
|
||||
|
||||
test("generateappealpdfcopy returns INCIDENT_ID_REQUIRED when docProps missing", async () => {
|
||||
const mod = loadModule("pages/api/file/generateappealpdfcopy.js", {
|
||||
respondError: respondErrorMock,
|
||||
getCaseByID: async () => [],
|
||||
getPortalModuleDetails: async () => ({ value: [{}] }),
|
||||
getAppealPDFDocs: async () => [],
|
||||
getFormCollectionByID: () => ({ UrlName: "planningappeals78" }),
|
||||
getPickLists: async () => ({}),
|
||||
planningappeals78_pdf: () => ({}),
|
||||
other_pdf: () => ({}),
|
||||
pdf: () => ({ toBuffer: async () => Buffer.from("pdf") })
|
||||
});
|
||||
|
||||
const req = { body: {} };
|
||||
const res = createRes();
|
||||
await mod.default(req, res);
|
||||
|
||||
assert.strictEqual(res.state.statusCode, 400);
|
||||
assert.strictEqual(res.state.jsonBody.error.code, "INCIDENT_ID_REQUIRED");
|
||||
});
|
||||
|
||||
test("generateappealpdfcopy returns CASE_NOT_FOUND when case lookup is empty", async () => {
|
||||
const mod = loadModule("pages/api/file/generateappealpdfcopy.js", {
|
||||
respondError: respondErrorMock,
|
||||
getCaseByID: async () => [],
|
||||
getPortalModuleDetails: async () => ({ value: [{}] }),
|
||||
getAppealPDFDocs: async () => [],
|
||||
getFormCollectionByID: () => ({ UrlName: "planningappeals78" }),
|
||||
getPickLists: async () => ({}),
|
||||
planningappeals78_pdf: () => ({}),
|
||||
other_pdf: () => ({}),
|
||||
pdf: () => ({ toBuffer: async () => Buffer.from("pdf") })
|
||||
});
|
||||
|
||||
const req = { body: { docProps: "i1" } };
|
||||
const res = createRes();
|
||||
await mod.default(req, res);
|
||||
|
||||
assert.strictEqual(res.state.statusCode, 404);
|
||||
assert.strictEqual(res.state.jsonBody.error.code, "CASE_NOT_FOUND");
|
||||
});
|
||||
|
||||
test("generateappealpdfcopy returns FORM_COLLECTION_NOT_FOUND when collection is unresolved", async () => {
|
||||
const mod = loadModule("pages/api/file/generateappealpdfcopy.js", {
|
||||
respondError: respondErrorMock,
|
||||
getCaseByID: async () => [
|
||||
{
|
||||
pinswg_appealcasetype: 846040000,
|
||||
ticketnumber: "CAS-1",
|
||||
description: "desc"
|
||||
}
|
||||
],
|
||||
getPortalModuleDetails: async () => ({ value: [{}] }),
|
||||
getAppealPDFDocs: async () => [],
|
||||
getFormCollectionByID: () => null,
|
||||
getPickLists: async () => ({}),
|
||||
planningappeals78_pdf: () => ({}),
|
||||
other_pdf: () => ({}),
|
||||
pdf: () => ({ toBuffer: async () => Buffer.from("pdf") })
|
||||
});
|
||||
|
||||
const req = { body: { docProps: "i1" } };
|
||||
const res = createRes();
|
||||
await mod.default(req, res);
|
||||
|
||||
assert.strictEqual(res.state.statusCode, 400);
|
||||
assert.strictEqual(
|
||||
res.state.jsonBody.error.code,
|
||||
"FORM_COLLECTION_NOT_FOUND"
|
||||
);
|
||||
});
|
||||
|
||||
test("generateappealpdfcopy success returns pdf buffer and headers", async () => {
|
||||
const mod = loadModule("pages/api/file/generateappealpdfcopy.js", {
|
||||
respondError: respondErrorMock,
|
||||
getCaseByID: async () => [
|
||||
{
|
||||
pinswg_appealcasetype: 846040000,
|
||||
ticketnumber: "CAS-1",
|
||||
description: "desc"
|
||||
}
|
||||
],
|
||||
getPortalModuleDetails: async () => ({ value: [{}] }),
|
||||
getAppealPDFDocs: async () => [{ id: "d1" }],
|
||||
getFormCollectionByID: () => ({
|
||||
UrlName: "planningappeals78",
|
||||
LogicalCollectionName: "pinswg_planningappeals78s"
|
||||
}),
|
||||
getPickLists: async () => ({ a: 1 }),
|
||||
planningappeals78_pdf: () => ({ type: "pdfComponent" }),
|
||||
other_pdf: () => ({ type: "otherComponent" }),
|
||||
pdf: () => ({ toBuffer: async () => Buffer.from("pdf-content") })
|
||||
});
|
||||
|
||||
const req = { body: { docProps: "i1" } };
|
||||
const res = createRes();
|
||||
await mod.default(req, res);
|
||||
|
||||
assert.strictEqual(res.state.headers["content-type"], "application/pdf");
|
||||
assert.strictEqual(
|
||||
typeof res.state.headers["content-disposition"],
|
||||
"string"
|
||||
);
|
||||
assert.strictEqual(res.state.sentBody.toString(), "pdf-content");
|
||||
});
|
||||
|
||||
test("generateappealpdfcopy catch path returns APPEAL_PDF_COPY_GENERATION_FAILED", async () => {
|
||||
const mod = loadModule("pages/api/file/generateappealpdfcopy.js", {
|
||||
respondError: respondErrorMock,
|
||||
getCaseByID: async () => [
|
||||
{
|
||||
pinswg_appealcasetype: 846040000,
|
||||
ticketnumber: "CAS-1",
|
||||
description: "desc"
|
||||
}
|
||||
],
|
||||
getPortalModuleDetails: async () => ({ value: [{}] }),
|
||||
getAppealPDFDocs: async () => [{ id: "d1" }],
|
||||
getFormCollectionByID: () => ({
|
||||
UrlName: "planningappeals78",
|
||||
LogicalCollectionName: "pinswg_planningappeals78s"
|
||||
}),
|
||||
getPickLists: async () => ({ a: 1 }),
|
||||
planningappeals78_pdf: () => ({ type: "pdfComponent" }),
|
||||
other_pdf: () => ({ type: "otherComponent" }),
|
||||
pdf: () => ({
|
||||
toBuffer: async () => {
|
||||
throw new Error("pdf failure");
|
||||
}
|
||||
})
|
||||
});
|
||||
|
||||
const req = { body: { docProps: "i1" } };
|
||||
const res = createRes();
|
||||
await mod.default(req, res);
|
||||
|
||||
assert.strictEqual(res.state.statusCode, 400);
|
||||
assert.strictEqual(
|
||||
res.state.jsonBody.error.code,
|
||||
"APPEAL_PDF_COPY_GENERATION_FAILED"
|
||||
);
|
||||
});
|
||||
|
||||
const run = async () => {
|
||||
let passed = 0;
|
||||
for (const currentTest of tests) {
|
||||
|
||||
Reference in New Issue
Block a user