TASK22109: email mini-slice tidy and notify negative-path tests
This commit is contained in:
@@ -277,6 +277,66 @@ test("getcaseref failure returns CASE_REF_FETCH_FAILED", async () => {
|
||||
assert.strictEqual(res.state.jsonBody.error.code, "CASE_REF_FETCH_FAILED");
|
||||
});
|
||||
|
||||
test("notify returns EMAIL_ADDRESS_REQUIRED when emailAddress is missing", async () => {
|
||||
const mod = loadModule("pages/api/email/notify.js", {
|
||||
respondError: respondErrorMock,
|
||||
respondSuccess: respondSuccessMock,
|
||||
consoleLogger: () => {},
|
||||
redactSensitive: (value) => value,
|
||||
sanitizeString: () => "",
|
||||
isNonEmptyString: () => false,
|
||||
getPreferredLanguage: async () => ({ value: [] })
|
||||
});
|
||||
|
||||
const req = { body: { templateId: "t1", reference: "OTHER" } };
|
||||
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("notify send failure returns EMAIL_NOTIFY_FAILED", async () => {
|
||||
const mod = loadModule("pages/api/email/notify.js", {
|
||||
respondError: respondErrorMock,
|
||||
respondSuccess: respondSuccessMock,
|
||||
consoleLogger: () => {},
|
||||
redactSensitive: (value) => value,
|
||||
sanitizeString: (value) => value,
|
||||
isNonEmptyString: () => true,
|
||||
getPreferredLanguage: async () => ({ value: [] }),
|
||||
require: (name) => {
|
||||
if (name === "notifications-node-client") {
|
||||
return {
|
||||
NotifyClient: function NotifyClient() {
|
||||
return {
|
||||
sendEmail: async () => {
|
||||
throw new Error("notify failed");
|
||||
}
|
||||
};
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return require(name);
|
||||
}
|
||||
});
|
||||
|
||||
const req = {
|
||||
body: {
|
||||
templateId: "t1",
|
||||
emailAddress: "user@test.local",
|
||||
personalisation: {},
|
||||
reference: "OTHER"
|
||||
}
|
||||
};
|
||||
const res = createRes();
|
||||
await mod.default(req, res);
|
||||
|
||||
assert.strictEqual(res.state.statusCode, 400);
|
||||
assert.strictEqual(res.state.jsonBody.error.code, "EMAIL_NOTIFY_FAILED");
|
||||
});
|
||||
|
||||
const run = async () => {
|
||||
let passed = 0;
|
||||
for (const currentTest of tests) {
|
||||
|
||||
Reference in New Issue
Block a user