TASK22109: expand email contract coverage and logging hygiene
This commit is contained in:
@@ -150,6 +150,133 @@ test("getall top-level failure returns EMAIL_COMBINED_FETCH_FAILED", async () =>
|
||||
);
|
||||
});
|
||||
|
||||
test("getmailinglist success returns flattened mailing list results", async () => {
|
||||
const mod = loadModule("pages/api/email/getmailinglist.js", {
|
||||
respondError: respondErrorMock,
|
||||
respondSuccess: respondSuccessMock,
|
||||
getToken: async () => ({ access_token: "token" }),
|
||||
hashAPIPath: () => "&hash=expected",
|
||||
azureHeaders: () => ({}),
|
||||
axios: {
|
||||
get: async () => ({
|
||||
data: {
|
||||
value: [
|
||||
{
|
||||
pinswg_emailnotifications: true,
|
||||
pinswg_Contact: {
|
||||
contactid: "c1",
|
||||
emailaddress1: "a@test.local"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
})
|
||||
},
|
||||
consoleLogger: () => {}
|
||||
});
|
||||
|
||||
const req = { query: {} };
|
||||
const res = createRes();
|
||||
await mod.default(req, res);
|
||||
|
||||
assert.strictEqual(res.state.statusCode, 200);
|
||||
assert.deepStrictEqual(JSON.parse(JSON.stringify(res.state.jsonBody)), [
|
||||
{
|
||||
pinswg_emailnotifications: true,
|
||||
contactid: "c1",
|
||||
contact_email: "a@test.local"
|
||||
}
|
||||
]);
|
||||
});
|
||||
|
||||
test("getmailinglist failure returns MAILING_LIST_FETCH_FAILED", async () => {
|
||||
const mod = loadModule("pages/api/email/getmailinglist.js", {
|
||||
respondError: respondErrorMock,
|
||||
respondSuccess: respondSuccessMock,
|
||||
getToken: async () => ({ access_token: "token" }),
|
||||
hashAPIPath: () => "&hash=expected",
|
||||
azureHeaders: () => ({}),
|
||||
axios: {
|
||||
get: async () => {
|
||||
throw new Error("mailing list 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,
|
||||
"MAILING_LIST_FETCH_FAILED"
|
||||
);
|
||||
});
|
||||
|
||||
test("getcaseref success returns flattened case ref results", async () => {
|
||||
const mod = loadModule("pages/api/email/getcaseref.js", {
|
||||
respondError: respondErrorMock,
|
||||
respondSuccess: respondSuccessMock,
|
||||
getToken: async () => ({ access_token: "token" }),
|
||||
hashAPIPath: () => "&hash=expected",
|
||||
azureHeaders: () => ({}),
|
||||
axios: {
|
||||
get: async () => ({
|
||||
data: {
|
||||
value: [
|
||||
{
|
||||
pinswg_emailnotifications: true,
|
||||
pinswg_Contact: {
|
||||
contactid: "c2",
|
||||
emailaddress1: "b@test.local"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
})
|
||||
},
|
||||
consoleLogger: () => {}
|
||||
});
|
||||
|
||||
const req = { query: {} };
|
||||
const res = createRes();
|
||||
await mod.default(req, res);
|
||||
|
||||
assert.strictEqual(res.state.statusCode, 200);
|
||||
assert.deepStrictEqual(JSON.parse(JSON.stringify(res.state.jsonBody)), [
|
||||
{
|
||||
pinswg_emailnotifications: true,
|
||||
contactid: "c2",
|
||||
contact_email: "b@test.local"
|
||||
}
|
||||
]);
|
||||
});
|
||||
|
||||
test("getcaseref failure returns CASE_REF_FETCH_FAILED", async () => {
|
||||
const mod = loadModule("pages/api/email/getcaseref.js", {
|
||||
respondError: respondErrorMock,
|
||||
respondSuccess: respondSuccessMock,
|
||||
getToken: async () => ({ access_token: "token" }),
|
||||
hashAPIPath: () => "&hash=expected",
|
||||
azureHeaders: () => ({}),
|
||||
axios: {
|
||||
get: async () => {
|
||||
throw new Error("case ref 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, "CASE_REF_FETCH_FAILED");
|
||||
});
|
||||
|
||||
const run = async () => {
|
||||
let passed = 0;
|
||||
for (const currentTest of tests) {
|
||||
|
||||
Reference in New Issue
Block a user