refactor(document): complete signed post flows via fileClient
This commit is contained in:
@@ -12,7 +12,7 @@ const loadFileClientModule = (injected = {}) => {
|
||||
source = source.replace(/import[\s\S]*?from\s+"[^"]+";\n?/g, "");
|
||||
source = source.replace(/export const\s+/g, "const ");
|
||||
source +=
|
||||
"\nmodule.exports = { getFileJson, getSignedFileJson, downloadFileBlob };\n";
|
||||
"\nmodule.exports = { getFileJson, getSignedFileJson, downloadFileBlob, postSignedFileJson };\n";
|
||||
|
||||
const context = {
|
||||
module: { exports: {} },
|
||||
@@ -104,6 +104,50 @@ test("clients/fileClient downloadFileBlob requests blob response", async () => {
|
||||
assert.strictEqual(requestCalls[0].url, "/api/file/downloadblob?x=1");
|
||||
});
|
||||
|
||||
test("clients/fileClient postSignedFileJson signs url and posts payload", async () => {
|
||||
const signedCalls = [];
|
||||
const requestCalls = [];
|
||||
|
||||
const mod = loadFileClientModule({
|
||||
buildHashedQueryUrl: async (queryUrl) => {
|
||||
signedCalls.push(queryUrl);
|
||||
return queryUrl + "&hash=signed-post";
|
||||
},
|
||||
requestJson: async (config) => {
|
||||
requestCalls.push(config);
|
||||
return { uploaded: true };
|
||||
}
|
||||
});
|
||||
|
||||
const payload = { name: "doc" };
|
||||
const result = await mod.postSignedFileJson(
|
||||
"/api/file/uploadsinglefile",
|
||||
payload,
|
||||
{
|
||||
headers: { "content-type": "multipart/form-data" }
|
||||
}
|
||||
);
|
||||
|
||||
assert.deepStrictEqual(JSON.parse(JSON.stringify(result)), {
|
||||
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.deepStrictEqual(
|
||||
JSON.parse(JSON.stringify(requestCalls[0].data)),
|
||||
payload
|
||||
);
|
||||
assert.strictEqual(
|
||||
requestCalls[0].headers["content-type"],
|
||||
"multipart/form-data"
|
||||
);
|
||||
});
|
||||
|
||||
const run = async () => {
|
||||
let passed = 0;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user