TASK22211: normalize advanced search paged endpoint contract
This commit is contained in:
@@ -971,6 +971,92 @@ test("getadvancedsearch catch path returns ADVANCED_SEARCH_FETCH_FAILED", async
|
||||
);
|
||||
});
|
||||
|
||||
test("getadvancedsearchpaged returns SEARCH_STRING_REQUIRED when searchstring missing", async () => {
|
||||
const mod = loadModule("pages/api/endpoint/getadvancedsearchpaged_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: {
|
||||
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, "SEARCH_STRING_REQUIRED");
|
||||
});
|
||||
|
||||
test("getadvancedsearchpaged returns ORDER_BY_REQUIRED when orderby missing", async () => {
|
||||
const mod = loadModule("pages/api/endpoint/getadvancedsearchpaged_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: encodeURI(JSON.stringify({ q: "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("getadvancedsearchpaged catch path returns ADVANCED_SEARCH_PAGED_FETCH_FAILED", async () => {
|
||||
const mod = loadModule("pages/api/endpoint/getadvancedsearchpaged_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: encodeURI(JSON.stringify({ q: "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,
|
||||
"ADVANCED_SEARCH_PAGED_FETCH_FAILED"
|
||||
);
|
||||
});
|
||||
|
||||
test("getsearchdocumenthistory returns DOCUMENT_ID_REQUIRED when documentid missing", async () => {
|
||||
const mod = loadModule(
|
||||
"pages/api/endpoint/getsearchdocumenthistory_api.js",
|
||||
|
||||
Reference in New Issue
Block a user