TASK22211: normalize basic search endpoint contracts

This commit is contained in:
2026-03-23 11:23:07 +00:00
parent 9af541ac6b
commit b880364e51
5 changed files with 505 additions and 185 deletions
@@ -1,9 +1,9 @@
import axios from "axios"; import axios from "axios";
import CryptoJS from "crypto-js";
import { azureHeaders } from "../../../actions/core/headers"; import { azureHeaders } from "../../../actions/core/headers";
import { consoleLogger } from "../../../actions/core/logger"; import { consoleLogger } from "../../../actions/core/logger";
import { getToken } from "../../../actions/core/token"; import { getToken } from "../../../actions/core/token";
import { hashAPIPath } from "../../../actions/core/hash"; import { hashAPIPath } from "../../../actions/core/hash";
import { respondError, respondSuccess } from "../middleware/apiResponse";
const WEBAPI_URL = const WEBAPI_URL =
process.env.RELAY_ROOT || process.env.RELAY_ROOT ||
@@ -285,9 +285,11 @@ export default async function ApiProxy(req, res) {
let lpaRef = (req.query.lpaRef || "").trim(); let lpaRef = (req.query.lpaRef || "").trim();
if (!lpaRef) { if (!lpaRef) {
return res return respondError(res, {
.status(400) status: 400,
.json({ error: "Missing required query param: lpaRef" }); code: "LPA_REF_REQUIRED",
message: "lpaRef is required"
});
} }
// ✅ Escape single quotes for OData // ✅ Escape single quotes for OData
@@ -298,10 +300,6 @@ export default async function ApiProxy(req, res) {
// contains(tolower(pinswg_lpaapplicationreference), 'lowered search') // contains(tolower(pinswg_lpaapplicationreference), 'lowered search')
const lowered = lpaRef.toLowerCase(); const lowered = lpaRef.toLowerCase();
console.log(
`\n=== LPA REF SEARCH ===\nSearching for "${lpaRef}" (case-insensitive contains)\nAcross ${appealTypeArrayWithLpaRef.length} entity types\n======================\n`
);
const resultsPerType = await Promise.all( const resultsPerType = await Promise.all(
appealTypeArrayWithLpaRef.map(async (item) => { appealTypeArrayWithLpaRef.map(async (item) => {
// You can expand/select more fields if needed, but keep light for speed // You can expand/select more fields if needed, but keep light for speed
@@ -323,17 +321,6 @@ export default async function ApiProxy(req, res) {
`&$count=true` + `&$count=true` +
`&$orderby=modifiedon desc`; `&$orderby=modifiedon desc`;
console.log(
"\n------------------------------------------\n",
"Entity:",
item.LogicalCollectionName,
"\nQuery:",
queryUrl,
"\nFull:",
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
"\n------------------------------------------\n"
);
const { data } = await axios.get( const { data } = await axios.get(
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
azureHeaders(token.access_token) azureHeaders(token.access_token)
@@ -353,10 +340,6 @@ export default async function ApiProxy(req, res) {
] || null ] || null
})); }));
console.log(
`Returned ${normalized.length} records from ${item.LogicalCollectionName}`
);
return normalized; return normalized;
}) })
); );
@@ -372,9 +355,13 @@ export default async function ApiProxy(req, res) {
value: flattened value: flattened
}; };
return res.status(200).json(output); return respondSuccess(res, output);
} catch (error) { } catch (error) {
consoleLogger(error); consoleLogger(error);
return res.status(400).json(error); return respondError(res, {
status: 400,
code: "BASIC_SEARCH_LPA_REF_FETCH_FAILED",
message: "Failed to fetch basic search by lpa reference"
});
} }
} }
+49 -15
View File
@@ -30,30 +30,62 @@
*/ */
import axios from "axios"; import axios from "axios";
import CryptoJS from "crypto-js";
import { azureHeaders } from "../../../actions/core/headers"; import { azureHeaders } from "../../../actions/core/headers";
import { consoleLogger } from "../../../actions/core/logger"; import { consoleLogger } from "../../../actions/core/logger";
import { getToken } from "../../../actions/core/token"; import { getToken } from "../../../actions/core/token";
import { getSelectQuery } from "../../../actions/selectQueryTypes"; import { getSelectQuery } from "../../../actions/selectQueryTypes";
import { getNavigationPropertyByPrimaryAttribute } from "../../../components/utils"; import { getNavigationPropertyByPrimaryAttribute } from "../../../components/utils";
import { hashAPIPath } from "../../../actions/core/hash"; import { hashAPIPath } from "../../../actions/core/hash";
import { respondError, respondSuccess } from "../middleware/apiResponse";
const WEBAPI_URL = const WEBAPI_URL =
process.env.RELAY_ROOT || process.env.RELAY_ROOT ||
"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 appealTypeName = req.query.appealTypeName; const appealTypeName = req.query.appealTypeName;
var primaryIdAttribute = req.query.primaryIdAttribute; const primaryIdAttribute = req.query.primaryIdAttribute;
var incidentID = req.query.incidentID; const incidentID = req.query.incidentID;
var token = await getToken();
let navigationProperty = if (
typeof appealTypeName !== "string" ||
appealTypeName.trim().length === 0
) {
return respondError(res, {
status: 400,
code: "APPEAL_TYPE_NAME_REQUIRED",
message: "appealTypeName is required"
});
}
if (
typeof primaryIdAttribute !== "string" ||
primaryIdAttribute.trim().length === 0
) {
return respondError(res, {
status: 400,
code: "PRIMARY_ID_ATTRIBUTE_REQUIRED",
message: "primaryIdAttribute is required"
});
}
if (typeof incidentID !== "string" || incidentID.trim().length === 0) {
return respondError(res, {
status: 400,
code: "INCIDENT_ID_REQUIRED",
message: "incidentID is required"
});
}
try {
const token = await getToken();
const navigationProperty =
getNavigationPropertyByPrimaryAttribute( getNavigationPropertyByPrimaryAttribute(
primaryIdAttribute primaryIdAttribute
).NavigationProperty; ).NavigationProperty;
var queryUrl = let queryUrl =
appealTypeName + appealTypeName +
"?$filter=_" + "?$filter=_" +
(primaryIdAttribute == "pinswg_sipscase" (primaryIdAttribute == "pinswg_sipscase"
@@ -87,12 +119,11 @@ export default async function ApiProxy(req, res) {
// "\n==========================================\n" // "\n==========================================\n"
// ); // );
return axios const { data } = await axios.get(
.get(
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
azureHeaders(token.access_token) azureHeaders(token.access_token)
) );
.then(({ data }) => {
let flattened = data.value.map((r) => ({ let flattened = data.value.map((r) => ({
...r, ...r,
ticketnumber: r[navigationProperty]?.ticketnumber || null ticketnumber: r[navigationProperty]?.ticketnumber || null
@@ -100,10 +131,13 @@ export default async function ApiProxy(req, res) {
data.value = flattened; data.value = flattened;
res.status(200).json(data); return respondSuccess(res, data);
}) } catch (error) {
.catch((error) => {
consoleLogger(error); consoleLogger(error);
res.status(400).json(error); return respondError(res, {
status: 400,
code: "BASIC_SEARCH_DETAILS_FETCH_FAILED",
message: "Failed to fetch basic search details"
}); });
}
} }
@@ -30,7 +30,6 @@
*/ */
import axios from "axios"; import axios from "axios";
import CryptoJS from "crypto-js";
import _ from "lodash"; import _ from "lodash";
import { azureHeadersPaged } from "../../../actions/core/headers"; import { azureHeadersPaged } from "../../../actions/core/headers";
import { consoleLogger } from "../../../actions/core/logger"; import { consoleLogger } from "../../../actions/core/logger";
@@ -38,30 +37,51 @@ import { getToken } from "../../../actions/core/token";
import { getSelectQuery } from "../../../actions/selectQueryTypes"; import { getSelectQuery } from "../../../actions/selectQueryTypes";
import { getNavigationPropertyByPrimaryAttribute } from "../../../components/utils"; import { getNavigationPropertyByPrimaryAttribute } from "../../../components/utils";
import { hashAPIPath } from "../../../actions/core/hash"; import { hashAPIPath } from "../../../actions/core/hash";
import { respondError, respondSuccess } from "../middleware/apiResponse";
const WEBAPI_URL = const WEBAPI_URL =
process.env.RELAY_ROOT || process.env.RELAY_ROOT ||
"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 appealTypeName = req.query.appealTypeName; const appealTypeName = req.query.appealTypeName;
var primaryIdAttribute = req.query.primaryIdAttribute; const primaryIdAttribute = req.query.primaryIdAttribute;
var incidentID = req.query.incidentID; const incidentID = req.query.incidentID;
if ( if (
!appealTypeName || typeof appealTypeName !== "string" ||
!primaryIdAttribute || appealTypeName.trim().length === 0
!incidentID ||
String(appealTypeName).trim().length === 0 ||
String(primaryIdAttribute).trim().length === 0 ||
String(incidentID).trim().length === 0
) { ) {
return res.status(400).json(); return respondError(res, {
status: 400,
code: "APPEAL_TYPE_NAME_REQUIRED",
message: "appealTypeName is required"
});
} }
var token = await getToken(); if (
typeof primaryIdAttribute !== "string" ||
primaryIdAttribute.trim().length === 0
) {
return respondError(res, {
status: 400,
code: "PRIMARY_ID_ATTRIBUTE_REQUIRED",
message: "primaryIdAttribute is required"
});
}
let navigationProperty = if (typeof incidentID !== "string" || incidentID.trim().length === 0) {
return respondError(res, {
status: 400,
code: "INCIDENT_ID_REQUIRED",
message: "incidentID is required"
});
}
try {
const token = await getToken();
const navigationProperty =
getNavigationPropertyByPrimaryAttribute( getNavigationPropertyByPrimaryAttribute(
primaryIdAttribute primaryIdAttribute
).NavigationProperty; ).NavigationProperty;
@@ -73,7 +93,7 @@ export default async function ApiProxy(req, res) {
// " eq " + // " eq " +
// incidentID + // incidentID +
var queryUrl = let queryUrl =
appealTypeName + appealTypeName +
"?$filter=" + "?$filter=" +
incidentID + incidentID +
@@ -92,12 +112,11 @@ export default async function ApiProxy(req, res) {
? "pinswg_sipscase_value" ? "pinswg_sipscase_value"
: primaryIdAttribute + "s_value"); : primaryIdAttribute + "s_value");
return axios const { data } = await axios.get(
.get(
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
azureHeadersPaged(token.access_token) azureHeadersPaged(token.access_token)
) );
.then(({ data }) => {
let flattened = data.value.map((r) => ({ let flattened = data.value.map((r) => ({
...r, ...r,
ticketnumber: r[navigationProperty]?.ticketnumber || null ticketnumber: r[navigationProperty]?.ticketnumber || null
@@ -105,15 +124,18 @@ export default async function ApiProxy(req, res) {
data.value = flattened; data.value = flattened;
var dataStr; if (_.has(data, "@odata.nextLink") === true) {
_.has(data, "@odata.nextLink") == true && const dataStr = JSON.stringify(data["@odata.nextLink"]);
((dataStr = JSON.stringify(data["@odata.nextLink"])), data["@odata.nextLink"] = dataStr.split("/v8.2/")[1];
(data["@odata.nextLink"] = dataStr.split("/v8.2/")[1])); }
return res.status(200).json(data); return respondSuccess(res, data);
}) } catch (error) {
.catch((error) => {
consoleLogger(error); consoleLogger(error);
res.status(400).json(error); return respondError(res, {
status: 400,
code: "BASIC_SEARCH_DETAILS_PAGED_FETCH_FAILED",
message: "Failed to fetch paged basic search details"
}); });
}
} }
+58 -32
View File
@@ -48,28 +48,60 @@ import { azureHeadersPagedCustom } from "../../../actions/core/headers";
import { consoleLogger } from "../../../actions/core/logger"; import { consoleLogger } from "../../../actions/core/logger";
import { getToken } from "../../../actions/core/token"; import { getToken } from "../../../actions/core/token";
import { hashAPIPath } from "../../../actions/core/hash"; import { hashAPIPath } from "../../../actions/core/hash";
import { respondError, respondSuccess } from "../middleware/apiResponse";
const WEBAPI_URL = const WEBAPI_URL =
process.env.RELAY_ROOT || process.env.RELAY_ROOT ||
"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; let searchString = req.query.searchString;
var pageNumber = req.query.pageNumber; const pageNumber = req.query.pageNumber;
const orderby = req.query.orderby;
const fieldSort = req.query.fieldSort;
const showNumberOfRecords = req.query.showNumberOfRecords;
if (typeof searchString === "undefined" || searchString.length === 0) { if (typeof searchString !== "string" || searchString.trim().length === 0) {
return res.status(400).json(); return respondError(res, {
status: 400,
code: "SEARCH_STRING_REQUIRED",
message: "searchString is required"
});
} }
var token = await getToken(); if (typeof orderby !== "string" || orderby.trim().length === 0) {
return respondError(res, {
status: 400,
code: "ORDER_BY_REQUIRED",
message: "orderby is required"
});
}
var orderby = req.query.orderby; if (typeof fieldSort !== "string" || fieldSort.trim().length === 0) {
var fieldSort = req.query.fieldSort; return respondError(res, {
var showNumberOfRecords = req.query.showNumberOfRecords; status: 400,
code: "FIELD_SORT_REQUIRED",
message: "fieldSort is required"
});
}
if (
typeof showNumberOfRecords !== "string" ||
showNumberOfRecords.trim().length === 0
) {
return respondError(res, {
status: 400,
code: "SHOW_NUMBER_OF_RECORDS_REQUIRED",
message: "showNumberOfRecords is required"
});
}
try {
const token = await getToken();
searchString = searchString.replace(/\'/g, "''"); searchString = searchString.replace(/\'/g, "''");
var queryUrl = const queryUrl =
"incidents?$select=pinswg_environmentalstatementlocation,pinswg_caseaddress,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)&$filter=(contains(title, '" + "incidents?$select=pinswg_environmentalstatementlocation,pinswg_caseaddress,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)&$filter=(contains(title, '" +
searchString + searchString +
"') or contains(ticketnumber, '" + "') or contains(ticketnumber, '" +
@@ -89,29 +121,23 @@ export default async function ApiProxy(req, res) {
? "&$skiptoken=" + '<cookie pagenumber="' + pageNumber + '" />' ? "&$skiptoken=" + '<cookie pagenumber="' + pageNumber + '" />'
: ""); : "");
var apiResponse = const { data } = await axios.get(
searchString.length > 0
? axios
.get(
WEBAPI_URL + queryUrl + hashAPIPath(queryUrl), WEBAPI_URL + queryUrl + hashAPIPath(queryUrl),
azureHeadersPagedCustom( azureHeadersPagedCustom(token.access_token, showNumberOfRecords)
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]));
res.status(200).json(data);
})
.catch((error) => {
consoleLogger(error);
res.status(400).json(error);
})
: res.status(400).json();
return apiResponse; if (_.has(data, "@odata.nextLink") === true) {
const 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: "BASIC_SEARCH_PAGED_FETCH_FAILED",
message: "Failed to fetch paged basic search results"
});
}
} }
@@ -1522,6 +1522,257 @@ test("getawaitingsubmission catch path returns AWAITING_SUBMISSION_FETCH_FAILED"
); );
}); });
test("getbasicsearchdetails returns APPEAL_TYPE_NAME_REQUIRED when appealTypeName missing", async () => {
const mod = loadModule("pages/api/endpoint/getbasicsearchdetails_api.js", {
respondError: respondErrorMock,
respondSuccess: respondSuccessMock,
getToken: async () => ({ access_token: "token" }),
getSelectQuery: () => "&$select=title",
getNavigationPropertyByPrimaryAttribute: () => ({
NavigationProperty: "pinswg_TestNav"
}),
hashAPIPath: () => "&hash=expected",
azureHeaders: () => ({}),
axios: { get: async () => ({ data: { value: [] } }) },
consoleLogger: () => {}
});
const req = {
query: {
primaryIdAttribute: "pinswg_planningappeals78id",
incidentID: "i1"
}
};
const res = createRes();
await mod.default(req, res);
assert.strictEqual(res.state.statusCode, 400);
assert.strictEqual(
res.state.jsonBody.error.code,
"APPEAL_TYPE_NAME_REQUIRED"
);
});
test("getbasicsearchdetails catch path returns BASIC_SEARCH_DETAILS_FETCH_FAILED", async () => {
const mod = loadModule("pages/api/endpoint/getbasicsearchdetails_api.js", {
respondError: respondErrorMock,
respondSuccess: respondSuccessMock,
getToken: async () => ({ access_token: "token" }),
getSelectQuery: () => "&$select=title",
getNavigationPropertyByPrimaryAttribute: () => ({
NavigationProperty: "pinswg_TestNav"
}),
hashAPIPath: () => "&hash=expected",
azureHeaders: () => ({}),
axios: {
get: async () => {
throw new Error("relay failed");
}
},
consoleLogger: () => {}
});
const req = {
query: {
appealTypeName: "pinswg_planningappeals78s",
primaryIdAttribute: "pinswg_planningappeals78id",
incidentID: "i1"
}
};
const res = createRes();
await mod.default(req, res);
assert.strictEqual(res.state.statusCode, 400);
assert.strictEqual(
res.state.jsonBody.error.code,
"BASIC_SEARCH_DETAILS_FETCH_FAILED"
);
});
test("getbasicsearchdetailspaged returns APPEAL_TYPE_NAME_REQUIRED when appealTypeName missing", async () => {
const mod = loadModule(
"pages/api/endpoint/getbasicsearchdetailspaged_api.js",
{
respondError: respondErrorMock,
respondSuccess: respondSuccessMock,
getToken: async () => ({ access_token: "token" }),
getSelectQuery: () => "&$select=title",
getNavigationPropertyByPrimaryAttribute: () => ({
NavigationProperty: "pinswg_TestNav"
}),
hashAPIPath: () => "&hash=expected",
azureHeadersPaged: () => ({}),
axios: { get: async () => ({ data: { value: [] } }) },
consoleLogger: () => {},
_: { has: () => false }
}
);
const req = {
query: {
primaryIdAttribute: "pinswg_planningappeals78id",
incidentID: "i1"
}
};
const res = createRes();
await mod.default(req, res);
assert.strictEqual(res.state.statusCode, 400);
assert.strictEqual(
res.state.jsonBody.error.code,
"APPEAL_TYPE_NAME_REQUIRED"
);
});
test("getbasicsearchdetailspaged catch path returns BASIC_SEARCH_DETAILS_PAGED_FETCH_FAILED", async () => {
const mod = loadModule(
"pages/api/endpoint/getbasicsearchdetailspaged_api.js",
{
respondError: respondErrorMock,
respondSuccess: respondSuccessMock,
getToken: async () => ({ access_token: "token" }),
getSelectQuery: () => "&$select=title",
getNavigationPropertyByPrimaryAttribute: () => ({
NavigationProperty: "pinswg_TestNav"
}),
hashAPIPath: () => "&hash=expected",
azureHeadersPaged: () => ({}),
axios: {
get: async () => {
throw new Error("relay failed");
}
},
consoleLogger: () => {},
_: { has: () => false }
}
);
const req = {
query: {
appealTypeName: "pinswg_planningappeals78s",
primaryIdAttribute: "pinswg_planningappeals78id",
incidentID: "i1"
}
};
const res = createRes();
await mod.default(req, res);
assert.strictEqual(res.state.statusCode, 400);
assert.strictEqual(
res.state.jsonBody.error.code,
"BASIC_SEARCH_DETAILS_PAGED_FETCH_FAILED"
);
});
test("getbasicsearchpaged returns ORDER_BY_REQUIRED when orderby missing", async () => {
const mod = loadModule("pages/api/endpoint/getbasicsearchpaged_api.js", {
respondError: respondErrorMock,
respondSuccess: respondSuccessMock,
getToken: async () => ({ access_token: "token" }),
hashAPIPath: () => "&hash=expected",
azureHeadersPagedCustom: () => ({}),
axios: { get: async () => ({ data: { value: [] } }) },
consoleLogger: () => {},
_: { has: () => false }
});
const req = {
query: {
searchString: "cas",
fieldSort: "asc",
showNumberOfRecords: "10"
}
};
const res = createRes();
await mod.default(req, res);
assert.strictEqual(res.state.statusCode, 400);
assert.strictEqual(res.state.jsonBody.error.code, "ORDER_BY_REQUIRED");
});
test("getbasicsearchpaged catch path returns BASIC_SEARCH_PAGED_FETCH_FAILED", async () => {
const mod = loadModule("pages/api/endpoint/getbasicsearchpaged_api.js", {
respondError: respondErrorMock,
respondSuccess: respondSuccessMock,
getToken: async () => ({ access_token: "token" }),
hashAPIPath: () => "&hash=expected",
azureHeadersPagedCustom: () => ({}),
axios: {
get: async () => {
throw new Error("relay failed");
}
},
consoleLogger: () => {},
_: { has: () => false }
});
const req = {
query: {
searchString: "cas",
orderby: "createdon",
fieldSort: "asc",
showNumberOfRecords: "10"
}
};
const res = createRes();
await mod.default(req, res);
assert.strictEqual(res.state.statusCode, 400);
assert.strictEqual(
res.state.jsonBody.error.code,
"BASIC_SEARCH_PAGED_FETCH_FAILED"
);
});
test("getbasicsearch_by_lparref returns LPA_REF_REQUIRED when lpaRef missing", async () => {
const mod = loadModule(
"pages/api/endpoint/getbasicsearch_by_lparref_api.js",
{
respondError: respondErrorMock,
respondSuccess: respondSuccessMock,
getToken: async () => ({ access_token: "token" }),
hashAPIPath: () => "&hash=expected",
azureHeaders: () => ({}),
axios: { get: async () => ({ data: { value: [] } }) },
consoleLogger: () => {}
}
);
const req = { query: {} };
const res = createRes();
await mod.default(req, res);
assert.strictEqual(res.state.statusCode, 400);
assert.strictEqual(res.state.jsonBody.error.code, "LPA_REF_REQUIRED");
});
test("getbasicsearch_by_lparref catch path returns BASIC_SEARCH_LPA_REF_FETCH_FAILED", async () => {
const mod = loadModule(
"pages/api/endpoint/getbasicsearch_by_lparref_api.js",
{
respondError: respondErrorMock,
respondSuccess: respondSuccessMock,
getToken: async () => {
throw new Error("token failed");
},
hashAPIPath: () => "&hash=expected",
azureHeaders: () => ({}),
axios: { get: async () => ({ data: { value: [] } }) },
consoleLogger: () => {}
}
);
const req = { query: { lpaRef: "abc" } };
const res = createRes();
await mod.default(req, res);
assert.strictEqual(res.state.statusCode, 400);
assert.strictEqual(
res.state.jsonBody.error.code,
"BASIC_SEARCH_LPA_REF_FETCH_FAILED"
);
});
const run = async () => { const run = async () => {
let passed = 0; let passed = 0;
for (const currentTest of tests) { for (const currentTest of tests) {