TASK22211: normalize basic search endpoint contracts
This commit is contained in:
@@ -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 () => {
|
||||
let passed = 0;
|
||||
for (const currentTest of tests) {
|
||||
|
||||
Reference in New Issue
Block a user