TASK22269: group migrate remaining account/portal signed GET flows
This commit is contained in:
@@ -134,6 +134,47 @@ test("portal/sendRepCompleteMessage rejects when hash signing fails before reque
|
||||
assert.strictEqual(logger.calls.length, 0);
|
||||
});
|
||||
|
||||
test("portal/sendRepCompleteMessage requests signed URL from shared signed helper", async () => {
|
||||
const axios = createAxiosMock();
|
||||
const logger = createLoggerMock();
|
||||
|
||||
const signedCalls = [];
|
||||
const requestCalls = [];
|
||||
|
||||
const portal = loadServiceModule("portalDirectService.js", {
|
||||
axios,
|
||||
BASE_URL: "",
|
||||
consoleLogger: logger.consoleLogger,
|
||||
buildSignedUrl: async (queryUrl) => {
|
||||
signedCalls.push(queryUrl);
|
||||
return `${queryUrl}&hash=signed-portal`;
|
||||
},
|
||||
requestJson: async (config) => {
|
||||
requestCalls.push(config);
|
||||
return { ok: true };
|
||||
}
|
||||
});
|
||||
|
||||
const result = await portal.sendRepCompleteMessage(
|
||||
"container-x",
|
||||
"CASE-99",
|
||||
"rep-a"
|
||||
);
|
||||
|
||||
assert.deepStrictEqual(normalize(result), { ok: true });
|
||||
assert.strictEqual(signedCalls.length, 1);
|
||||
assert.strictEqual(
|
||||
signedCalls[0],
|
||||
"/api/file/createrepcompletemessage_api?container=container-x&tempcaseref=CASE-99&repid=rep-a"
|
||||
);
|
||||
assert.strictEqual(requestCalls.length, 1);
|
||||
assert.strictEqual(requestCalls[0].method, "get");
|
||||
assert.strictEqual(
|
||||
requestCalls[0].url,
|
||||
"/api/file/createrepcompletemessage_api?container=container-x&tempcaseref=CASE-99&repid=rep-a&hash=signed-portal"
|
||||
);
|
||||
});
|
||||
|
||||
test("portal/deleteWatchedCases logs and returns undefined when signed delete fails", async () => {
|
||||
const axios = createAxiosMock();
|
||||
const logger = createLoggerMock();
|
||||
|
||||
@@ -256,9 +256,13 @@ test("account/getPortalLogin appends hash and returns res.data", async () => {
|
||||
return { data: { hash: "&hash=login123" } };
|
||||
}
|
||||
|
||||
return { data: { value: [{ id: "user-1" }] } };
|
||||
throw new Error("Unexpected get url: " + url);
|
||||
};
|
||||
|
||||
axios.requestHandler = async () => ({
|
||||
data: { value: [{ id: "user-1" }] }
|
||||
});
|
||||
|
||||
const account = loadServiceModule("accountDirectService.js", {
|
||||
axios,
|
||||
BASE_URL: "http://example.local",
|
||||
@@ -274,8 +278,9 @@ test("account/getPortalLogin appends hash and returns res.data", async () => {
|
||||
signCalls[0],
|
||||
"/api/endpoint/gethash_api?path=%2Fapi%2Fendpoint%2Fgetportallogin_api%3FemailAddress%3Dperson%40example.com"
|
||||
);
|
||||
assert.strictEqual(axios.calls[1].config.method, "get");
|
||||
assert.strictEqual(
|
||||
axios.calls[1].url,
|
||||
axios.calls[1].config.url,
|
||||
"http://example.local/api/endpoint/getportallogin_api?emailAddress=person@example.com&hash=login123"
|
||||
);
|
||||
});
|
||||
@@ -290,9 +295,11 @@ test("account/getPortalLogin returns JSON stringified error on failure", async (
|
||||
return { data: { hash: "&hash=err" } };
|
||||
}
|
||||
|
||||
return Promise.reject(error);
|
||||
throw new Error("Unexpected get url: " + url);
|
||||
};
|
||||
|
||||
axios.requestHandler = async () => Promise.reject(error);
|
||||
|
||||
const account = loadServiceModule("accountDirectService.js", {
|
||||
axios,
|
||||
BASE_URL: "",
|
||||
|
||||
@@ -107,6 +107,15 @@ const loadServiceModule = (fileName, injected = {}) => {
|
||||
return queryUrl + hashResponse.data.hash;
|
||||
};
|
||||
|
||||
const defaultBuildSignedUrl = async (queryUrl, config = {}) => {
|
||||
const { baseUrl = "" } = config;
|
||||
const hashedUrl = await (
|
||||
injected.buildHashedQueryUrl || defaultBuildHashedQueryUrl
|
||||
)(queryUrl);
|
||||
|
||||
return `${baseUrl}${hashedUrl}`;
|
||||
};
|
||||
|
||||
const defaultGetSignedFileJson = async (queryUrl) => {
|
||||
const hashedUrl = await (
|
||||
injected.buildHashedQueryUrl || defaultBuildHashedQueryUrl
|
||||
@@ -138,6 +147,33 @@ const loadServiceModule = (fileName, injected = {}) => {
|
||||
});
|
||||
};
|
||||
|
||||
const defaultGetSignedJson = async (queryUrl, config = {}) => {
|
||||
const { baseUrl, ...requestConfig } = config;
|
||||
const signedUrl = await (
|
||||
injected.buildSignedUrl || defaultBuildSignedUrl
|
||||
)(queryUrl, { baseUrl });
|
||||
|
||||
return (injected.requestJson || defaultRequestJson)({
|
||||
method: "get",
|
||||
url: signedUrl,
|
||||
...requestConfig
|
||||
});
|
||||
};
|
||||
|
||||
const defaultPostSignedJson = async (queryUrl, data, config = {}) => {
|
||||
const { baseUrl, ...requestConfig } = config;
|
||||
const signedUrl = await (
|
||||
injected.buildSignedUrl || defaultBuildSignedUrl
|
||||
)(queryUrl, { baseUrl });
|
||||
|
||||
return (injected.requestJson || defaultRequestJson)({
|
||||
method: "post",
|
||||
url: signedUrl,
|
||||
data,
|
||||
...requestConfig
|
||||
});
|
||||
};
|
||||
|
||||
const defaultBuildFileQuery = (pathValue, params = {}, options = {}) => {
|
||||
const { encode = false } = options;
|
||||
const entries = Object.entries(params).filter(([, value]) => {
|
||||
@@ -184,7 +220,10 @@ const loadServiceModule = (fileName, injected = {}) => {
|
||||
getSignedFileJson:
|
||||
injected.getSignedFileJson || defaultGetSignedFileJson,
|
||||
downloadFileBlob: injected.downloadFileBlob || defaultDownloadFileBlob,
|
||||
getSignedJson: injected.getSignedJson || defaultGetSignedJson,
|
||||
postSignedJson: injected.postSignedJson || defaultPostSignedJson,
|
||||
deleteSignedJson: injected.deleteSignedJson || defaultDeleteSignedJson,
|
||||
buildSignedUrl: injected.buildSignedUrl || defaultBuildSignedUrl,
|
||||
buildHashedQueryUrl:
|
||||
injected.buildHashedQueryUrl || defaultBuildHashedQueryUrl,
|
||||
buildFileQuery: injected.buildFileQuery || defaultBuildFileQuery,
|
||||
|
||||
Reference in New Issue
Block a user