TASK22224: harden getbloblist and getprogressobjblob parity

This commit is contained in:
2026-03-23 17:45:47 +00:00
parent c84287be3c
commit ab50430493
3 changed files with 206 additions and 35 deletions
@@ -377,6 +377,138 @@ test("getbloblist handler returns INVALID_HASH for mismatch", async () => {
assert.strictEqual(res.state.jsonBody.error.code, "INVALID_HASH");
});
test("getbloblist handler accepts encoded casefolder hash variant", async () => {
const mod = loadModule("pages/api/file/getbloblist.js", {
nextConnect: createNextConnectMock(),
middleware: () => {},
hashAPIPath: (queryPath) =>
queryPath.includes("casefolderID=CASE%2FSUB")
? "&hash=expected"
: "&hash=other",
respondError: respondErrorMock,
respondSuccess: respondSuccessMock,
getBlobs: async () => ({ file: "a.pdf" }),
getRepsFilesBlobs: async () => ({ file: "rep.pdf" })
});
const req = {
query: {
container: "c1",
casefolderID: "CASE/SUB",
hash: "expected"
}
};
const res = createRes();
await mod.default.handler(req, res);
assert.strictEqual(res.state.statusCode, 200);
assert.deepStrictEqual(JSON.parse(JSON.stringify(res.state.jsonBody)), {
value: [{ file: "rep.pdf" }]
});
});
test("getbloblist handler dependency failure returns GET_BLOB_LIST_FAILED", async () => {
const mod = loadModule("pages/api/file/getbloblist.js", {
nextConnect: createNextConnectMock(),
middleware: () => {},
hashAPIPath: () => "&hash=expected",
respondError: respondErrorMock,
respondSuccess: respondSuccessMock,
getBlobs: async () => {
throw new Error("blob lookup failed");
},
getRepsFilesBlobs: async () => ({ file: "rep.pdf" })
});
const req = {
query: { container: "c1", casefolderID: "f1", hash: "expected" }
};
const res = createRes();
await mod.default.handler(req, res);
assert.strictEqual(res.state.statusCode, 400);
assert.strictEqual(res.state.jsonBody.error.code, "GET_BLOB_LIST_FAILED");
});
test("getprogressobjblob handler success returns payload", async () => {
const mod = loadModule("pages/api/file/getprogressobjblob.js", {
nextConnect: createNextConnectMock(),
middleware: () => {},
hashAPIPath: () => "&hash=expected",
respondError: respondErrorMock,
respondSuccess: respondSuccessMock,
getProgressBlobs: async () => ({ path: "CASE1/CASE1_appeal.json" }),
downloadProgressFile: async () => ({ id: "progress-1" })
});
const req = {
query: { container: "c1", casefolderID: "CASE1", hash: "expected" }
};
const res = createRes();
await mod.default.handler(req, res);
assert.strictEqual(res.state.statusCode, 200);
assert.deepStrictEqual(JSON.parse(JSON.stringify(res.state.jsonBody)), {
id: "progress-1"
});
});
test("getprogressobjblob handler accepts encoded casefolder hash variant", async () => {
const mod = loadModule("pages/api/file/getprogressobjblob.js", {
nextConnect: createNextConnectMock(),
middleware: () => {},
hashAPIPath: (queryPath) =>
queryPath.includes("casefolderID=CASE%2FSUB")
? "&hash=expected"
: "&hash=other",
respondError: respondErrorMock,
respondSuccess: respondSuccessMock,
getProgressBlobs: async () => ({ path: "CASE/SUB/CASE_appeal.json" }),
downloadProgressFile: async () => ({ id: "progress-2" })
});
const req = {
query: {
container: "c1",
casefolderID: "CASE/SUB",
hash: "expected"
}
};
const res = createRes();
await mod.default.handler(req, res);
assert.strictEqual(res.state.statusCode, 200);
assert.deepStrictEqual(JSON.parse(JSON.stringify(res.state.jsonBody)), {
id: "progress-2"
});
});
test("getprogressobjblob handler dependency failure returns GET_PROGRESS_OBJ_BLOB_FAILED", async () => {
const mod = loadModule("pages/api/file/getprogressobjblob.js", {
nextConnect: createNextConnectMock(),
middleware: () => {},
hashAPIPath: () => "&hash=expected",
respondError: respondErrorMock,
respondSuccess: respondSuccessMock,
getProgressBlobs: async () => {
throw new Error("progress lookup failed");
},
downloadProgressFile: async () => ({})
});
const req = {
query: { container: "c1", casefolderID: "CASE1", hash: "expected" }
};
const res = createRes();
await mod.default.handler(req, res);
assert.strictEqual(res.state.statusCode, 400);
assert.strictEqual(
res.state.jsonBody.error.code,
"GET_PROGRESS_OBJ_BLOB_FAILED"
);
});
test("setupcontainer handler returns MISSING_REQUIRED_QUERY when ident missing", async () => {
const mod = loadModule("pages/api/file/setupcontainer.js", {
nextConnect: createNextConnectMock(),