TASK22224: larger parity bundle for reps and upload handlers
This commit is contained in:
@@ -51,6 +51,38 @@ test("upload handler returns INVALID_HASH for wrong hash", async () => {
|
||||
assert.strictEqual(res.state.jsonBody.error.code, "INVALID_HASH");
|
||||
});
|
||||
|
||||
test("upload handler accepts alternate canonical hash candidate", async () => {
|
||||
const mod = loadModule("pages/api/file/upload.js", {
|
||||
nextConnect: createNextConnectMock(),
|
||||
middleware: () => {},
|
||||
hashAPIPath: (queryPath) =>
|
||||
queryPath === "/api/file/upload?"
|
||||
? "?hash=expected"
|
||||
: "?hash=other",
|
||||
respondError: respondErrorMock,
|
||||
respondSuccess: respondSuccessMock,
|
||||
createBlob: async () => ({ id: "blob-alt" }),
|
||||
createRepBlob: async () => ({ id: "rep-alt" })
|
||||
});
|
||||
|
||||
const req = {
|
||||
query: { hash: "expected" },
|
||||
body: {
|
||||
appealData: { key: "value" },
|
||||
containerID: ["c1"],
|
||||
casefolderID: ["f1"],
|
||||
repOrAppeal: false
|
||||
}
|
||||
};
|
||||
const res = createRes();
|
||||
await mod.default.handler(req, res);
|
||||
|
||||
assert.strictEqual(res.state.statusCode, 200);
|
||||
assert.deepStrictEqual(JSON.parse(JSON.stringify(res.state.jsonBody)), {
|
||||
data: { id: "blob-alt" }
|
||||
});
|
||||
});
|
||||
|
||||
test("deleteblob handler returns MISSING_REQUIRED_QUERY when blobname missing", async () => {
|
||||
const mod = loadModule("pages/api/file/deleteblob.js", {
|
||||
nextConnect: createNextConnectMock(),
|
||||
@@ -375,6 +407,84 @@ test("getrepsblob handler dependency failure returns GET_REPS_BLOB_FAILED", asyn
|
||||
assert.strictEqual(res.state.jsonBody.error.code, "GET_REPS_BLOB_FAILED");
|
||||
});
|
||||
|
||||
test("getrepsblob handler accepts encoded container hash variant", async () => {
|
||||
const mod = loadModule("pages/api/file/getrepsblob.js", {
|
||||
nextConnect: createNextConnectMock(),
|
||||
middleware: () => {},
|
||||
hashAPIPath: (queryPath) =>
|
||||
queryPath.includes("container=cont%2F1")
|
||||
? "&hash=expected"
|
||||
: "&hash=other",
|
||||
respondError: respondErrorMock,
|
||||
respondSuccess: respondSuccessMock,
|
||||
consoleLogger: () => {},
|
||||
getRepsBlobs: async () => [{ path: "cont/rep1.json" }],
|
||||
downloadAllRepsFiles: async () => ({ value: [{ id: "r-encoded" }] })
|
||||
});
|
||||
|
||||
const req = {
|
||||
query: { container: "cont/1", 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: [{ id: "r-encoded" }]
|
||||
});
|
||||
});
|
||||
|
||||
test("uploadsinglefile handler returns HASH_REQUIRED when hash missing", async () => {
|
||||
const mod = loadModule("pages/api/file/uploadsinglefile.js", {
|
||||
nextConnect: createNextConnectMock(),
|
||||
middleware: () => {},
|
||||
hashAPIPath: () => "?hash=expected",
|
||||
respondError: respondErrorMock,
|
||||
respondSuccess: respondSuccessMock,
|
||||
consoleLogger: () => {},
|
||||
uploadSingleFile: async () => ({ uploaded: 0 }),
|
||||
fileTypeFromBuffer: async () => ({ mime: "application/pdf" }),
|
||||
fs: { readFileSync: () => Buffer.from("x") }
|
||||
});
|
||||
|
||||
const req = { query: {}, body: {}, files: {} };
|
||||
const res = createRes();
|
||||
await mod.default.handler(req, res);
|
||||
|
||||
assert.strictEqual(res.state.statusCode, 400);
|
||||
assert.strictEqual(res.state.jsonBody.error.code, "HASH_REQUIRED");
|
||||
});
|
||||
|
||||
test("uploadsinglefile handler dependency failure returns UPLOAD_SINGLE_FILE_FAILED", async () => {
|
||||
const mod = loadModule("pages/api/file/uploadsinglefile.js", {
|
||||
nextConnect: createNextConnectMock(),
|
||||
middleware: () => {},
|
||||
hashAPIPath: () => "?hash=expected",
|
||||
respondError: respondErrorMock,
|
||||
respondSuccess: respondSuccessMock,
|
||||
consoleLogger: () => {},
|
||||
uploadSingleFile: async () => {
|
||||
throw new Error("upload failed");
|
||||
},
|
||||
fileTypeFromBuffer: async () => ({ mime: "application/pdf" }),
|
||||
fs: { readFileSync: () => Buffer.from("x") }
|
||||
});
|
||||
|
||||
const req = {
|
||||
query: { hash: "expected" },
|
||||
body: { containerID: ["c1"], casefolderID: ["f1"] },
|
||||
files: {}
|
||||
};
|
||||
const res = createRes();
|
||||
await mod.default.handler(req, res);
|
||||
|
||||
assert.strictEqual(res.state.statusCode, 500);
|
||||
assert.strictEqual(
|
||||
res.state.jsonBody.error.code,
|
||||
"UPLOAD_SINGLE_FILE_FAILED"
|
||||
);
|
||||
});
|
||||
|
||||
test("getawaitingsubmissionfromblob handler success returns payload", async () => {
|
||||
const mod = loadModule("pages/api/file/getawaitingsubmissionfromblob.js", {
|
||||
nextConnect: createNextConnectMock(),
|
||||
|
||||
Reference in New Issue
Block a user