TASK22269: delegate fileClient signed get/post to signedRequestClient
This commit is contained in:
@@ -24,8 +24,11 @@ const loadFileClientModule = (injected = {}) => {
|
||||
requestJson: async () => {
|
||||
throw new Error("requestJson not injected");
|
||||
},
|
||||
buildHashedQueryUrl: async () => {
|
||||
throw new Error("buildHashedQueryUrl not injected");
|
||||
getSignedJson: async () => {
|
||||
throw new Error("getSignedJson not injected");
|
||||
},
|
||||
postSignedJson: async () => {
|
||||
throw new Error("postSignedJson not injected");
|
||||
},
|
||||
...injected
|
||||
};
|
||||
@@ -56,15 +59,10 @@ test("clients/fileClient getFileJson delegates to getJson", async () => {
|
||||
|
||||
test("clients/fileClient getSignedFileJson signs url and requests json", async () => {
|
||||
const signedCalls = [];
|
||||
const requestCalls = [];
|
||||
|
||||
const mod = loadFileClientModule({
|
||||
buildHashedQueryUrl: async (queryUrl) => {
|
||||
getSignedJson: async (queryUrl) => {
|
||||
signedCalls.push(queryUrl);
|
||||
return queryUrl + "&hash=signed";
|
||||
},
|
||||
requestJson: async (config) => {
|
||||
requestCalls.push(config);
|
||||
return { deleted: true };
|
||||
}
|
||||
});
|
||||
@@ -77,11 +75,9 @@ test("clients/fileClient getSignedFileJson signs url and requests json", async (
|
||||
deleted: true
|
||||
});
|
||||
assert.strictEqual(signedCalls.length, 1);
|
||||
assert.strictEqual(requestCalls.length, 1);
|
||||
assert.strictEqual(requestCalls[0].method, "get");
|
||||
assert.strictEqual(
|
||||
requestCalls[0].url,
|
||||
"/api/file/deleteblobcase?container=a&casefolderID=b&hash=signed"
|
||||
signedCalls[0],
|
||||
"/api/file/deleteblobcase?container=a&casefolderID=b"
|
||||
);
|
||||
});
|
||||
|
||||
@@ -106,15 +102,12 @@ test("clients/fileClient downloadFileBlob requests blob response", async () => {
|
||||
|
||||
test("clients/fileClient postSignedFileJson signs url and posts payload", async () => {
|
||||
const signedCalls = [];
|
||||
const requestCalls = [];
|
||||
const postedCalls = [];
|
||||
|
||||
const mod = loadFileClientModule({
|
||||
buildHashedQueryUrl: async (queryUrl) => {
|
||||
postSignedJson: async (queryUrl, data, config) => {
|
||||
signedCalls.push(queryUrl);
|
||||
return queryUrl + "&hash=signed-post";
|
||||
},
|
||||
requestJson: async (config) => {
|
||||
requestCalls.push(config);
|
||||
postedCalls.push({ data, config });
|
||||
return { uploaded: true };
|
||||
}
|
||||
});
|
||||
@@ -132,18 +125,14 @@ test("clients/fileClient postSignedFileJson signs url and posts payload", async
|
||||
uploaded: true
|
||||
});
|
||||
assert.strictEqual(signedCalls.length, 1);
|
||||
assert.strictEqual(requestCalls.length, 1);
|
||||
assert.strictEqual(requestCalls[0].method, "post");
|
||||
assert.strictEqual(
|
||||
requestCalls[0].url,
|
||||
"/api/file/uploadsinglefile&hash=signed-post"
|
||||
);
|
||||
assert.strictEqual(postedCalls.length, 1);
|
||||
assert.strictEqual(signedCalls[0], "/api/file/uploadsinglefile");
|
||||
assert.deepStrictEqual(
|
||||
JSON.parse(JSON.stringify(requestCalls[0].data)),
|
||||
JSON.parse(JSON.stringify(postedCalls[0].data)),
|
||||
payload
|
||||
);
|
||||
assert.strictEqual(
|
||||
requestCalls[0].headers["content-type"],
|
||||
postedCalls[0].config.headers["content-type"],
|
||||
"multipart/form-data"
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user