test(harness): add fileClient default helper injections
This commit is contained in:
@@ -89,6 +89,10 @@ const loadServiceModule = (fileName, injected = {}) => {
|
||||
return injected.axios(config).then((response) => response.data);
|
||||
};
|
||||
|
||||
const defaultGetFileJson = (url) => {
|
||||
return defaultGetJson(url);
|
||||
};
|
||||
|
||||
const defaultBuildHashedQueryUrl = async (queryUrl) => {
|
||||
if (!injected.axios || !injected.axios.get) {
|
||||
throw new Error(
|
||||
@@ -103,6 +107,25 @@ const loadServiceModule = (fileName, injected = {}) => {
|
||||
return queryUrl + hashResponse.data.hash;
|
||||
};
|
||||
|
||||
const defaultGetSignedFileJson = async (queryUrl) => {
|
||||
const hashedUrl = await (
|
||||
injected.buildHashedQueryUrl || defaultBuildHashedQueryUrl
|
||||
)(queryUrl);
|
||||
|
||||
return (injected.requestJson || defaultRequestJson)({
|
||||
method: "get",
|
||||
url: hashedUrl
|
||||
});
|
||||
};
|
||||
|
||||
const defaultDownloadFileBlob = (url) => {
|
||||
return (injected.requestJson || defaultRequestJson)({
|
||||
method: "get",
|
||||
url,
|
||||
responseType: "blob"
|
||||
});
|
||||
};
|
||||
|
||||
const context = {
|
||||
module: { exports: {} },
|
||||
exports: {},
|
||||
@@ -118,6 +141,10 @@ const loadServiceModule = (fileName, injected = {}) => {
|
||||
},
|
||||
getJson: injected.getJson || defaultGetJson,
|
||||
requestJson: injected.requestJson || defaultRequestJson,
|
||||
getFileJson: injected.getFileJson || defaultGetFileJson,
|
||||
getSignedFileJson:
|
||||
injected.getSignedFileJson || defaultGetSignedFileJson,
|
||||
downloadFileBlob: injected.downloadFileBlob || defaultDownloadFileBlob,
|
||||
buildHashedQueryUrl:
|
||||
injected.buildHashedQueryUrl || defaultBuildHashedQueryUrl,
|
||||
...injected
|
||||
|
||||
Reference in New Issue
Block a user