mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-06-14 16:42:35 +02:00
SMTP notification tests
This commit is contained in:
parent
c31efc0ef4
commit
bfff6d0207
2 changed files with 51 additions and 1 deletions
|
@ -1,5 +1,5 @@
|
||||||
module.exports = {
|
module.exports = {
|
||||||
"rootDir": "..",
|
"rootDir": "..",
|
||||||
"testRegex": "./test/backend.spec.js",
|
"testRegex": ["./test/backend.spec.js", "./server/.*.spec.js"],
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
50
server/notification-providers/smtp.spec.js
Normal file
50
server/notification-providers/smtp.spec.js
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
jest.mock("nodemailer", () => ({
|
||||||
|
createTransport: jest.fn(),
|
||||||
|
}));
|
||||||
|
const mockNodEmailer = require("nodemailer");
|
||||||
|
|
||||||
|
const SMTP = require("./smtp");
|
||||||
|
|
||||||
|
describe("notification default information", () => {
|
||||||
|
it("should have the correct name", () => {
|
||||||
|
let notification = new SMTP();
|
||||||
|
expect(notification.name).toBe("smtp");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("notification to act properly on send", () => {
|
||||||
|
it("should call transport with the proper default data", async () => {
|
||||||
|
let sender = jest.fn()
|
||||||
|
.mockResolvedValue(() => {
|
||||||
|
return;
|
||||||
|
});
|
||||||
|
mockNodEmailer.createTransport.mockImplementationOnce(() => {
|
||||||
|
return { sendMail: sender };
|
||||||
|
});
|
||||||
|
|
||||||
|
let notif = new SMTP();
|
||||||
|
let notificationConf = {
|
||||||
|
smtpHost: "host",
|
||||||
|
smtpPort: "port",
|
||||||
|
smtpSecure: "secure",
|
||||||
|
smtpUsername: "username",
|
||||||
|
smtpPassword: "password",
|
||||||
|
customSubject: "custom subject",
|
||||||
|
};
|
||||||
|
let msg = "Message";
|
||||||
|
let monitorConf = { };
|
||||||
|
let heartbeatConf = { };
|
||||||
|
let res = await notif.send(notificationConf, msg, monitorConf, heartbeatConf);
|
||||||
|
|
||||||
|
expect(mockNodEmailer.createTransport).toHaveBeenCalledWith({
|
||||||
|
auth: {
|
||||||
|
pass: "password",
|
||||||
|
user: "username",
|
||||||
|
},
|
||||||
|
host: "host",
|
||||||
|
port: "port",
|
||||||
|
secure: "secure",
|
||||||
|
});
|
||||||
|
expect(res).toBe("Sent Successfully.");
|
||||||
|
});
|
||||||
|
});
|
Loading…
Add table
Reference in a new issue