TASK22211: normalize case creation and media endpoint contracts
This commit is contained in:
@@ -3119,6 +3119,134 @@ test("getdnscoords catch path returns DNS_COORDS_FETCH_FAILED", async () => {
|
||||
);
|
||||
});
|
||||
|
||||
test("getappealpdfdocuments returns INCIDENT_ID_REQUIRED when incidentid missing", async () => {
|
||||
const mod = loadModule("pages/api/endpoint/getappealpdfdocuments_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("getappealpdfdocuments catch path returns APPEAL_PDF_DOCUMENTS_FETCH_FAILED", async () => {
|
||||
const mod = loadModule("pages/api/endpoint/getappealpdfdocuments_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,
|
||||
"APPEAL_PDF_DOCUMENTS_FETCH_FAILED"
|
||||
);
|
||||
});
|
||||
|
||||
test("createcase returns CASE_PAYLOAD_REQUIRED when body missing", async () => {
|
||||
const mod = loadModule("pages/api/endpoint/createcase_api.js", {
|
||||
respondError: respondErrorMock,
|
||||
respondSuccess: respondSuccessMock,
|
||||
getToken: async () => ({ access_token: "token" }),
|
||||
getCaseBlob: async () => {},
|
||||
hashAPIPath: () => "&hash=expected",
|
||||
axios: async () => ({ data: { ticketnumber: "CAS-1" } }),
|
||||
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, "CASE_PAYLOAD_REQUIRED");
|
||||
});
|
||||
|
||||
test("createcase returns CONTACT_ID_REQUIRED when contactid missing", async () => {
|
||||
const mod = loadModule("pages/api/endpoint/createcase_api.js", {
|
||||
respondError: respondErrorMock,
|
||||
respondSuccess: respondSuccessMock,
|
||||
getToken: async () => ({ access_token: "token" }),
|
||||
getCaseBlob: async () => {},
|
||||
hashAPIPath: () => "&hash=expected",
|
||||
axios: async () => ({ data: { ticketnumber: "CAS-1" } }),
|
||||
consoleLogger: () => {}
|
||||
});
|
||||
|
||||
const req = {
|
||||
query: { appealTypeId: "a1", containername: "c1", lpaID: "l1" },
|
||||
body: { title: "x" }
|
||||
};
|
||||
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("createcase catch path returns CASE_CREATE_FAILED", async () => {
|
||||
const mod = loadModule("pages/api/endpoint/createcase_api.js", {
|
||||
respondError: respondErrorMock,
|
||||
respondSuccess: respondSuccessMock,
|
||||
getToken: async () => ({ access_token: "token" }),
|
||||
getCaseBlob: async () => {},
|
||||
hashAPIPath: () => "&hash=expected",
|
||||
axios: async () => {
|
||||
throw new Error("create failed");
|
||||
},
|
||||
consoleLogger: () => {}
|
||||
});
|
||||
|
||||
const req = {
|
||||
query: {
|
||||
contactid: "c1",
|
||||
appealTypeId: "a1",
|
||||
containername: "container",
|
||||
lpaID: "l1"
|
||||
},
|
||||
body: { title: "x" }
|
||||
};
|
||||
const res = createRes();
|
||||
await mod.default(req, res);
|
||||
|
||||
assert.strictEqual(res.state.statusCode, 400);
|
||||
assert.strictEqual(res.state.jsonBody.error.code, "CASE_CREATE_FAILED");
|
||||
});
|
||||
|
||||
test("getsipsmedia returns success contract", async () => {
|
||||
const mod = loadModule("pages/api/endpoint/getsipsmedia_api.js", {
|
||||
respondSuccess: respondSuccessMock
|
||||
});
|
||||
|
||||
const req = { query: {} };
|
||||
const res = createRes();
|
||||
await mod.default(req, res);
|
||||
|
||||
assert.strictEqual(res.state.statusCode, 200);
|
||||
assert.strictEqual(res.state.jsonBody["@odata.count"], 4);
|
||||
});
|
||||
|
||||
const run = async () => {
|
||||
let passed = 0;
|
||||
for (const currentTest of tests) {
|
||||
|
||||
Reference in New Issue
Block a user