TASK22211: normalize portal module and lpa case endpoint contracts
This commit is contained in:
@@ -1967,6 +1967,186 @@ test("getbasicdnssearchdetailspaged catch path returns BASIC_DNS_SEARCH_DETAILS_
|
||||
);
|
||||
});
|
||||
|
||||
test("getportalmoduledetails returns APPEAL_TYPE_REQUIRED when appealType missing", async () => {
|
||||
const mod = loadModule("pages/api/endpoint/getportalmoduledetails_api.js", {
|
||||
respondError: respondErrorMock,
|
||||
respondSuccess: respondSuccessMock,
|
||||
getToken: async () => ({ access_token: "token" }),
|
||||
getSelectQuery: () => "&$select=pinswg_name",
|
||||
hashAPIPath: () => "&hash=expected",
|
||||
azureHeaders: () => ({}),
|
||||
axios: { get: async () => ({ data: { value: [] } }) },
|
||||
consoleLogger: () => {}
|
||||
});
|
||||
|
||||
const req = { query: { caseReference: "CAS-1" } };
|
||||
const res = createRes();
|
||||
await mod.default(req, res);
|
||||
|
||||
assert.strictEqual(res.state.statusCode, 400);
|
||||
assert.strictEqual(res.state.jsonBody.error.code, "APPEAL_TYPE_REQUIRED");
|
||||
});
|
||||
|
||||
test("getportalmoduledetails catch path returns PORTAL_MODULE_DETAILS_FETCH_FAILED", async () => {
|
||||
const mod = loadModule("pages/api/endpoint/getportalmoduledetails_api.js", {
|
||||
respondError: respondErrorMock,
|
||||
respondSuccess: respondSuccessMock,
|
||||
getToken: async () => ({ access_token: "token" }),
|
||||
getSelectQuery: () => "&$select=pinswg_name",
|
||||
hashAPIPath: () => "&hash=expected",
|
||||
azureHeaders: () => ({}),
|
||||
axios: {
|
||||
get: async () => {
|
||||
throw new Error("relay failed");
|
||||
}
|
||||
},
|
||||
consoleLogger: () => {}
|
||||
});
|
||||
|
||||
const req = {
|
||||
query: {
|
||||
appealType: "pinswg_planningappeals78s",
|
||||
caseReference: "CAS-1"
|
||||
}
|
||||
};
|
||||
const res = createRes();
|
||||
await mod.default(req, res);
|
||||
|
||||
assert.strictEqual(res.state.statusCode, 400);
|
||||
assert.strictEqual(
|
||||
res.state.jsonBody.error.code,
|
||||
"PORTAL_MODULE_DETAILS_FETCH_FAILED"
|
||||
);
|
||||
});
|
||||
|
||||
test("getportalmoduledetailsproxy returns APPEAL_TYPE_REQUIRED when appealType missing", async () => {
|
||||
const mod = loadModule(
|
||||
"pages/api/endpoint/getportalmoduledetailsproxy_api.js",
|
||||
{
|
||||
respondError: respondErrorMock,
|
||||
respondSuccess: respondSuccessMock,
|
||||
getToken: async () => ({ access_token: "token" }),
|
||||
getSelectQuery: () => "&$select=pinswg_name",
|
||||
hashAPIPath: () => "&hash=expected",
|
||||
azureHeaders: () => ({}),
|
||||
axios: { get: async () => ({ data: { value: [] } }) },
|
||||
consoleLogger: () => {}
|
||||
}
|
||||
);
|
||||
|
||||
const req = { query: { caseReference: "CAS-1" } };
|
||||
const res = createRes();
|
||||
await mod.default(req, res);
|
||||
|
||||
assert.strictEqual(res.state.statusCode, 400);
|
||||
assert.strictEqual(res.state.jsonBody.error.code, "APPEAL_TYPE_REQUIRED");
|
||||
});
|
||||
|
||||
test("getportalmoduledetailsproxy catch path returns PORTAL_MODULE_DETAILS_PROXY_FETCH_FAILED", async () => {
|
||||
const mod = loadModule(
|
||||
"pages/api/endpoint/getportalmoduledetailsproxy_api.js",
|
||||
{
|
||||
respondError: respondErrorMock,
|
||||
respondSuccess: respondSuccessMock,
|
||||
getToken: async () => ({ access_token: "token" }),
|
||||
getSelectQuery: () => "&$select=pinswg_name",
|
||||
hashAPIPath: () => "&hash=expected",
|
||||
azureHeaders: () => ({}),
|
||||
axios: {
|
||||
get: async () => {
|
||||
throw new Error("relay failed");
|
||||
}
|
||||
},
|
||||
consoleLogger: () => {}
|
||||
}
|
||||
);
|
||||
|
||||
const req = {
|
||||
query: {
|
||||
appealType: "pinswg_planningappeals78s",
|
||||
caseReference: "CAS-1"
|
||||
}
|
||||
};
|
||||
const res = createRes();
|
||||
await mod.default(req, res);
|
||||
|
||||
assert.strictEqual(res.state.statusCode, 400);
|
||||
assert.strictEqual(
|
||||
res.state.jsonBody.error.code,
|
||||
"PORTAL_MODULE_DETAILS_PROXY_FETCH_FAILED"
|
||||
);
|
||||
});
|
||||
|
||||
test("getmylpacases returns LPA_ID_REQUIRED when lpaid missing", async () => {
|
||||
const mod = loadModule("pages/api/endpoint/getmylpacases_api.js", {
|
||||
respondError: respondErrorMock,
|
||||
respondSuccess: respondSuccessMock,
|
||||
getToken: async () => ({ access_token: "token" }),
|
||||
getLPA: async () => [{ name: "Test LPA", accountid: "acc1" }],
|
||||
jsonpath: () => [{ accountid: "acc1" }],
|
||||
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_ID_REQUIRED");
|
||||
});
|
||||
|
||||
test("getmylpacases returns LPA_NOT_FOUND when lpaid lookup misses", async () => {
|
||||
const mod = loadModule("pages/api/endpoint/getmylpacases_api.js", {
|
||||
respondError: respondErrorMock,
|
||||
respondSuccess: respondSuccessMock,
|
||||
getToken: async () => ({ access_token: "token" }),
|
||||
getLPA: async () => [{ name: "Another LPA", accountid: "acc1" }],
|
||||
jsonpath: () => [],
|
||||
hashAPIPath: () => "&hash=expected",
|
||||
azureHeaders: () => ({}),
|
||||
axios: { get: async () => ({ data: { value: [] } }) },
|
||||
consoleLogger: () => {}
|
||||
});
|
||||
|
||||
const req = { query: { lpaid: "Missing LPA" } };
|
||||
const res = createRes();
|
||||
await mod.default(req, res);
|
||||
|
||||
assert.strictEqual(res.state.statusCode, 404);
|
||||
assert.strictEqual(res.state.jsonBody.error.code, "LPA_NOT_FOUND");
|
||||
});
|
||||
|
||||
test("getmylpacases catch path returns MY_LPA_CASES_FETCH_FAILED", async () => {
|
||||
const mod = loadModule("pages/api/endpoint/getmylpacases_api.js", {
|
||||
respondError: respondErrorMock,
|
||||
respondSuccess: respondSuccessMock,
|
||||
getToken: async () => ({ access_token: "token" }),
|
||||
getLPA: async () => [{ name: "Test LPA", accountid: "acc1" }],
|
||||
jsonpath: () => [{ accountid: "acc1" }],
|
||||
hashAPIPath: () => "&hash=expected",
|
||||
azureHeaders: () => ({}),
|
||||
axios: {
|
||||
get: async () => {
|
||||
throw new Error("relay failed");
|
||||
}
|
||||
},
|
||||
consoleLogger: () => {}
|
||||
});
|
||||
|
||||
const req = { query: { lpaid: "Test LPA" } };
|
||||
const res = createRes();
|
||||
await mod.default(req, res);
|
||||
|
||||
assert.strictEqual(res.state.statusCode, 400);
|
||||
assert.strictEqual(
|
||||
res.state.jsonBody.error.code,
|
||||
"MY_LPA_CASES_FETCH_FAILED"
|
||||
);
|
||||
});
|
||||
|
||||
const run = async () => {
|
||||
let passed = 0;
|
||||
for (const currentTest of tests) {
|
||||
|
||||
Reference in New Issue
Block a user