TASK22224: aggressive non-file parity bundle
This commit is contained in:
@@ -425,3 +425,54 @@ Validation:
|
|||||||
Follow-ups:
|
Follow-ups:
|
||||||
|
|
||||||
- Optional: apply equivalent modernization to any remaining relay-backed handlers outside `pages/api/file/` that still use raw axios promise chains and have no explicit phase21 contract assertions.
|
- Optional: apply equivalent modernization to any remaining relay-backed handlers outside `pages/api/file/` that still use raw axios promise chains and have no explicit phase21 contract assertions.
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
|
### CL-011: TASK22224 aggressive non-file bundle (email/admin/endpoint parity)
|
||||||
|
|
||||||
|
date: 2026-03-23
|
||||||
|
author: Cline
|
||||||
|
scope: `pages/api/email/{getmailinglist,getcaseref,notify}.js`, `pages/api/admin/{getnewappeals_api,getlatestdocuments_api}.js`, `pages/api/endpoint/getportallogin_api.js`, `tests/phase21/endpoint-handler-contract.test.cjs`
|
||||||
|
type: change
|
||||||
|
rationale: Execute requested aggressive bundling for remaining non-file modernization/parity candidates: remove legacy promise chains and improve hash compatibility on login endpoint while preserving existing contracts.
|
||||||
|
impact: Improves consistency and resilience across email/admin/endpoint routes with no contract regressions; adds encoded hash-variant compatibility for portal login hash checks.
|
||||||
|
status: completed
|
||||||
|
|
||||||
|
Summary:
|
||||||
|
|
||||||
|
- `pages/api/email/getmailinglist.js`
|
||||||
|
- converted axios `.then/.catch` to `try/catch`
|
||||||
|
- preserved flattening behavior and error contract `MAILING_LIST_FETCH_FAILED`
|
||||||
|
- `pages/api/email/getcaseref.js`
|
||||||
|
- converted axios `.then/.catch` to `try/catch`
|
||||||
|
- preserved flattening behavior and error contract `CASE_REF_FETCH_FAILED`
|
||||||
|
- `pages/api/email/notify.js`
|
||||||
|
- converted notify client `.then/.catch` to `try/catch`
|
||||||
|
- preserved success payload and error contract `EMAIL_NOTIFY_FAILED`
|
||||||
|
- `pages/api/admin/getnewappeals_api.js`
|
||||||
|
- removed unused `CryptoJS` import
|
||||||
|
- converted axios `.then/.catch` to `try/catch`
|
||||||
|
- preserved `@odata.nextLink` normalization and error contract `ADMIN_NEW_APPEALS_FETCH_FAILED`
|
||||||
|
- `pages/api/admin/getlatestdocuments_api.js`
|
||||||
|
- converted axios `.then/.catch` to `try/catch`
|
||||||
|
- preserved flatten/enrich behavior and error contract `ADMIN_LATEST_DOCS_FETCH_FAILED`
|
||||||
|
- `pages/api/endpoint/getportallogin_api.js`
|
||||||
|
- retained required query/hash guards
|
||||||
|
- expanded hash validation to accept raw + encoded `emailAddress` query-path candidates
|
||||||
|
- preserved error contract `PORTAL_LOGIN_FETCH_FAILED`
|
||||||
|
- phase21 endpoint tests expanded:
|
||||||
|
- `getportallogin` encoded hash variant success path
|
||||||
|
- `getnewappeals_api` catch contract
|
||||||
|
- `getlatestdocuments_api` catch contract
|
||||||
|
|
||||||
|
Validation:
|
||||||
|
|
||||||
|
- `node tests/phase21/api-contract-slice1.test.cjs` -> pass
|
||||||
|
- helper: 4/4
|
||||||
|
- file-handler: 49/49
|
||||||
|
- email-handler: 12/12
|
||||||
|
- endpoint-handler: 152/152
|
||||||
|
|
||||||
|
Follow-ups:
|
||||||
|
|
||||||
|
- Remaining major modernization candidate is `pages/api/file/generateappealpdf.js` (+ optional `pages/api/file/generatepdf.js`) if we continue final closure slices.
|
||||||
|
|||||||
@@ -43,18 +43,18 @@ const encryptDocReference = (documentRef) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default async function ApiProxy(req, res) {
|
export default async function ApiProxy(req, res) {
|
||||||
var pageNumber = req.query.pageNumber || 1;
|
const pageNumber = req.query.pageNumber || 1;
|
||||||
var token = await getToken();
|
const token = await getToken();
|
||||||
|
|
||||||
var orderby = req.query.orderby || "createdon";
|
const orderby = req.query.orderby || "createdon";
|
||||||
var fieldSort = req.query.fieldSort || "desc";
|
const fieldSort = req.query.fieldSort || "desc";
|
||||||
var showNumberOfRecords = req.query.showNumberOfRecords || 10;
|
const showNumberOfRecords = req.query.showNumberOfRecords || 10;
|
||||||
var documentType = req.query.documentType || "all";
|
const documentType = req.query.documentType || "all";
|
||||||
var documentOrigin = req.query.documentOrigin || "all";
|
const documentOrigin = req.query.documentOrigin || "all";
|
||||||
var numberOfWeeks = req.query.numberWeeks || 1;
|
const numberOfWeeks = req.query.numberWeeks || 1;
|
||||||
|
|
||||||
var docTypeQueryString = "";
|
let docTypeQueryString = "";
|
||||||
var docOriginQueryString = "";
|
let docOriginQueryString = "";
|
||||||
|
|
||||||
if (documentType != "all") {
|
if (documentType != "all") {
|
||||||
if (documentType.indexOf(",") >= 0) {
|
if (documentType.indexOf(",") >= 0) {
|
||||||
@@ -108,7 +108,7 @@ export default async function ApiProxy(req, res) {
|
|||||||
return resultDate.toISOString().replace(/\.000Z$/, "Z"); // format as 'YYYY-MM-DDT00:00:00Z'
|
return resultDate.toISOString().replace(/\.000Z$/, "Z"); // format as 'YYYY-MM-DDT00:00:00Z'
|
||||||
}
|
}
|
||||||
|
|
||||||
var queryUrl =
|
const queryUrl =
|
||||||
"pinswg_documents?$select=pinswg_name,createdon,pinswg_publishtoweb,_pinswg_documentids_value,pinswg_isharedocumentlocations,pinswg_isharedocumentreference,pinswg_uploadurl,pinswg_uploadstatus,pinswg_origin&$filter=createdon ge " +
|
"pinswg_documents?$select=pinswg_name,createdon,pinswg_publishtoweb,_pinswg_documentids_value,pinswg_isharedocumentlocations,pinswg_isharedocumentreference,pinswg_uploadurl,pinswg_uploadstatus,pinswg_origin&$filter=createdon ge " +
|
||||||
daysAgoISO(numberOfWeeks) +
|
daysAgoISO(numberOfWeeks) +
|
||||||
docTypeQueryString +
|
docTypeQueryString +
|
||||||
@@ -131,40 +131,37 @@ export default async function ApiProxy(req, res) {
|
|||||||
"\n==========================================\n"
|
"\n==========================================\n"
|
||||||
);
|
);
|
||||||
|
|
||||||
var apiResponse = axios
|
try {
|
||||||
.get(
|
const { data } = await axios.get(
|
||||||
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
||||||
azureHeadersPagedCustom(token.access_token, showNumberOfRecords)
|
azureHeadersPagedCustom(token.access_token, showNumberOfRecords)
|
||||||
)
|
);
|
||||||
.then(({ data }) => {
|
|
||||||
let flattened = data.value.map((r) => ({
|
|
||||||
...r,
|
|
||||||
ticketnumber: r.pinswg_DocumentIds?.ticketnumber || null,
|
|
||||||
publishtoweb: r.pinswg_DocumentIds?.pinswg_publishtoweb || null
|
|
||||||
}));
|
|
||||||
|
|
||||||
data.value = flattened;
|
const flattened = data.value.map((r) => ({
|
||||||
data.value.forEach(function (element) {
|
...r,
|
||||||
element.pinswg_hashlink = encryptDocReference(
|
ticketnumber: r.pinswg_DocumentIds?.ticketnumber || null,
|
||||||
element.pinswg_isharedocumentreference
|
publishtoweb: r.pinswg_DocumentIds?.pinswg_publishtoweb || null
|
||||||
);
|
}));
|
||||||
});
|
|
||||||
|
|
||||||
var dataStr;
|
data.value = flattened;
|
||||||
|
data.value.forEach(function (element) {
|
||||||
_.has(data, "@odata.nextLink") == true &&
|
element.pinswg_hashlink = encryptDocReference(
|
||||||
((dataStr = JSON.stringify(data["@odata.nextLink"])),
|
element.pinswg_isharedocumentreference
|
||||||
(data["@odata.nextLink"] = dataStr.split("/v8.2/")[1]));
|
);
|
||||||
return respondSuccess(res, data);
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
consoleLogger(error);
|
|
||||||
return respondError(res, {
|
|
||||||
status: 400,
|
|
||||||
code: "ADMIN_LATEST_DOCS_FETCH_FAILED",
|
|
||||||
message: "Failed to fetch latest documents"
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return apiResponse;
|
let dataStr;
|
||||||
|
|
||||||
|
_.has(data, "@odata.nextLink") == true &&
|
||||||
|
((dataStr = JSON.stringify(data["@odata.nextLink"])),
|
||||||
|
(data["@odata.nextLink"] = dataStr.split("/v8.2/")[1]));
|
||||||
|
return respondSuccess(res, data);
|
||||||
|
} catch (error) {
|
||||||
|
consoleLogger(error);
|
||||||
|
return respondError(res, {
|
||||||
|
status: 400,
|
||||||
|
code: "ADMIN_LATEST_DOCS_FETCH_FAILED",
|
||||||
|
message: "Failed to fetch latest documents"
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,6 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
import CryptoJS from "crypto-js";
|
|
||||||
import _ from "lodash";
|
import _ from "lodash";
|
||||||
import { azureHeadersPagedCustom } from "../../../actions/core/headers";
|
import { azureHeadersPagedCustom } from "../../../actions/core/headers";
|
||||||
import { getToken } from "../../../actions/core/token";
|
import { getToken } from "../../../actions/core/token";
|
||||||
@@ -29,15 +28,14 @@ const WEBAPI_URL =
|
|||||||
"https://dev-pedw-ns.servicebus.windows.net/dev-pedw-hc/";
|
"https://dev-pedw-ns.servicebus.windows.net/dev-pedw-hc/";
|
||||||
|
|
||||||
export default async function ApiProxy(req, res) {
|
export default async function ApiProxy(req, res) {
|
||||||
var searchString = req.query.searchString;
|
const pageNumber = req.query.pageNumber || 1;
|
||||||
var pageNumber = req.query.pageNumber || 1;
|
const token = await getToken();
|
||||||
var token = await getToken();
|
|
||||||
|
|
||||||
var orderby = req.query.orderby || "createdon";
|
const orderby = req.query.orderby || "createdon";
|
||||||
var fieldSort = req.query.fieldSort || "desc";
|
const fieldSort = req.query.fieldSort || "desc";
|
||||||
var showNumberOfRecords = req.query.showNumberOfRecords || 10;
|
const showNumberOfRecords = req.query.showNumberOfRecords || 10;
|
||||||
|
|
||||||
var queryUrl =
|
const queryUrl =
|
||||||
"incidents?$select=caseorigincode,pinswg_publishtoweb,modifiedon,description,numberofchildincidents,_accountid_value,_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value,pinswg_lpareference,pinswg_appellantagent,pinswg_appellantfirstname,pinswg_appellantlastname&$expand=primarycontactid($select=fullname)&$orderby=" +
|
"incidents?$select=caseorigincode,pinswg_publishtoweb,modifiedon,description,numberofchildincidents,_accountid_value,_customerid_value,_pinswg_associatedlpa_value,_ownerid_value,pinswg_appealcasetype,statuscode,ticketnumber,title, _primarycontactid_value,pinswg_lpareference,pinswg_appellantagent,pinswg_appellantfirstname,pinswg_appellantlastname&$expand=primarycontactid($select=fullname)&$orderby=" +
|
||||||
orderby +
|
orderby +
|
||||||
" " +
|
" " +
|
||||||
@@ -55,26 +53,23 @@ export default async function ApiProxy(req, res) {
|
|||||||
"\n==========================================\n"
|
"\n==========================================\n"
|
||||||
);
|
);
|
||||||
|
|
||||||
var apiResponse = axios
|
try {
|
||||||
.get(
|
const { data } = await axios.get(
|
||||||
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
||||||
azureHeadersPagedCustom(token.access_token, showNumberOfRecords)
|
azureHeadersPagedCustom(token.access_token, showNumberOfRecords)
|
||||||
)
|
);
|
||||||
.then(({ data }) => {
|
|
||||||
var dataStr;
|
|
||||||
_.has(data, "@odata.nextLink") == true &&
|
|
||||||
((dataStr = JSON.stringify(data["@odata.nextLink"])),
|
|
||||||
(data["@odata.nextLink"] = dataStr.split("/v8.2/")[1]));
|
|
||||||
return respondSuccess(res, data);
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
consoleLogger(error);
|
|
||||||
return respondError(res, {
|
|
||||||
status: 400,
|
|
||||||
code: "ADMIN_NEW_APPEALS_FETCH_FAILED",
|
|
||||||
message: "Failed to fetch new appeals"
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
return apiResponse;
|
let dataStr;
|
||||||
|
_.has(data, "@odata.nextLink") == true &&
|
||||||
|
((dataStr = JSON.stringify(data["@odata.nextLink"])),
|
||||||
|
(data["@odata.nextLink"] = dataStr.split("/v8.2/")[1]));
|
||||||
|
return respondSuccess(res, data);
|
||||||
|
} catch (error) {
|
||||||
|
consoleLogger(error);
|
||||||
|
return respondError(res, {
|
||||||
|
status: 400,
|
||||||
|
code: "ADMIN_NEW_APPEALS_FETCH_FAILED",
|
||||||
|
message: "Failed to fetch new appeals"
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,27 +22,25 @@ function flattenWatchlistEntry(entry) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default async function ApiProxy(req, res) {
|
export default async function ApiProxy(req, res) {
|
||||||
var token = await getToken();
|
const token = await getToken();
|
||||||
|
|
||||||
var queryUrl =
|
const queryUrl =
|
||||||
"pinswg_watchlists?$count=true&$filter=pinswg_emailnotifications ne null&$expand=pinswg_Contact($select=contactid,emailaddress1)&$select=pinswg_emailnotifications,_pinswg_watchedcase_value";
|
"pinswg_watchlists?$count=true&$filter=pinswg_emailnotifications ne null&$expand=pinswg_Contact($select=contactid,emailaddress1)&$select=pinswg_emailnotifications,_pinswg_watchedcase_value";
|
||||||
|
|
||||||
return axios
|
try {
|
||||||
.get(
|
const { data } = await axios.get(
|
||||||
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
||||||
azureHeaders(token.access_token)
|
azureHeaders(token.access_token)
|
||||||
)
|
);
|
||||||
.then(({ data }) => {
|
const flattenedResults = data.value.map(flattenWatchlistEntry);
|
||||||
const flattenedResults = data.value.map(flattenWatchlistEntry);
|
|
||||||
|
|
||||||
return respondSuccess(res, flattenedResults);
|
return respondSuccess(res, flattenedResults);
|
||||||
})
|
} catch (error) {
|
||||||
.catch((error) => {
|
consoleLogger(error);
|
||||||
consoleLogger(error);
|
return respondError(res, {
|
||||||
return respondError(res, {
|
status: 400,
|
||||||
status: 400,
|
code: "CASE_REF_FETCH_FAILED",
|
||||||
code: "CASE_REF_FETCH_FAILED",
|
message: "Failed to fetch case references"
|
||||||
message: "Failed to fetch case references"
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,27 +22,25 @@ function flattenWatchlistEntry(entry) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export default async function ApiProxy(req, res) {
|
export default async function ApiProxy(req, res) {
|
||||||
var token = await getToken();
|
const token = await getToken();
|
||||||
|
|
||||||
var queryUrl =
|
const queryUrl =
|
||||||
"pinswg_watchlists?$count=true&$filter=pinswg_emailnotifications ne null&$expand=pinswg_Contact($select=contactid,emailaddress1)&$select=pinswg_emailnotifications,_pinswg_watchedcase_value";
|
"pinswg_watchlists?$count=true&$filter=pinswg_emailnotifications ne null&$expand=pinswg_Contact($select=contactid,emailaddress1)&$select=pinswg_emailnotifications,_pinswg_watchedcase_value";
|
||||||
|
|
||||||
return axios
|
try {
|
||||||
.get(
|
const { data } = await axios.get(
|
||||||
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
|
||||||
azureHeaders(token.access_token)
|
azureHeaders(token.access_token)
|
||||||
)
|
);
|
||||||
.then(({ data }) => {
|
const flattenedResults = data.value.map(flattenWatchlistEntry);
|
||||||
const flattenedResults = data.value.map(flattenWatchlistEntry);
|
|
||||||
|
|
||||||
return respondSuccess(res, flattenedResults);
|
return respondSuccess(res, flattenedResults);
|
||||||
})
|
} catch (error) {
|
||||||
.catch((error) => {
|
consoleLogger(error);
|
||||||
consoleLogger(error);
|
return respondError(res, {
|
||||||
return respondError(res, {
|
status: 400,
|
||||||
status: 400,
|
code: "MAILING_LIST_FETCH_FAILED",
|
||||||
code: "MAILING_LIST_FETCH_FAILED",
|
message: "Failed to fetch mailing list"
|
||||||
message: "Failed to fetch mailing list"
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+14
-15
@@ -31,7 +31,7 @@ import { getPreferredLanguage } from "../../../actions/services/accountService";
|
|||||||
import { respondError, respondSuccess } from "../middleware/apiResponse";
|
import { respondError, respondSuccess } from "../middleware/apiResponse";
|
||||||
|
|
||||||
export default async function ApiProxy(req, res) {
|
export default async function ApiProxy(req, res) {
|
||||||
var data = req.body;
|
const data = req.body;
|
||||||
const emailAddress = sanitizeString(data?.emailAddress);
|
const emailAddress = sanitizeString(data?.emailAddress);
|
||||||
|
|
||||||
if (!isNonEmptyString(emailAddress)) {
|
if (!isNonEmptyString(emailAddress)) {
|
||||||
@@ -58,7 +58,7 @@ export default async function ApiProxy(req, res) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var NotifyClient = require("notifications-node-client").NotifyClient;
|
const NotifyClient = require("notifications-node-client").NotifyClient;
|
||||||
|
|
||||||
const notifyClient = new NotifyClient(process.env.NOTIFY_API_KEY);
|
const notifyClient = new NotifyClient(process.env.NOTIFY_API_KEY);
|
||||||
//const emailReplyToId = process.env.EMAIL_REPLY_TO_ID;
|
//const emailReplyToId = process.env.EMAIL_REPLY_TO_ID;
|
||||||
@@ -68,20 +68,19 @@ export default async function ApiProxy(req, res) {
|
|||||||
payload: redactSensitive(data)
|
payload: redactSensitive(data)
|
||||||
});
|
});
|
||||||
|
|
||||||
notifyClient
|
try {
|
||||||
.sendEmail(data.templateId, data.emailAddress, {
|
await notifyClient.sendEmail(data.templateId, data.emailAddress, {
|
||||||
personalisation: data.personalisation,
|
personalisation: data.personalisation,
|
||||||
reference: data.reference
|
reference: data.reference
|
||||||
})
|
|
||||||
.then(() => {
|
|
||||||
return respondSuccess(res, data);
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
consoleLogger(error);
|
|
||||||
return respondError(res, {
|
|
||||||
status: 400,
|
|
||||||
code: "EMAIL_NOTIFY_FAILED",
|
|
||||||
message: "Failed to send notify email"
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
return respondSuccess(res, data);
|
||||||
|
} catch (error) {
|
||||||
|
consoleLogger(error);
|
||||||
|
return respondError(res, {
|
||||||
|
status: 400,
|
||||||
|
code: "EMAIL_NOTIFY_FAILED",
|
||||||
|
message: "Failed to send notify email"
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,8 +49,16 @@ export default async function ApiProxy(req, res) {
|
|||||||
|
|
||||||
const checkquerypath =
|
const checkquerypath =
|
||||||
"/api/endpoint/getportallogin_api?emailAddress=" + emailAddress;
|
"/api/endpoint/getportallogin_api?emailAddress=" + emailAddress;
|
||||||
|
const encodedCheckquerypath =
|
||||||
|
"/api/endpoint/getportallogin_api?emailAddress=" +
|
||||||
|
encodeURIComponent(emailAddress);
|
||||||
|
|
||||||
if (hashAPIPath(checkquerypath) != "&hash=" + checkHash) {
|
const expectedHashCandidates = [
|
||||||
|
hashAPIPath(checkquerypath),
|
||||||
|
hashAPIPath(encodedCheckquerypath)
|
||||||
|
];
|
||||||
|
|
||||||
|
if (!expectedHashCandidates.includes("&hash=" + checkHash)) {
|
||||||
return respondError(res, {
|
return respondError(res, {
|
||||||
status: 400,
|
status: 400,
|
||||||
code: "INVALID_HASH",
|
code: "INVALID_HASH",
|
||||||
|
|||||||
@@ -323,6 +323,93 @@ test("getportallogin catch path returns PORTAL_LOGIN_FETCH_FAILED", async () =>
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test("getportallogin accepts encoded email hash variant", async () => {
|
||||||
|
const mod = loadModule("pages/api/endpoint/getportallogin_api.js", {
|
||||||
|
respondError: respondErrorMock,
|
||||||
|
respondSuccess: respondSuccessMock,
|
||||||
|
getToken: async () => ({ access_token: "token" }),
|
||||||
|
hashAPIPath: (input) =>
|
||||||
|
input && input.includes("emailAddress=user%2Btest%40local")
|
||||||
|
? "&hash=expected"
|
||||||
|
: "&hash=other",
|
||||||
|
azureHeadersPaged: () => ({}),
|
||||||
|
axios: {
|
||||||
|
get: async () => ({ data: { value: [{ contactid: "c1" }] } })
|
||||||
|
},
|
||||||
|
consoleLogger: () => {}
|
||||||
|
});
|
||||||
|
|
||||||
|
const req = {
|
||||||
|
query: { emailAddress: "user+test@local", hash: "expected" }
|
||||||
|
};
|
||||||
|
const res = createRes();
|
||||||
|
await mod.default(req, res);
|
||||||
|
|
||||||
|
assert.strictEqual(res.state.statusCode, 200);
|
||||||
|
assert.deepStrictEqual(JSON.parse(JSON.stringify(res.state.jsonBody)), {
|
||||||
|
value: [{ contactid: "c1" }]
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test("getnewappeals catch path returns ADMIN_NEW_APPEALS_FETCH_FAILED", async () => {
|
||||||
|
const mod = loadModule("pages/api/admin/getnewappeals_api.js", {
|
||||||
|
respondError: respondErrorMock,
|
||||||
|
respondSuccess: respondSuccessMock,
|
||||||
|
getToken: async () => ({ access_token: "token" }),
|
||||||
|
hashAPIPath: () => "&hash=expected",
|
||||||
|
azureHeadersPagedCustom: () => ({}),
|
||||||
|
axios: {
|
||||||
|
get: async () => {
|
||||||
|
throw new Error("admin new appeals failed");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
consoleLogger: () => {},
|
||||||
|
_: { has: () => false }
|
||||||
|
});
|
||||||
|
|
||||||
|
const req = { query: {} };
|
||||||
|
const res = createRes();
|
||||||
|
await mod.default(req, res);
|
||||||
|
|
||||||
|
assert.strictEqual(res.state.statusCode, 400);
|
||||||
|
assert.strictEqual(
|
||||||
|
res.state.jsonBody.error.code,
|
||||||
|
"ADMIN_NEW_APPEALS_FETCH_FAILED"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("getlatestdocuments catch path returns ADMIN_LATEST_DOCS_FETCH_FAILED", async () => {
|
||||||
|
const mod = loadModule("pages/api/admin/getlatestdocuments_api.js", {
|
||||||
|
respondError: respondErrorMock,
|
||||||
|
respondSuccess: respondSuccessMock,
|
||||||
|
getToken: async () => ({ access_token: "token" }),
|
||||||
|
hashAPIPath: () => "&hash=expected",
|
||||||
|
azureHeadersPagedCustom: () => ({}),
|
||||||
|
axios: {
|
||||||
|
get: async () => {
|
||||||
|
throw new Error("latest docs failed");
|
||||||
|
}
|
||||||
|
},
|
||||||
|
consoleLogger: () => {},
|
||||||
|
process: { env: { HASHKEY: "abc" } },
|
||||||
|
CryptoJS: {
|
||||||
|
HmacSHA256: () => ({ toString: () => "hash" }),
|
||||||
|
enc: { Hex: { parse: () => "parsed" } }
|
||||||
|
},
|
||||||
|
_: { has: () => false }
|
||||||
|
});
|
||||||
|
|
||||||
|
const req = { query: {} };
|
||||||
|
const res = createRes();
|
||||||
|
await mod.default(req, res);
|
||||||
|
|
||||||
|
assert.strictEqual(res.state.statusCode, 400);
|
||||||
|
assert.strictEqual(
|
||||||
|
res.state.jsonBody.error.code,
|
||||||
|
"ADMIN_LATEST_DOCS_FETCH_FAILED"
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
test("getportalloginproxy catch path returns PORTAL_LOGIN_PROXY_FETCH_FAILED", async () => {
|
test("getportalloginproxy catch path returns PORTAL_LOGIN_PROXY_FETCH_FAILED", async () => {
|
||||||
const mod = loadModule("pages/api/endpoint/getportalloginproxy_api.js", {
|
const mod = loadModule("pages/api/endpoint/getportalloginproxy_api.js", {
|
||||||
respondError: respondErrorMock,
|
respondError: respondErrorMock,
|
||||||
|
|||||||
Reference in New Issue
Block a user