2754 lines
91 KiB
JavaScript
2754 lines
91 KiB
JavaScript
const assert = require("assert");
|
|
const {
|
|
loadModule,
|
|
createRes,
|
|
respondSuccessMock,
|
|
respondErrorMock
|
|
} = require("./_shared.cjs");
|
|
|
|
const tests = [];
|
|
const test = (name, fn) => tests.push({ name, fn });
|
|
|
|
test("getaccounts returns EMAIL_ADDRESS_REQUIRED when emailAddress missing", async () => {
|
|
const mod = loadModule("pages/api/endpoint/getaccounts_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, "EMAIL_ADDRESS_REQUIRED");
|
|
});
|
|
|
|
test("getaccounts catch path returns ACCOUNTS_FETCH_FAILED", async () => {
|
|
const mod = loadModule("pages/api/endpoint/getaccounts_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: { emailAddress: "user@test.local" } };
|
|
const res = createRes();
|
|
await mod.default(req, res);
|
|
|
|
assert.strictEqual(res.state.statusCode, 400);
|
|
assert.strictEqual(res.state.jsonBody.error.code, "ACCOUNTS_FETCH_FAILED");
|
|
});
|
|
|
|
test("getemailaccountcheck returns EMAIL_ADDRESS_REQUIRED when emailAddress missing", async () => {
|
|
const mod = loadModule("pages/api/endpoint/getemailaccountcheck_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, "EMAIL_ADDRESS_REQUIRED");
|
|
});
|
|
|
|
test("getemailaccountcheck catch path returns EMAIL_ACCOUNT_CHECK_FAILED", async () => {
|
|
const mod = loadModule("pages/api/endpoint/getemailaccountcheck_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: { emailAddress: "user@test.local" } };
|
|
const res = createRes();
|
|
await mod.default(req, res);
|
|
|
|
assert.strictEqual(res.state.statusCode, 400);
|
|
assert.strictEqual(
|
|
res.state.jsonBody.error.code,
|
|
"EMAIL_ACCOUNT_CHECK_FAILED"
|
|
);
|
|
});
|
|
|
|
test("getpreferredlanguage returns EMAIL_ADDRESS_REQUIRED when emailAddress missing", async () => {
|
|
const mod = loadModule("pages/api/endpoint/getpreferredlanguage_api.js", {
|
|
respondError: respondErrorMock,
|
|
respondSuccess: respondSuccessMock,
|
|
sanitizeString: () => "",
|
|
isNonEmptyString: () => false,
|
|
escapeODataString: (value) => value,
|
|
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, "EMAIL_ADDRESS_REQUIRED");
|
|
});
|
|
|
|
test("getpreferredlanguage catch path returns PREFERRED_LANGUAGE_FETCH_FAILED", async () => {
|
|
const mod = loadModule("pages/api/endpoint/getpreferredlanguage_api.js", {
|
|
respondError: respondErrorMock,
|
|
respondSuccess: respondSuccessMock,
|
|
sanitizeString: (value) => value,
|
|
isNonEmptyString: () => true,
|
|
escapeODataString: (value) => value,
|
|
getToken: async () => ({ access_token: "token" }),
|
|
hashAPIPath: () => "&hash=expected",
|
|
azureHeaders: () => ({}),
|
|
axios: {
|
|
get: async () => {
|
|
throw new Error("relay failed");
|
|
}
|
|
},
|
|
consoleLogger: () => {}
|
|
});
|
|
|
|
const req = { query: { emailAddress: "user@test.local" } };
|
|
const res = createRes();
|
|
await mod.default(req, res);
|
|
|
|
assert.strictEqual(res.state.statusCode, 400);
|
|
assert.strictEqual(
|
|
res.state.jsonBody.error.code,
|
|
"PREFERRED_LANGUAGE_FETCH_FAILED"
|
|
);
|
|
});
|
|
|
|
test("getpreferredlanguage success returns existing data payload contract", async () => {
|
|
const mod = loadModule("pages/api/endpoint/getpreferredlanguage_api.js", {
|
|
respondError: respondErrorMock,
|
|
respondSuccess: respondSuccessMock,
|
|
sanitizeString: (value) => value,
|
|
isNonEmptyString: () => true,
|
|
escapeODataString: (value) => value,
|
|
getToken: async () => ({ access_token: "token" }),
|
|
hashAPIPath: () => "&hash=expected",
|
|
azureHeaders: () => ({}),
|
|
axios: {
|
|
get: async () => ({
|
|
data: {
|
|
value: [
|
|
{
|
|
contactid: "c1",
|
|
pinswg_preferredlanguage: 807570001
|
|
}
|
|
]
|
|
}
|
|
})
|
|
},
|
|
consoleLogger: () => {}
|
|
});
|
|
|
|
const req = { query: { emailAddress: "user@test.local" } };
|
|
const res = createRes();
|
|
await mod.default(req, res);
|
|
|
|
assert.strictEqual(res.state.statusCode, 200);
|
|
assert.deepStrictEqual(JSON.parse(JSON.stringify(res.state.jsonBody)), {
|
|
value: [
|
|
{
|
|
contactid: "c1",
|
|
pinswg_preferredlanguage: 807570001
|
|
}
|
|
]
|
|
});
|
|
});
|
|
|
|
test("getlogin returns EMAIL_ADDRESS_REQUIRED when emailAddress missing", async () => {
|
|
const mod = loadModule("pages/api/endpoint/getlogin_api.js", {
|
|
respondError: respondErrorMock,
|
|
respondSuccess: respondSuccessMock,
|
|
getToken: async () => ({ access_token: "token" }),
|
|
hashAPIPath: () => "&hash=expected",
|
|
azureHeadersPaged: () => ({}),
|
|
axios: { get: async () => ({ data: { value: [] } }) },
|
|
consoleLogger: () => {}
|
|
});
|
|
|
|
const req = { query: { pwd: "abc123" } };
|
|
const res = createRes();
|
|
await mod.default(req, res);
|
|
|
|
assert.strictEqual(res.state.statusCode, 400);
|
|
assert.strictEqual(res.state.jsonBody.error.code, "EMAIL_ADDRESS_REQUIRED");
|
|
});
|
|
|
|
test("getlogin returns PASSWORD_REQUIRED when pwd missing", async () => {
|
|
const mod = loadModule("pages/api/endpoint/getlogin_api.js", {
|
|
respondError: respondErrorMock,
|
|
respondSuccess: respondSuccessMock,
|
|
getToken: async () => ({ access_token: "token" }),
|
|
hashAPIPath: () => "&hash=expected",
|
|
azureHeadersPaged: () => ({}),
|
|
axios: { get: async () => ({ data: { value: [] } }) },
|
|
consoleLogger: () => {}
|
|
});
|
|
|
|
const req = { query: { emailAddress: "user@test.local" } };
|
|
const res = createRes();
|
|
await mod.default(req, res);
|
|
|
|
assert.strictEqual(res.state.statusCode, 400);
|
|
assert.strictEqual(res.state.jsonBody.error.code, "PASSWORD_REQUIRED");
|
|
});
|
|
|
|
test("getlogin catch path returns LOGIN_FETCH_FAILED", async () => {
|
|
const mod = loadModule("pages/api/endpoint/getlogin_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: { emailAddress: "user@test.local", pwd: "abc123" } };
|
|
const res = createRes();
|
|
await mod.default(req, res);
|
|
|
|
assert.strictEqual(res.state.statusCode, 400);
|
|
assert.strictEqual(res.state.jsonBody.error.code, "LOGIN_FETCH_FAILED");
|
|
});
|
|
|
|
test("getportallogin returns HASH_REQUIRED when hash missing", async () => {
|
|
const mod = loadModule("pages/api/endpoint/getportallogin_api.js", {
|
|
respondError: respondErrorMock,
|
|
respondSuccess: respondSuccessMock,
|
|
getToken: async () => ({ access_token: "token" }),
|
|
hashAPIPath: (input) =>
|
|
input && input.startsWith("/api/endpoint/getportallogin_api")
|
|
? "&hash=expected"
|
|
: "&hash=relay",
|
|
azureHeadersPaged: () => ({}),
|
|
axios: { get: async () => ({ data: { value: [] } }) },
|
|
consoleLogger: () => {}
|
|
});
|
|
|
|
const req = { query: { emailAddress: "user@test.local" } };
|
|
const res = createRes();
|
|
await mod.default(req, res);
|
|
|
|
assert.strictEqual(res.state.statusCode, 400);
|
|
assert.strictEqual(res.state.jsonBody.error.code, "HASH_REQUIRED");
|
|
});
|
|
|
|
test("getportallogin returns INVALID_HASH when hash mismatch", async () => {
|
|
const mod = loadModule("pages/api/endpoint/getportallogin_api.js", {
|
|
respondError: respondErrorMock,
|
|
respondSuccess: respondSuccessMock,
|
|
getToken: async () => ({ access_token: "token" }),
|
|
hashAPIPath: (input) =>
|
|
input && input.startsWith("/api/endpoint/getportallogin_api")
|
|
? "&hash=expected"
|
|
: "&hash=relay",
|
|
azureHeadersPaged: () => ({}),
|
|
axios: { get: async () => ({ data: { value: [] } }) },
|
|
consoleLogger: () => {}
|
|
});
|
|
|
|
const req = { query: { emailAddress: "user@test.local", hash: "wrong" } };
|
|
const res = createRes();
|
|
await mod.default(req, res);
|
|
|
|
assert.strictEqual(res.state.statusCode, 400);
|
|
assert.strictEqual(res.state.jsonBody.error.code, "INVALID_HASH");
|
|
});
|
|
|
|
test("getportallogin catch path returns PORTAL_LOGIN_FETCH_FAILED", async () => {
|
|
const mod = loadModule("pages/api/endpoint/getportallogin_api.js", {
|
|
respondError: respondErrorMock,
|
|
respondSuccess: respondSuccessMock,
|
|
getToken: async () => ({ access_token: "token" }),
|
|
hashAPIPath: (input) =>
|
|
input && input.startsWith("/api/endpoint/getportallogin_api")
|
|
? "&hash=expected"
|
|
: "&hash=relay",
|
|
azureHeadersPaged: () => ({}),
|
|
axios: {
|
|
get: async () => {
|
|
throw new Error("relay failed");
|
|
}
|
|
},
|
|
consoleLogger: () => {}
|
|
});
|
|
|
|
const req = {
|
|
query: { emailAddress: "user@test.local", hash: "expected" }
|
|
};
|
|
const res = createRes();
|
|
await mod.default(req, res);
|
|
|
|
assert.strictEqual(res.state.statusCode, 400);
|
|
assert.strictEqual(
|
|
res.state.jsonBody.error.code,
|
|
"PORTAL_LOGIN_FETCH_FAILED"
|
|
);
|
|
});
|
|
|
|
test("getportalloginproxy catch path returns PORTAL_LOGIN_PROXY_FETCH_FAILED", async () => {
|
|
const mod = loadModule("pages/api/endpoint/getportalloginproxy_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: { emailAddress: "user@test.local" } };
|
|
const res = createRes();
|
|
await mod.default(req, res);
|
|
|
|
assert.strictEqual(res.state.statusCode, 400);
|
|
assert.strictEqual(
|
|
res.state.jsonBody.error.code,
|
|
"PORTAL_LOGIN_PROXY_FETCH_FAILED"
|
|
);
|
|
});
|
|
|
|
test("getpersonalaccount returns CONTACT_ID_REQUIRED when contactid missing", async () => {
|
|
const mod = loadModule("pages/api/endpoint/getpersonalaccount_api.js", {
|
|
respondError: respondErrorMock,
|
|
respondSuccess: respondSuccessMock,
|
|
getToken: async () => ({ access_token: "token" }),
|
|
hashAPIPath: () => "&hash=expected",
|
|
azureHeaders: () => ({}),
|
|
axios: { get: async () => ({ data: { contactid: "c1" } }) },
|
|
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, "CONTACT_ID_REQUIRED");
|
|
});
|
|
|
|
test("getpersonalaccount catch path returns PERSONAL_ACCOUNT_FETCH_FAILED", async () => {
|
|
const mod = loadModule("pages/api/endpoint/getpersonalaccount_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: { contactid: "c1" } };
|
|
const res = createRes();
|
|
await mod.default(req, res);
|
|
|
|
assert.strictEqual(res.state.statusCode, 400);
|
|
assert.strictEqual(
|
|
res.state.jsonBody.error.code,
|
|
"PERSONAL_ACCOUNT_FETCH_FAILED"
|
|
);
|
|
});
|
|
|
|
test("getaccounts success returns existing data payload contract", async () => {
|
|
const mod = loadModule("pages/api/endpoint/getaccounts_api.js", {
|
|
respondError: respondErrorMock,
|
|
respondSuccess: respondSuccessMock,
|
|
getToken: async () => ({ access_token: "token" }),
|
|
hashAPIPath: () => "&hash=expected",
|
|
azureHeaders: () => ({}),
|
|
axios: {
|
|
get: async () => ({ data: { value: [{ contactid: "c1" }] } })
|
|
},
|
|
consoleLogger: () => {}
|
|
});
|
|
|
|
const req = { query: { emailAddress: "user@test.local" } };
|
|
const res = createRes();
|
|
await mod.default(req, res);
|
|
|
|
assert.strictEqual(res.state.statusCode, 200);
|
|
assert.deepStrictEqual(JSON.parse(JSON.stringify(res.state.jsonBody)), {
|
|
value: [{ contactid: "c1" }]
|
|
});
|
|
});
|
|
|
|
test("getemailaccountcheck success returns existing data payload contract", async () => {
|
|
const mod = loadModule("pages/api/endpoint/getemailaccountcheck_api.js", {
|
|
respondError: respondErrorMock,
|
|
respondSuccess: respondSuccessMock,
|
|
getToken: async () => ({ access_token: "token" }),
|
|
hashAPIPath: () => "&hash=expected",
|
|
azureHeaders: () => ({}),
|
|
axios: {
|
|
get: async () => ({
|
|
data: { value: [{ emailaddress1: "u@test" }] }
|
|
})
|
|
},
|
|
consoleLogger: () => {}
|
|
});
|
|
|
|
const req = { query: { emailAddress: "user@test.local" } };
|
|
const res = createRes();
|
|
await mod.default(req, res);
|
|
|
|
assert.strictEqual(res.state.statusCode, 200);
|
|
assert.deepStrictEqual(JSON.parse(JSON.stringify(res.state.jsonBody)), {
|
|
value: [{ emailaddress1: "u@test" }]
|
|
});
|
|
});
|
|
|
|
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"
|
|
);
|
|
});
|
|
|
|
test("getsearchdocumenthistory returns DOCUMENT_ID_REQUIRED when documentid missing", async () => {
|
|
const mod = loadModule(
|
|
"pages/api/endpoint/getsearchdocumenthistory_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, "DOCUMENT_ID_REQUIRED");
|
|
});
|
|
|
|
test("getsearchdocumenthistory catch path returns SEARCH_DOCUMENT_HISTORY_FETCH_FAILED", async () => {
|
|
const mod = loadModule(
|
|
"pages/api/endpoint/getsearchdocumenthistory_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: { documentid: "d1" } };
|
|
const res = createRes();
|
|
await mod.default(req, res);
|
|
|
|
assert.strictEqual(res.state.statusCode, 400);
|
|
assert.strictEqual(
|
|
res.state.jsonBody.error.code,
|
|
"SEARCH_DOCUMENT_HISTORY_FETCH_FAILED"
|
|
);
|
|
});
|
|
|
|
test("getsearchdocumenthistory success returns existing data payload contract", async () => {
|
|
const mod = loadModule(
|
|
"pages/api/endpoint/getsearchdocumenthistory_api.js",
|
|
{
|
|
respondError: respondErrorMock,
|
|
respondSuccess: respondSuccessMock,
|
|
getToken: async () => ({ access_token: "token" }),
|
|
hashAPIPath: () => "&hash=expected",
|
|
azureHeadersPaged: () => ({}),
|
|
axios: {
|
|
get: async () => ({
|
|
data: { value: [{ _pinswg_documentid_value: "d1" }] }
|
|
})
|
|
},
|
|
consoleLogger: () => {}
|
|
}
|
|
);
|
|
|
|
const req = { query: { documentid: "d1" } };
|
|
const res = createRes();
|
|
await mod.default(req, res);
|
|
|
|
assert.strictEqual(res.state.statusCode, 200);
|
|
assert.deepStrictEqual(JSON.parse(JSON.stringify(res.state.jsonBody)), {
|
|
value: [{ _pinswg_documentid_value: "d1" }]
|
|
});
|
|
});
|
|
|
|
test("getsearchdocumenthistorypaged returns DOCUMENT_ID_REQUIRED when documentid missing", async () => {
|
|
const mod = loadModule(
|
|
"pages/api/endpoint/getsearchdocumenthistorypaged_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, "DOCUMENT_ID_REQUIRED");
|
|
});
|
|
|
|
test("getsearchdocumenthistorypaged catch path returns SEARCH_DOCUMENT_HISTORY_PAGED_FETCH_FAILED", async () => {
|
|
const mod = loadModule(
|
|
"pages/api/endpoint/getsearchdocumenthistorypaged_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: { documentid: "d1" } };
|
|
const res = createRes();
|
|
await mod.default(req, res);
|
|
|
|
assert.strictEqual(res.state.statusCode, 400);
|
|
assert.strictEqual(
|
|
res.state.jsonBody.error.code,
|
|
"SEARCH_DOCUMENT_HISTORY_PAGED_FETCH_FAILED"
|
|
);
|
|
});
|
|
|
|
test("getsearchdocumentdetails returns INCIDENT_ID_REQUIRED when incidentid missing", async () => {
|
|
const mod = loadModule(
|
|
"pages/api/endpoint/getsearchdocumentdetails_api.js",
|
|
{
|
|
respondError: respondErrorMock,
|
|
respondSuccess: respondSuccessMock,
|
|
getToken: async () => ({ access_token: "token" }),
|
|
hashAPIPath: () => "&hash=expected",
|
|
azureHeadersPaged: () => ({}),
|
|
axios: { get: async () => ({ data: { value: [] } }) },
|
|
consoleLogger: () => {},
|
|
CryptoJS: {
|
|
HmacSHA256: () => ({ toString: () => "hash" }),
|
|
enc: { Hex: { parse: () => "parsed", stringify: () => "hex" } }
|
|
},
|
|
_: { has: () => false }
|
|
}
|
|
);
|
|
|
|
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("getsearchdocumentdetails catch path returns SEARCH_DOCUMENT_DETAILS_FETCH_FAILED", async () => {
|
|
const mod = loadModule(
|
|
"pages/api/endpoint/getsearchdocumentdetails_api.js",
|
|
{
|
|
respondError: respondErrorMock,
|
|
respondSuccess: respondSuccessMock,
|
|
getToken: async () => ({ access_token: "token" }),
|
|
hashAPIPath: () => "&hash=expected",
|
|
azureHeadersPaged: () => ({}),
|
|
axios: {
|
|
get: async () => {
|
|
throw new Error("relay failed");
|
|
}
|
|
},
|
|
consoleLogger: () => {},
|
|
CryptoJS: {
|
|
HmacSHA256: () => ({ toString: () => "hash" }),
|
|
enc: { Hex: { parse: () => "parsed", stringify: () => "hex" } }
|
|
},
|
|
_: { has: () => false }
|
|
}
|
|
);
|
|
|
|
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,
|
|
"SEARCH_DOCUMENT_DETAILS_FETCH_FAILED"
|
|
);
|
|
});
|
|
|
|
test("getsearchdocumentdetailspaged returns INCIDENT_ID_REQUIRED when incidentid missing", async () => {
|
|
const mod = loadModule(
|
|
"pages/api/endpoint/getsearchdocumentdetailspaged_api.js",
|
|
{
|
|
respondError: respondErrorMock,
|
|
respondSuccess: respondSuccessMock,
|
|
getToken: async () => ({ access_token: "token" }),
|
|
hashAPIPath: () => "&hash=expected",
|
|
azureHeadersPagedCustom: () => ({}),
|
|
axios: { get: async () => ({ data: { value: [] } }) },
|
|
consoleLogger: () => {},
|
|
CryptoJS: {
|
|
HmacSHA256: () => ({ toString: () => "hash" }),
|
|
enc: { Hex: { parse: () => "parsed", stringify: () => "hex" } }
|
|
},
|
|
_: { 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, "INCIDENT_ID_REQUIRED");
|
|
});
|
|
|
|
test("getsearchdocumentdetailspaged catch path returns SEARCH_DOCUMENT_DETAILS_PAGED_FETCH_FAILED", async () => {
|
|
const mod = loadModule(
|
|
"pages/api/endpoint/getsearchdocumentdetailspaged_api.js",
|
|
{
|
|
respondError: respondErrorMock,
|
|
respondSuccess: respondSuccessMock,
|
|
getToken: async () => ({ access_token: "token" }),
|
|
hashAPIPath: () => "&hash=expected",
|
|
azureHeadersPagedCustom: () => ({}),
|
|
axios: {
|
|
get: async () => {
|
|
throw new Error("relay failed");
|
|
}
|
|
},
|
|
consoleLogger: () => {},
|
|
CryptoJS: {
|
|
HmacSHA256: () => ({ toString: () => "hash" }),
|
|
enc: { Hex: { parse: () => "parsed", stringify: () => "hex" } }
|
|
},
|
|
_: { has: () => false }
|
|
}
|
|
);
|
|
|
|
const req = {
|
|
query: {
|
|
incidentid: "i1",
|
|
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_DOCUMENT_DETAILS_PAGED_FETCH_FAILED"
|
|
);
|
|
});
|
|
|
|
test("getsearchdocumentTypes returns INCIDENT_ID_REQUIRED when incidentid missing", async () => {
|
|
const mod = loadModule("pages/api/endpoint/getsearchdocumentTypes_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("getsearchdocumentTypes catch path returns SEARCH_DOCUMENT_TYPES_FETCH_FAILED", async () => {
|
|
const mod = loadModule("pages/api/endpoint/getsearchdocumentTypes_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,
|
|
"SEARCH_DOCUMENT_TYPES_FETCH_FAILED"
|
|
);
|
|
});
|
|
|
|
test("getsearchdocumentTypes success returns grouped data payload contract", async () => {
|
|
const mod = loadModule("pages/api/endpoint/getsearchdocumentTypes_api.js", {
|
|
respondError: respondErrorMock,
|
|
respondSuccess: respondSuccessMock,
|
|
getToken: async () => ({ access_token: "token" }),
|
|
hashAPIPath: () => "&hash=expected",
|
|
azureHeaders: () => ({}),
|
|
axios: {
|
|
get: async () => ({
|
|
data: {
|
|
value: [
|
|
{
|
|
pinswg_isharedocumentlocations: 1,
|
|
"pinswg_isharedocumentlocations@OData.Community.Display.V1.FormattedValue":
|
|
"Plans"
|
|
},
|
|
{
|
|
pinswg_isharedocumentlocations: 1,
|
|
"pinswg_isharedocumentlocations@OData.Community.Display.V1.FormattedValue":
|
|
"Plans"
|
|
},
|
|
{
|
|
pinswg_isharedocumentlocations: 2,
|
|
"pinswg_isharedocumentlocations@OData.Community.Display.V1.FormattedValue":
|
|
"Letters"
|
|
}
|
|
]
|
|
}
|
|
})
|
|
},
|
|
consoleLogger: () => {}
|
|
});
|
|
|
|
const req = { query: { incidentid: "i1" } };
|
|
const res = createRes();
|
|
await mod.default(req, res);
|
|
|
|
assert.strictEqual(res.state.statusCode, 200);
|
|
assert.deepStrictEqual(JSON.parse(JSON.stringify(res.state.jsonBody)), [
|
|
{
|
|
pinswg_isharedocumentlocations: 1,
|
|
pinswg_isharedocumentlocationsLabel: "Plans",
|
|
count: 2
|
|
},
|
|
{
|
|
pinswg_isharedocumentlocations: 2,
|
|
pinswg_isharedocumentlocationsLabel: "Letters",
|
|
count: 1
|
|
}
|
|
]);
|
|
});
|
|
|
|
test("getmycases returns LOGGED_IN_USER_ID_REQUIRED when loggedInUserId missing", async () => {
|
|
const mod = loadModule("pages/api/endpoint/getmycases_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("getmycases catch path returns MY_CASES_FETCH_FAILED", async () => {
|
|
const mod = loadModule("pages/api/endpoint/getmycases_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_CASES_FETCH_FAILED");
|
|
});
|
|
|
|
test("getmyrepresentations returns LOGGED_IN_USER_ID_REQUIRED when loggedInUserId missing", async () => {
|
|
const mod = loadModule("pages/api/endpoint/getmyrepresentations_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("getmyrepresentations catch path returns MY_REPRESENTATIONS_FETCH_FAILED", async () => {
|
|
const mod = loadModule("pages/api/endpoint/getmyrepresentations_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_FETCH_FAILED"
|
|
);
|
|
});
|
|
|
|
test("getwatchedcases returns LOGGED_IN_USER_ID_REQUIRED when loggedInUserId missing", async () => {
|
|
const mod = loadModule("pages/api/endpoint/getwatchedcases_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("getwatchedcases catch path returns WATCHED_CASES_FETCH_FAILED", async () => {
|
|
const mod = loadModule("pages/api/endpoint/getwatchedcases_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_FETCH_FAILED"
|
|
);
|
|
});
|
|
|
|
test("getawaitingsubmission returns LOGGED_IN_USER_ID_REQUIRED when loggedInUserId missing", async () => {
|
|
const mod = loadModule("pages/api/endpoint/getawaitingsubmission_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("getawaitingsubmission catch path returns AWAITING_SUBMISSION_FETCH_FAILED", async () => {
|
|
const mod = loadModule("pages/api/endpoint/getawaitingsubmission_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_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"
|
|
);
|
|
});
|
|
|
|
test("getbasicdnssearch catch path returns BASIC_DNS_SEARCH_FETCH_FAILED", async () => {
|
|
const mod = loadModule("pages/api/endpoint/getbasicdnssearch_api.js", {
|
|
respondError: respondErrorMock,
|
|
respondSuccess: respondSuccessMock,
|
|
getToken: async () => ({ access_token: "token" }),
|
|
hashAPIPath: () => "&hash=expected",
|
|
azureHeadersPaged: () => ({}),
|
|
axios: {
|
|
get: async () => {
|
|
throw new Error("relay failed");
|
|
}
|
|
},
|
|
consoleLogger: () => {},
|
|
_: { has: () => false }
|
|
});
|
|
|
|
const req = { query: {} };
|
|
const res = createRes();
|
|
await mod.default(req, res);
|
|
|
|
assert.strictEqual(res.state.statusCode, 400);
|
|
assert.strictEqual(
|
|
res.state.jsonBody.error.code,
|
|
"BASIC_DNS_SEARCH_FETCH_FAILED"
|
|
);
|
|
});
|
|
|
|
test("getbasicdnssearchpaged returns ORDER_BY_REQUIRED when orderby missing", async () => {
|
|
const mod = loadModule("pages/api/endpoint/getbasicdnssearchpaged_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: { 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("getbasicdnssearchpaged catch path returns BASIC_DNS_SEARCH_PAGED_FETCH_FAILED", async () => {
|
|
const mod = loadModule("pages/api/endpoint/getbasicdnssearchpaged_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: {
|
|
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_DNS_SEARCH_PAGED_FETCH_FAILED"
|
|
);
|
|
});
|
|
|
|
test("getbasicdnssearchdetails returns CASE_REFERENCE_REQUIRED when caseReference missing", async () => {
|
|
const mod = loadModule(
|
|
"pages/api/endpoint/getbasicdnssearchdetails_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: {} };
|
|
const res = createRes();
|
|
await mod.default(req, res);
|
|
|
|
assert.strictEqual(res.state.statusCode, 400);
|
|
assert.strictEqual(
|
|
res.state.jsonBody.error.code,
|
|
"CASE_REFERENCE_REQUIRED"
|
|
);
|
|
});
|
|
|
|
test("getbasicdnssearchdetails catch path returns BASIC_DNS_SEARCH_DETAILS_FETCH_FAILED", async () => {
|
|
const mod = loadModule(
|
|
"pages/api/endpoint/getbasicdnssearchdetails_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: { caseReference: "DNS-001" } };
|
|
const res = createRes();
|
|
await mod.default(req, res);
|
|
|
|
assert.strictEqual(res.state.statusCode, 400);
|
|
assert.strictEqual(
|
|
res.state.jsonBody.error.code,
|
|
"BASIC_DNS_SEARCH_DETAILS_FETCH_FAILED"
|
|
);
|
|
});
|
|
|
|
test("getbasicdnssearchdetailspaged returns CASE_REFERENCE_REQUIRED when caseReference missing", async () => {
|
|
const mod = loadModule(
|
|
"pages/api/endpoint/getbasicdnssearchdetailspaged_api.js",
|
|
{
|
|
respondError: respondErrorMock,
|
|
respondSuccess: respondSuccessMock,
|
|
getToken: async () => ({ access_token: "token" }),
|
|
getSelectQuery: () => "&$select=pinswg_name",
|
|
hashAPIPath: () => "&hash=expected",
|
|
azureHeadersPaged: () => ({}),
|
|
axios: { get: async () => ({ data: { value: [] } }) },
|
|
consoleLogger: () => {},
|
|
_: { has: () => false }
|
|
}
|
|
);
|
|
|
|
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_REFERENCE_REQUIRED"
|
|
);
|
|
});
|
|
|
|
test("getbasicdnssearchdetailspaged catch path returns BASIC_DNS_SEARCH_DETAILS_PAGED_FETCH_FAILED", async () => {
|
|
const mod = loadModule(
|
|
"pages/api/endpoint/getbasicdnssearchdetailspaged_api.js",
|
|
{
|
|
respondError: respondErrorMock,
|
|
respondSuccess: respondSuccessMock,
|
|
getToken: async () => ({ access_token: "token" }),
|
|
getSelectQuery: () => "&$select=pinswg_name",
|
|
hashAPIPath: () => "&hash=expected",
|
|
azureHeadersPaged: () => ({}),
|
|
axios: {
|
|
get: async () => {
|
|
throw new Error("relay failed");
|
|
}
|
|
},
|
|
consoleLogger: () => {},
|
|
_: { has: () => false }
|
|
}
|
|
);
|
|
|
|
const req = { query: { caseReference: "DNS-001" } };
|
|
const res = createRes();
|
|
await mod.default(req, res);
|
|
|
|
assert.strictEqual(res.state.statusCode, 400);
|
|
assert.strictEqual(
|
|
res.state.jsonBody.error.code,
|
|
"BASIC_DNS_SEARCH_DETAILS_PAGED_FETCH_FAILED"
|
|
);
|
|
});
|
|
|
|
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"
|
|
);
|
|
});
|
|
|
|
test("getcase returns INCIDENT_ID_REQUIRED when incidentID missing", async () => {
|
|
const mod = loadModule("pages/api/endpoint/getcase_api.js", {
|
|
respondError: respondErrorMock,
|
|
respondSuccess: respondSuccessMock,
|
|
getToken: async () => ({ access_token: "token" }),
|
|
hashAPIPath: () => "&hash=expected",
|
|
azureHeaders: () => ({}),
|
|
axios: { get: async () => ({ data: { ticketnumber: "CAS-1" } }) },
|
|
consoleLogger: () => {},
|
|
_: { has: () => false }
|
|
});
|
|
|
|
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("getcase catch path returns CASE_FETCH_FAILED", async () => {
|
|
const mod = loadModule("pages/api/endpoint/getcase_api.js", {
|
|
respondError: respondErrorMock,
|
|
respondSuccess: respondSuccessMock,
|
|
getToken: async () => ({ access_token: "token" }),
|
|
hashAPIPath: () => "&hash=expected",
|
|
azureHeaders: () => ({}),
|
|
axios: {
|
|
get: async () => {
|
|
throw new Error("relay failed");
|
|
}
|
|
},
|
|
consoleLogger: () => {},
|
|
_: { has: () => false }
|
|
});
|
|
|
|
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, "CASE_FETCH_FAILED");
|
|
});
|
|
|
|
test("getcasebyid returns INCIDENT_ID_REQUIRED when incidentID missing", async () => {
|
|
const mod = loadModule("pages/api/endpoint/getcasebyid_api.js", {
|
|
respondError: respondErrorMock,
|
|
respondSuccess: respondSuccessMock,
|
|
getToken: async () => ({ access_token: "token" }),
|
|
hashAPIPath: () => "&hash=expected",
|
|
azureHeaders: () => ({}),
|
|
axios: { get: async () => ({ data: { ticketnumber: "CAS-1" } }) },
|
|
consoleLogger: () => {},
|
|
_: { has: () => false }
|
|
});
|
|
|
|
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("getcasebyid catch path returns CASE_BY_ID_FETCH_FAILED", async () => {
|
|
const mod = loadModule("pages/api/endpoint/getcasebyid_api.js", {
|
|
respondError: respondErrorMock,
|
|
respondSuccess: respondSuccessMock,
|
|
getToken: async () => ({ access_token: "token" }),
|
|
hashAPIPath: () => "&hash=expected",
|
|
azureHeaders: () => ({}),
|
|
axios: {
|
|
get: async () => {
|
|
throw new Error("relay failed");
|
|
}
|
|
},
|
|
consoleLogger: () => {},
|
|
_: { has: () => false }
|
|
});
|
|
|
|
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,
|
|
"CASE_BY_ID_FETCH_FAILED"
|
|
);
|
|
});
|
|
|
|
test("getincidentbyid returns SEARCH_STRING_REQUIRED when searchString missing", async () => {
|
|
const mod = loadModule("pages/api/endpoint/getincidentbyid_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, "SEARCH_STRING_REQUIRED");
|
|
});
|
|
|
|
test("getincidentbyid catch path returns INCIDENT_BY_ID_FETCH_FAILED", async () => {
|
|
const mod = loadModule("pages/api/endpoint/getincidentbyid_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: { searchString: "incident-guid" } };
|
|
const res = createRes();
|
|
await mod.default(req, res);
|
|
|
|
assert.strictEqual(res.state.statusCode, 400);
|
|
assert.strictEqual(
|
|
res.state.jsonBody.error.code,
|
|
"INCIDENT_BY_ID_FETCH_FAILED"
|
|
);
|
|
});
|
|
|
|
test("createwatchedcases returns WATCHED_CASE_BINDINGS_REQUIRED when bindings missing", async () => {
|
|
const mod = loadModule("pages/api/endpoint/createwatchedcases_api.js", {
|
|
respondError: respondErrorMock,
|
|
respondSuccess: respondSuccessMock,
|
|
getToken: async () => ({ access_token: "token" }),
|
|
hashAPIPath: () => "&hash=expected",
|
|
axios: async () => ({ data: {} }),
|
|
consoleLogger: () => {}
|
|
});
|
|
|
|
const req = { body: {} };
|
|
const res = createRes();
|
|
await mod.default(req, res);
|
|
|
|
assert.strictEqual(res.state.statusCode, 400);
|
|
assert.strictEqual(
|
|
res.state.jsonBody.error.code,
|
|
"WATCHED_CASE_BINDINGS_REQUIRED"
|
|
);
|
|
});
|
|
|
|
test("createwatchedcases returns INVALID_BINDING_FORMAT when bindings invalid", async () => {
|
|
const mod = loadModule("pages/api/endpoint/createwatchedcases_api.js", {
|
|
respondError: respondErrorMock,
|
|
respondSuccess: respondSuccessMock,
|
|
getToken: async () => ({ access_token: "token" }),
|
|
hashAPIPath: () => "&hash=expected",
|
|
axios: async () => ({ data: {} }),
|
|
consoleLogger: () => {}
|
|
});
|
|
|
|
const req = {
|
|
body: {
|
|
"pinswg_WatchedCase@odata.bind": "/incidents",
|
|
"pinswg_Contact@odata.bind": "/contacts"
|
|
}
|
|
};
|
|
const res = createRes();
|
|
await mod.default(req, res);
|
|
|
|
assert.strictEqual(res.state.statusCode, 400);
|
|
assert.strictEqual(res.state.jsonBody.error.code, "INVALID_BINDING_FORMAT");
|
|
});
|
|
|
|
test("createwatchedcases catch path returns WATCHED_CASE_UPSERT_FAILED", async () => {
|
|
const mod = loadModule("pages/api/endpoint/createwatchedcases_api.js", {
|
|
respondError: respondErrorMock,
|
|
respondSuccess: respondSuccessMock,
|
|
getToken: async () => {
|
|
throw new Error("token failed");
|
|
},
|
|
hashAPIPath: () => "&hash=expected",
|
|
axios: async () => ({ data: {} }),
|
|
consoleLogger: () => {}
|
|
});
|
|
|
|
const req = {
|
|
body: {
|
|
"pinswg_WatchedCase@odata.bind": "/incidents(incident-id)",
|
|
"pinswg_Contact@odata.bind": "/contacts(contact-id)"
|
|
}
|
|
};
|
|
const res = createRes();
|
|
await mod.default(req, res);
|
|
|
|
assert.strictEqual(res.state.statusCode, 400);
|
|
assert.strictEqual(
|
|
res.state.jsonBody.error.code,
|
|
"WATCHED_CASE_UPSERT_FAILED"
|
|
);
|
|
});
|
|
|
|
test("deletewatchedcases returns WATCHED_CASE_ID_REQUIRED when watchedCaseID missing", async () => {
|
|
const mod = loadModule("pages/api/endpoint/deletewatchedcases_api.js", {
|
|
respondError: respondErrorMock,
|
|
respondSuccess: respondSuccessMock,
|
|
getToken: async () => ({ access_token: "token" }),
|
|
hashAPIPath: () => "&hash=expected",
|
|
axios: async () => ({ data: {} }),
|
|
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,
|
|
"WATCHED_CASE_ID_REQUIRED"
|
|
);
|
|
});
|
|
|
|
test("deletewatchedcases catch path returns WATCHED_CASE_DELETE_FAILED", async () => {
|
|
const mod = loadModule("pages/api/endpoint/deletewatchedcases_api.js", {
|
|
respondError: respondErrorMock,
|
|
respondSuccess: respondSuccessMock,
|
|
getToken: async () => ({ access_token: "token" }),
|
|
hashAPIPath: () => "&hash=expected",
|
|
axios: async () => {
|
|
throw new Error("delete failed");
|
|
},
|
|
consoleLogger: () => {}
|
|
});
|
|
|
|
const req = { query: { watchedCaseID: "w1" } };
|
|
const res = createRes();
|
|
await mod.default(req, res);
|
|
|
|
assert.strictEqual(res.state.statusCode, 400);
|
|
assert.strictEqual(
|
|
res.state.jsonBody.error.code,
|
|
"WATCHED_CASE_DELETE_FAILED"
|
|
);
|
|
});
|
|
|
|
test("deletewatchedcasesproxy returns WATCHED_CASE_ID_REQUIRED when watchedCaseID missing", async () => {
|
|
const mod = loadModule(
|
|
"pages/api/endpoint/deletewatchedcasesproxy_api.js",
|
|
{
|
|
respondError: respondErrorMock,
|
|
respondSuccess: respondSuccessMock,
|
|
getToken: async () => ({ access_token: "token" }),
|
|
hashAPIPath: () => "&hash=expected",
|
|
azureHeaders: () => ({}),
|
|
axios: { get: async () => ({ data: {} }) },
|
|
consoleLogger: () => {},
|
|
process: { env: {} }
|
|
}
|
|
);
|
|
|
|
const req = { query: {} };
|
|
const res = createRes();
|
|
await mod.default(req, res);
|
|
|
|
assert.strictEqual(res.state.statusCode, 400);
|
|
assert.strictEqual(
|
|
res.state.jsonBody.error.code,
|
|
"WATCHED_CASE_ID_REQUIRED"
|
|
);
|
|
});
|
|
|
|
test("deletewatchedcasesproxy catch path returns WATCHED_CASE_PROXY_DELETE_FAILED", async () => {
|
|
const mod = loadModule(
|
|
"pages/api/endpoint/deletewatchedcasesproxy_api.js",
|
|
{
|
|
respondError: respondErrorMock,
|
|
respondSuccess: respondSuccessMock,
|
|
getToken: async () => ({ access_token: "token" }),
|
|
hashAPIPath: () => "&hash=expected",
|
|
azureHeaders: () => ({}),
|
|
axios: {
|
|
get: async () => {
|
|
throw new Error("proxy delete failed");
|
|
}
|
|
},
|
|
consoleLogger: () => {},
|
|
process: { env: {} }
|
|
}
|
|
);
|
|
|
|
const req = { query: { watchedCaseID: "w1" } };
|
|
const res = createRes();
|
|
await mod.default(req, res);
|
|
|
|
assert.strictEqual(res.state.statusCode, 400);
|
|
assert.strictEqual(
|
|
res.state.jsonBody.error.code,
|
|
"WATCHED_CASE_PROXY_DELETE_FAILED"
|
|
);
|
|
});
|
|
|
|
test("deletemyrepresentations returns MY_REPRESENTATION_ID_REQUIRED when myRepresentationsID missing", async () => {
|
|
const mod = loadModule(
|
|
"pages/api/endpoint/deletemyrepresentations_api.js",
|
|
{
|
|
respondError: respondErrorMock,
|
|
respondSuccess: respondSuccessMock,
|
|
getToken: async () => ({ access_token: "token" }),
|
|
hashAPIPath: () => "&hash=expected",
|
|
axios: async () => ({ data: {} }),
|
|
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,
|
|
"MY_REPRESENTATION_ID_REQUIRED"
|
|
);
|
|
});
|
|
|
|
test("deletemyrepresentations catch path returns MY_REPRESENTATION_DELETE_FAILED", async () => {
|
|
const mod = loadModule(
|
|
"pages/api/endpoint/deletemyrepresentations_api.js",
|
|
{
|
|
respondError: respondErrorMock,
|
|
respondSuccess: respondSuccessMock,
|
|
getToken: async () => ({ access_token: "token" }),
|
|
hashAPIPath: () => "&hash=expected",
|
|
axios: async () => {
|
|
throw new Error("delete failed");
|
|
},
|
|
consoleLogger: () => {}
|
|
}
|
|
);
|
|
|
|
const req = { query: { myRepresentationsID: "r1" } };
|
|
const res = createRes();
|
|
await mod.default(req, res);
|
|
|
|
assert.strictEqual(res.state.statusCode, 400);
|
|
assert.strictEqual(
|
|
res.state.jsonBody.error.code,
|
|
"MY_REPRESENTATION_DELETE_FAILED"
|
|
);
|
|
});
|
|
|
|
test("deleteawaitingsubmissions returns INCIDENT_ID_REQUIRED when incidentID missing", async () => {
|
|
const mod = loadModule(
|
|
"pages/api/endpoint/deleteawaitingsubmissions_api.js",
|
|
{
|
|
respondError: respondErrorMock,
|
|
respondSuccess: respondSuccessMock,
|
|
getToken: async () => ({ access_token: "token" }),
|
|
hashAPIPath: () => "&hash=expected",
|
|
axios: async () => ({ data: {} }),
|
|
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("deleteawaitingsubmissions catch path returns AWAITING_SUBMISSION_DELETE_FAILED", async () => {
|
|
const mod = loadModule(
|
|
"pages/api/endpoint/deleteawaitingsubmissions_api.js",
|
|
{
|
|
respondError: respondErrorMock,
|
|
respondSuccess: respondSuccessMock,
|
|
getToken: async () => ({ access_token: "token" }),
|
|
hashAPIPath: () => "&hash=expected",
|
|
axios: async () => {
|
|
throw new Error("delete 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,
|
|
"AWAITING_SUBMISSION_DELETE_FAILED"
|
|
);
|
|
});
|
|
|
|
test("getlpa catch path returns LPA_FETCH_FAILED", async () => {
|
|
const mod = loadModule("pages/api/endpoint/getlpa_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: {} };
|
|
const res = createRes();
|
|
await mod.default(req, res);
|
|
|
|
assert.strictEqual(res.state.statusCode, 400);
|
|
assert.strictEqual(res.state.jsonBody.error.code, "LPA_FETCH_FAILED");
|
|
});
|
|
|
|
test("getappealid returns CASE_REFERENCE_REQUIRED when caseReference missing", async () => {
|
|
const mod = loadModule("pages/api/endpoint/getappealid_api.js", {
|
|
respondError: respondErrorMock,
|
|
respondSuccess: respondSuccessMock,
|
|
getToken: async () => ({ access_token: "token" }),
|
|
hashAPIPath: () => "&hash=expected",
|
|
azureHeaders: () => ({}),
|
|
axios: { get: async () => ({ data: { value: [] } }) },
|
|
consoleLogger: () => {}
|
|
});
|
|
|
|
const req = {
|
|
query: {
|
|
updateFormCollection: "pinswg_planningappeals78s",
|
|
primaryAttribute: "pinswg_planningappeals78id"
|
|
}
|
|
};
|
|
const res = createRes();
|
|
await mod.default(req, res);
|
|
|
|
assert.strictEqual(res.state.statusCode, 400);
|
|
assert.strictEqual(
|
|
res.state.jsonBody.error.code,
|
|
"CASE_REFERENCE_REQUIRED"
|
|
);
|
|
});
|
|
|
|
test("getappealid catch path returns APPEAL_ID_FETCH_FAILED", async () => {
|
|
const mod = loadModule("pages/api/endpoint/getappealid_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: {
|
|
caseReference: "CAS-1",
|
|
updateFormCollection: "pinswg_planningappeals78s",
|
|
primaryAttribute: "pinswg_planningappeals78id"
|
|
}
|
|
};
|
|
const res = createRes();
|
|
await mod.default(req, res);
|
|
|
|
assert.strictEqual(res.state.statusCode, 400);
|
|
assert.strictEqual(res.state.jsonBody.error.code, "APPEAL_ID_FETCH_FAILED");
|
|
});
|
|
|
|
test("getprojecttypes catch path returns PROJECT_TYPES_FETCH_FAILED", async () => {
|
|
const mod = loadModule("pages/api/endpoint/getprojecttypes_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: {} };
|
|
const res = createRes();
|
|
await mod.default(req, res);
|
|
|
|
assert.strictEqual(res.state.statusCode, 400);
|
|
assert.strictEqual(
|
|
res.state.jsonBody.error.code,
|
|
"PROJECT_TYPES_FETCH_FAILED"
|
|
);
|
|
});
|
|
|
|
test("getappealtypes catch path returns APPEAL_TYPES_FETCH_FAILED", async () => {
|
|
const mod = loadModule("pages/api/endpoint/getappealtypes_api.js", {
|
|
respondError: respondErrorMock,
|
|
respondSuccess: respondSuccessMock,
|
|
getToken: async () => ({ access_token: "token" }),
|
|
hashAPIPath: () => "&hash=expected",
|
|
azureHeaders: () => ({}),
|
|
axios: {
|
|
get: async () => {
|
|
throw new Error("relay failed");
|
|
}
|
|
},
|
|
consoleLogger: () => {},
|
|
process: { env: {} }
|
|
});
|
|
|
|
const req = { query: {} };
|
|
const res = createRes();
|
|
await mod.default(req, res);
|
|
|
|
assert.strictEqual(res.state.statusCode, 400);
|
|
assert.strictEqual(
|
|
res.state.jsonBody.error.code,
|
|
"APPEAL_TYPES_FETCH_FAILED"
|
|
);
|
|
});
|
|
|
|
test("getlinkedcases returns PARENT_INCIDENT_ID_REQUIRED when parentincidentid missing", async () => {
|
|
const mod = loadModule("pages/api/endpoint/getlinkedcases_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,
|
|
"PARENT_INCIDENT_ID_REQUIRED"
|
|
);
|
|
});
|
|
|
|
test("getlinkedcases catch path returns LINKED_CASES_FETCH_FAILED", async () => {
|
|
const mod = loadModule("pages/api/endpoint/getlinkedcases_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: { parentincidentid: "i1" } };
|
|
const res = createRes();
|
|
await mod.default(req, res);
|
|
|
|
assert.strictEqual(res.state.statusCode, 400);
|
|
assert.strictEqual(
|
|
res.state.jsonBody.error.code,
|
|
"LINKED_CASES_FETCH_FAILED"
|
|
);
|
|
});
|
|
|
|
const run = async () => {
|
|
let passed = 0;
|
|
for (const currentTest of tests) {
|
|
await currentTest.fn();
|
|
passed += 1;
|
|
}
|
|
console.log(
|
|
`Phase 21 endpoint-handler contract tests passed (${passed}/${tests.length}).`
|
|
);
|
|
};
|
|
|
|
module.exports = run;
|
|
|
|
if (require.main === module) {
|
|
run().catch((error) => {
|
|
console.error(error);
|
|
process.exit(1);
|
|
});
|
|
}
|