update error and response handling
This commit is contained in:
@@ -442,6 +442,535 @@ test("getemailaccountcheck success returns existing data payload contract", asyn
|
||||
});
|
||||
});
|
||||
|
||||
test("getwatchedcasesproxy returns LOGGED_IN_USER_ID_REQUIRED when loggedInUserId missing", async () => {
|
||||
const mod = loadModule("pages/api/endpoint/getwatchedcasesproxy_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,
|
||||
"LOGGED_IN_USER_ID_REQUIRED"
|
||||
);
|
||||
});
|
||||
|
||||
test("getwatchedcasesproxy catch path returns WATCHED_CASES_PROXY_FETCH_FAILED", async () => {
|
||||
const mod = loadModule("pages/api/endpoint/getwatchedcasesproxy_api.js", {
|
||||
respondError: respondErrorMock,
|
||||
respondSuccess: respondSuccessMock,
|
||||
getToken: async () => ({ access_token: "token" }),
|
||||
hashAPIPath: () => "&hash=expected",
|
||||
azureHeaders: () => ({}),
|
||||
axios: {
|
||||
get: async () => {
|
||||
throw new Error("relay failed");
|
||||
}
|
||||
},
|
||||
consoleLogger: () => {}
|
||||
});
|
||||
|
||||
const req = { query: { loggedInUserId: "c1" } };
|
||||
const res = createRes();
|
||||
await mod.default(req, res);
|
||||
|
||||
assert.strictEqual(res.state.statusCode, 400);
|
||||
assert.strictEqual(
|
||||
res.state.jsonBody.error.code,
|
||||
"WATCHED_CASES_PROXY_FETCH_FAILED"
|
||||
);
|
||||
});
|
||||
|
||||
test("getmyrepresentationsproxy returns LOGGED_IN_USER_ID_REQUIRED when loggedInUserId missing", async () => {
|
||||
const mod = loadModule(
|
||||
"pages/api/endpoint/getmyrepresentationsproxy_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,
|
||||
"LOGGED_IN_USER_ID_REQUIRED"
|
||||
);
|
||||
});
|
||||
|
||||
test("getmyrepresentationsproxy catch path returns MY_REPRESENTATIONS_PROXY_FETCH_FAILED", async () => {
|
||||
const mod = loadModule(
|
||||
"pages/api/endpoint/getmyrepresentationsproxy_api.js",
|
||||
{
|
||||
respondError: respondErrorMock,
|
||||
respondSuccess: respondSuccessMock,
|
||||
getToken: async () => ({ access_token: "token" }),
|
||||
hashAPIPath: () => "&hash=expected",
|
||||
azureHeaders: () => ({}),
|
||||
axios: {
|
||||
get: async () => {
|
||||
throw new Error("relay failed");
|
||||
}
|
||||
},
|
||||
consoleLogger: () => {}
|
||||
}
|
||||
);
|
||||
|
||||
const req = { query: { loggedInUserId: "c1" } };
|
||||
const res = createRes();
|
||||
await mod.default(req, res);
|
||||
|
||||
assert.strictEqual(res.state.statusCode, 400);
|
||||
assert.strictEqual(
|
||||
res.state.jsonBody.error.code,
|
||||
"MY_REPRESENTATIONS_PROXY_FETCH_FAILED"
|
||||
);
|
||||
});
|
||||
|
||||
test("getrepresentationsproxy returns INCIDENT_ID_REQUIRED when incidentID missing", async () => {
|
||||
const mod = loadModule(
|
||||
"pages/api/endpoint/getrepresentationsproxy_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, "INCIDENT_ID_REQUIRED");
|
||||
});
|
||||
|
||||
test("getrepresentationsproxy catch path returns REPRESENTATIONS_PROXY_FETCH_FAILED", async () => {
|
||||
const mod = loadModule(
|
||||
"pages/api/endpoint/getrepresentationsproxy_api.js",
|
||||
{
|
||||
respondError: respondErrorMock,
|
||||
respondSuccess: respondSuccessMock,
|
||||
getToken: async () => ({ access_token: "token" }),
|
||||
hashAPIPath: () => "&hash=expected",
|
||||
azureHeaders: () => ({}),
|
||||
axios: {
|
||||
get: async () => {
|
||||
throw new Error("relay failed");
|
||||
}
|
||||
},
|
||||
consoleLogger: () => {}
|
||||
}
|
||||
);
|
||||
|
||||
const req = { query: { incidentID: "i1" } };
|
||||
const res = createRes();
|
||||
await mod.default(req, res);
|
||||
|
||||
assert.strictEqual(res.state.statusCode, 400);
|
||||
assert.strictEqual(
|
||||
res.state.jsonBody.error.code,
|
||||
"REPRESENTATIONS_PROXY_FETCH_FAILED"
|
||||
);
|
||||
});
|
||||
|
||||
test("getawaitingsubmissionproxy returns LOGGED_IN_USER_ID_REQUIRED when loggedInUserId missing", async () => {
|
||||
const mod = loadModule(
|
||||
"pages/api/endpoint/getawaitingsubmissionproxy_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,
|
||||
"LOGGED_IN_USER_ID_REQUIRED"
|
||||
);
|
||||
});
|
||||
|
||||
test("getawaitingsubmissionproxy catch path returns AWAITING_SUBMISSION_PROXY_FETCH_FAILED", async () => {
|
||||
const mod = loadModule(
|
||||
"pages/api/endpoint/getawaitingsubmissionproxy_api.js",
|
||||
{
|
||||
respondError: respondErrorMock,
|
||||
respondSuccess: respondSuccessMock,
|
||||
getToken: async () => ({ access_token: "token" }),
|
||||
hashAPIPath: () => "&hash=expected",
|
||||
azureHeaders: () => ({}),
|
||||
axios: {
|
||||
get: async () => {
|
||||
throw new Error("relay failed");
|
||||
}
|
||||
},
|
||||
consoleLogger: () => {}
|
||||
}
|
||||
);
|
||||
|
||||
const req = { query: { loggedInUserId: "c1" } };
|
||||
const res = createRes();
|
||||
await mod.default(req, res);
|
||||
|
||||
assert.strictEqual(res.state.statusCode, 400);
|
||||
assert.strictEqual(
|
||||
res.state.jsonBody.error.code,
|
||||
"AWAITING_SUBMISSION_PROXY_FETCH_FAILED"
|
||||
);
|
||||
});
|
||||
|
||||
test("createaccount returns ACCOUNT_PAYLOAD_REQUIRED when body missing", async () => {
|
||||
const mod = loadModule("pages/api/endpoint/createaccount_api.js", {
|
||||
respondError: respondErrorMock,
|
||||
respondSuccess: respondSuccessMock,
|
||||
getToken: async () => ({ access_token: "token" }),
|
||||
hashAPIPath: () => "&hash=expected",
|
||||
axios: async () => ({ data: { contactid: "c1" } }),
|
||||
consoleLogger: () => {}
|
||||
});
|
||||
|
||||
const req = { query: {}, body: undefined };
|
||||
const res = createRes();
|
||||
await mod.default(req, res);
|
||||
|
||||
assert.strictEqual(res.state.statusCode, 400);
|
||||
assert.strictEqual(
|
||||
res.state.jsonBody.error.code,
|
||||
"ACCOUNT_PAYLOAD_REQUIRED"
|
||||
);
|
||||
});
|
||||
|
||||
test("createaccount catch path returns ACCOUNT_CREATE_FAILED", async () => {
|
||||
const mod = loadModule("pages/api/endpoint/createaccount_api.js", {
|
||||
respondError: respondErrorMock,
|
||||
respondSuccess: respondSuccessMock,
|
||||
getToken: async () => ({ access_token: "token" }),
|
||||
hashAPIPath: () => "&hash=expected",
|
||||
axios: async () => {
|
||||
throw new Error("relay failed");
|
||||
},
|
||||
consoleLogger: () => {}
|
||||
});
|
||||
|
||||
const req = { query: {}, body: { firstname: "A" } };
|
||||
const res = createRes();
|
||||
await mod.default(req, res);
|
||||
|
||||
assert.strictEqual(res.state.statusCode, 400);
|
||||
assert.strictEqual(res.state.jsonBody.error.code, "ACCOUNT_CREATE_FAILED");
|
||||
});
|
||||
|
||||
test("updateaccount returns CONTACT_ID_REQUIRED when contactId missing", async () => {
|
||||
const mod = loadModule("pages/api/endpoint/updateaccount_api.js", {
|
||||
respondError: respondErrorMock,
|
||||
respondSuccess: respondSuccessMock,
|
||||
getToken: async () => ({ access_token: "token" }),
|
||||
hashAPIPath: () => "&hash=expected",
|
||||
axios: async () => ({ data: { contactid: "c1" } }),
|
||||
consoleLogger: () => {}
|
||||
});
|
||||
|
||||
const req = { query: {}, body: { firstname: "A" } };
|
||||
const res = createRes();
|
||||
await mod.default(req, res);
|
||||
|
||||
assert.strictEqual(res.state.statusCode, 400);
|
||||
assert.strictEqual(res.state.jsonBody.error.code, "CONTACT_ID_REQUIRED");
|
||||
});
|
||||
|
||||
test("updateaccount returns ACCOUNT_UPDATE_PAYLOAD_REQUIRED when body missing", async () => {
|
||||
const mod = loadModule("pages/api/endpoint/updateaccount_api.js", {
|
||||
respondError: respondErrorMock,
|
||||
respondSuccess: respondSuccessMock,
|
||||
getToken: async () => ({ access_token: "token" }),
|
||||
hashAPIPath: () => "&hash=expected",
|
||||
axios: async () => ({ data: { contactid: "c1" } }),
|
||||
consoleLogger: () => {}
|
||||
});
|
||||
|
||||
const req = { query: { contactId: "c1" }, body: undefined };
|
||||
const res = createRes();
|
||||
await mod.default(req, res);
|
||||
|
||||
assert.strictEqual(res.state.statusCode, 400);
|
||||
assert.strictEqual(
|
||||
res.state.jsonBody.error.code,
|
||||
"ACCOUNT_UPDATE_PAYLOAD_REQUIRED"
|
||||
);
|
||||
});
|
||||
|
||||
test("updateaccount catch path returns ACCOUNT_UPDATE_FAILED", async () => {
|
||||
const mod = loadModule("pages/api/endpoint/updateaccount_api.js", {
|
||||
respondError: respondErrorMock,
|
||||
respondSuccess: respondSuccessMock,
|
||||
getToken: async () => ({ access_token: "token" }),
|
||||
hashAPIPath: () => "&hash=expected",
|
||||
axios: async () => {
|
||||
throw new Error("relay failed");
|
||||
},
|
||||
consoleLogger: () => {}
|
||||
});
|
||||
|
||||
const req = { query: { contactId: "c1" }, body: { firstname: "A" } };
|
||||
const res = createRes();
|
||||
await mod.default(req, res);
|
||||
|
||||
assert.strictEqual(res.state.statusCode, 400);
|
||||
assert.strictEqual(res.state.jsonBody.error.code, "ACCOUNT_UPDATE_FAILED");
|
||||
});
|
||||
|
||||
test("updatepassword returns CONTACT_ID_REQUIRED when contactId missing", async () => {
|
||||
const mod = loadModule("pages/api/endpoint/updatepassword_api.js", {
|
||||
respondError: respondErrorMock,
|
||||
respondSuccess: respondSuccessMock,
|
||||
getToken: async () => ({ access_token: "token" }),
|
||||
hashAPIPath: () => "&hash=expected",
|
||||
axios: async () => ({ data: { contactid: "c1" } }),
|
||||
consoleLogger: () => {}
|
||||
});
|
||||
|
||||
const req = { query: {}, body: { pinswg_password: "abc" } };
|
||||
const res = createRes();
|
||||
await mod.default(req, res);
|
||||
|
||||
assert.strictEqual(res.state.statusCode, 400);
|
||||
assert.strictEqual(res.state.jsonBody.error.code, "CONTACT_ID_REQUIRED");
|
||||
});
|
||||
|
||||
test("updatepassword returns PASSWORD_UPDATE_PAYLOAD_REQUIRED when body missing", async () => {
|
||||
const mod = loadModule("pages/api/endpoint/updatepassword_api.js", {
|
||||
respondError: respondErrorMock,
|
||||
respondSuccess: respondSuccessMock,
|
||||
getToken: async () => ({ access_token: "token" }),
|
||||
hashAPIPath: () => "&hash=expected",
|
||||
axios: async () => ({ data: { contactid: "c1" } }),
|
||||
consoleLogger: () => {}
|
||||
});
|
||||
|
||||
const req = { query: { contactId: "c1" }, body: undefined };
|
||||
const res = createRes();
|
||||
await mod.default(req, res);
|
||||
|
||||
assert.strictEqual(res.state.statusCode, 400);
|
||||
assert.strictEqual(
|
||||
res.state.jsonBody.error.code,
|
||||
"PASSWORD_UPDATE_PAYLOAD_REQUIRED"
|
||||
);
|
||||
});
|
||||
|
||||
test("updatepassword catch path returns PASSWORD_UPDATE_FAILED", async () => {
|
||||
const mod = loadModule("pages/api/endpoint/updatepassword_api.js", {
|
||||
respondError: respondErrorMock,
|
||||
respondSuccess: respondSuccessMock,
|
||||
getToken: async () => ({ access_token: "token" }),
|
||||
hashAPIPath: () => "&hash=expected",
|
||||
axios: async () => {
|
||||
throw new Error("relay failed");
|
||||
},
|
||||
consoleLogger: () => {}
|
||||
});
|
||||
|
||||
const req = {
|
||||
query: { contactId: "c1" },
|
||||
body: { pinswg_password: "abc" }
|
||||
};
|
||||
const res = createRes();
|
||||
await mod.default(req, res);
|
||||
|
||||
assert.strictEqual(res.state.statusCode, 400);
|
||||
assert.strictEqual(res.state.jsonBody.error.code, "PASSWORD_UPDATE_FAILED");
|
||||
});
|
||||
|
||||
test("getbasicsearch returns SEARCH_STRING_REQUIRED when searchString missing", async () => {
|
||||
const mod = loadModule("pages/api/endpoint/getbasicsearch_api.js", {
|
||||
respondError: respondErrorMock,
|
||||
respondSuccess: respondSuccessMock,
|
||||
getToken: async () => ({ access_token: "token" }),
|
||||
hashAPIPath: () => "&hash=expected",
|
||||
azureHeadersPaged: () => ({}),
|
||||
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, "SEARCH_STRING_REQUIRED");
|
||||
});
|
||||
|
||||
test("getbasicsearch catch path returns BASIC_SEARCH_FETCH_FAILED", async () => {
|
||||
const mod = loadModule("pages/api/endpoint/getbasicsearch_api.js", {
|
||||
respondError: respondErrorMock,
|
||||
respondSuccess: respondSuccessMock,
|
||||
getToken: async () => ({ access_token: "token" }),
|
||||
hashAPIPath: () => "&hash=expected",
|
||||
azureHeadersPaged: () => ({}),
|
||||
axios: {
|
||||
get: async () => {
|
||||
throw new Error("relay failed");
|
||||
}
|
||||
},
|
||||
consoleLogger: () => {}
|
||||
});
|
||||
|
||||
const req = { query: { searchString: "CAS" } };
|
||||
const res = createRes();
|
||||
await mod.default(req, res);
|
||||
|
||||
assert.strictEqual(res.state.statusCode, 400);
|
||||
assert.strictEqual(
|
||||
res.state.jsonBody.error.code,
|
||||
"BASIC_SEARCH_FETCH_FAILED"
|
||||
);
|
||||
});
|
||||
|
||||
test("getcasemessage returns CASE_ID_REQUIRED when id missing", async () => {
|
||||
const mod = loadModule("pages/api/endpoint/getcasemessage_api.js", {
|
||||
respondError: respondErrorMock,
|
||||
respondSuccess: respondSuccessMock,
|
||||
getToken: async () => ({ access_token: "token" }),
|
||||
hashAPIPath: () => "&hash=expected",
|
||||
azureHeadersPaged: () => ({}),
|
||||
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, "CASE_ID_REQUIRED");
|
||||
});
|
||||
|
||||
test("getcasemessage catch path returns CASE_MESSAGE_FETCH_FAILED", async () => {
|
||||
const mod = loadModule("pages/api/endpoint/getcasemessage_api.js", {
|
||||
respondError: respondErrorMock,
|
||||
respondSuccess: respondSuccessMock,
|
||||
getToken: async () => ({ access_token: "token" }),
|
||||
hashAPIPath: () => "&hash=expected",
|
||||
azureHeadersPaged: () => ({}),
|
||||
axios: {
|
||||
get: async () => {
|
||||
throw new Error("relay failed");
|
||||
}
|
||||
},
|
||||
consoleLogger: () => {}
|
||||
});
|
||||
|
||||
const req = { query: { id: "i1" } };
|
||||
const res = createRes();
|
||||
await mod.default(req, res);
|
||||
|
||||
assert.strictEqual(res.state.statusCode, 400);
|
||||
assert.strictEqual(
|
||||
res.state.jsonBody.error.code,
|
||||
"CASE_MESSAGE_FETCH_FAILED"
|
||||
);
|
||||
});
|
||||
|
||||
test("getadvancedsearch returns SEARCH_STRING_REQUIRED when searchstring missing", async () => {
|
||||
const mod = loadModule("pages/api/endpoint/getadvancedsearch_api.js", {
|
||||
respondError: respondErrorMock,
|
||||
respondSuccess: respondSuccessMock,
|
||||
getToken: async () => ({ access_token: "token" }),
|
||||
hashAPIPath: () => "&hash=expected",
|
||||
azureHeadersPaged: () => ({}),
|
||||
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, "SEARCH_STRING_REQUIRED");
|
||||
});
|
||||
|
||||
test("getadvancedsearch returns INVALID_SEARCH_STRING when searchstring invalid JSON", async () => {
|
||||
const mod = loadModule("pages/api/endpoint/getadvancedsearch_api.js", {
|
||||
respondError: respondErrorMock,
|
||||
respondSuccess: respondSuccessMock,
|
||||
getToken: async () => ({ access_token: "token" }),
|
||||
hashAPIPath: () => "&hash=expected",
|
||||
azureHeadersPaged: () => ({}),
|
||||
axios: { get: async () => ({ data: { value: [] } }) },
|
||||
consoleLogger: () => {}
|
||||
});
|
||||
|
||||
const req = { query: { searchstring: "not-json" } };
|
||||
const res = createRes();
|
||||
await mod.default(req, res);
|
||||
|
||||
assert.strictEqual(res.state.statusCode, 400);
|
||||
assert.strictEqual(res.state.jsonBody.error.code, "INVALID_SEARCH_STRING");
|
||||
});
|
||||
|
||||
test("getadvancedsearch catch path returns ADVANCED_SEARCH_FETCH_FAILED", async () => {
|
||||
const mod = loadModule("pages/api/endpoint/getadvancedsearch_api.js", {
|
||||
respondError: respondErrorMock,
|
||||
respondSuccess: respondSuccessMock,
|
||||
getToken: async () => ({ access_token: "token" }),
|
||||
hashAPIPath: () => "&hash=expected",
|
||||
azureHeadersPaged: () => ({}),
|
||||
axios: {
|
||||
get: async () => {
|
||||
throw new Error("relay failed");
|
||||
}
|
||||
},
|
||||
consoleLogger: () => {}
|
||||
});
|
||||
|
||||
const req = {
|
||||
query: {
|
||||
searchstring: encodeURI(
|
||||
JSON.stringify({ q: "cas", lpa: "l1", apt: "1" })
|
||||
)
|
||||
}
|
||||
};
|
||||
const res = createRes();
|
||||
await mod.default(req, res);
|
||||
|
||||
assert.strictEqual(res.state.statusCode, 400);
|
||||
assert.strictEqual(
|
||||
res.state.jsonBody.error.code,
|
||||
"ADVANCED_SEARCH_FETCH_FAILED"
|
||||
);
|
||||
});
|
||||
|
||||
const run = async () => {
|
||||
let passed = 0;
|
||||
for (const currentTest of tests) {
|
||||
|
||||
Reference in New Issue
Block a user