TASK22211: normalize case update and crm task endpoint contracts
This commit is contained in:
@@ -3320,6 +3320,143 @@ test("createcase catch path returns CASE_CREATE_FAILED", async () => {
|
||||
assert.strictEqual(res.state.jsonBody.error.code, "CASE_CREATE_FAILED");
|
||||
});
|
||||
|
||||
test("updatecase returns CASE_UPDATE_PAYLOAD_REQUIRED when body missing", async () => {
|
||||
const mod = loadModule("pages/api/endpoint/updatecase_api.js", {
|
||||
respondError: respondErrorMock,
|
||||
respondSuccess: respondSuccessMock,
|
||||
getToken: async () => ({ access_token: "token" }),
|
||||
hashAPIPath: () => "&hash=expected",
|
||||
axios: async () => ({ data: {} }),
|
||||
consoleLogger: () => {}
|
||||
});
|
||||
|
||||
const req = {
|
||||
query: { appealObj: "a1", updateFormCollection: "pinswg_x" },
|
||||
body: undefined
|
||||
};
|
||||
const res = createRes();
|
||||
await mod.default(req, res);
|
||||
|
||||
assert.strictEqual(res.state.statusCode, 400);
|
||||
assert.strictEqual(
|
||||
res.state.jsonBody.error.code,
|
||||
"CASE_UPDATE_PAYLOAD_REQUIRED"
|
||||
);
|
||||
});
|
||||
|
||||
test("updatecase catch path returns CASE_UPDATE_FAILED", async () => {
|
||||
const mod = loadModule("pages/api/endpoint/updatecase_api.js", {
|
||||
respondError: respondErrorMock,
|
||||
respondSuccess: respondSuccessMock,
|
||||
getToken: async () => ({ access_token: "token" }),
|
||||
hashAPIPath: () => "&hash=expected",
|
||||
axios: async () => {
|
||||
throw new Error("update failed");
|
||||
},
|
||||
consoleLogger: () => {}
|
||||
});
|
||||
|
||||
const req = {
|
||||
query: { appealObj: "a1", updateFormCollection: "pinswg_x" },
|
||||
body: { title: "updated" }
|
||||
};
|
||||
const res = createRes();
|
||||
await mod.default(req, res);
|
||||
|
||||
assert.strictEqual(res.state.statusCode, 400);
|
||||
assert.strictEqual(res.state.jsonBody.error.code, "CASE_UPDATE_FAILED");
|
||||
});
|
||||
|
||||
test("patchcase returns INCIDENT_ID_REQUIRED when incidentid missing", async () => {
|
||||
const mod = loadModule("pages/api/endpoint/patchcase_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("patchcase catch path returns CASE_PATCH_FAILED", async () => {
|
||||
const mod = loadModule("pages/api/endpoint/patchcase_api.js", {
|
||||
respondError: respondErrorMock,
|
||||
respondSuccess: respondSuccessMock,
|
||||
getToken: async () => ({ access_token: "token" }),
|
||||
hashAPIPath: () => "&hash=expected",
|
||||
axios: async () => {
|
||||
throw new Error("patch 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, "CASE_PATCH_FAILED");
|
||||
});
|
||||
|
||||
test("createcrmtask returns CONTACT_EMAIL_AND_SUBJECT_REQUIRED when required fields missing", async () => {
|
||||
const mod = loadModule("pages/api/endpoint/createcrmtask_api.js", {
|
||||
respondError: respondErrorMock,
|
||||
respondSuccess: respondSuccessMock,
|
||||
isNonEmptyString: () => false,
|
||||
sanitizeString: (v) => v,
|
||||
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,
|
||||
"CONTACT_EMAIL_AND_SUBJECT_REQUIRED"
|
||||
);
|
||||
});
|
||||
|
||||
test("createcrmtask catch path returns CRM_TASK_CREATE_FAILED", async () => {
|
||||
const mod = loadModule("pages/api/endpoint/createcrmtask_api.js", {
|
||||
respondError: respondErrorMock,
|
||||
respondSuccess: respondSuccessMock,
|
||||
isNonEmptyString: () => true,
|
||||
sanitizeString: (v) => v,
|
||||
getToken: async () => ({ access_token: "token" }),
|
||||
hashAPIPath: () => "&hash=expected",
|
||||
axios: async () => {
|
||||
throw new Error("create failed");
|
||||
},
|
||||
consoleLogger: () => {}
|
||||
});
|
||||
|
||||
const req = {
|
||||
body: {
|
||||
contactEmail: "user@test.local",
|
||||
contactSubject: "Need help",
|
||||
contactbody: "Details",
|
||||
typeOfContact: "plq"
|
||||
}
|
||||
};
|
||||
const res = createRes();
|
||||
await mod.default(req, res);
|
||||
|
||||
assert.strictEqual(res.state.statusCode, 400);
|
||||
assert.strictEqual(res.state.jsonBody.error.code, "CRM_TASK_CREATE_FAILED");
|
||||
});
|
||||
|
||||
test("getsipsmedia returns success contract", async () => {
|
||||
const mod = loadModule("pages/api/endpoint/getsipsmedia_api.js", {
|
||||
respondSuccess: respondSuccessMock
|
||||
|
||||
Reference in New Issue
Block a user