mirror of
https://github.com/louislam/uptime-kuma.git
synced 2025-06-15 08:56:47 +02:00
Test for calling notification from Notification.send
This commit is contained in:
parent
6be97fbb4d
commit
bc4f0f94fa
1 changed files with 64 additions and 0 deletions
|
@ -3,6 +3,7 @@ jest.mock("nodemailer", () => ({
|
||||||
}));
|
}));
|
||||||
const mockNodeMailer = require("nodemailer");
|
const mockNodeMailer = require("nodemailer");
|
||||||
const { UP } = require("../../src/util");
|
const { UP } = require("../../src/util");
|
||||||
|
const NotificationSend = require("../notification");
|
||||||
|
|
||||||
const SMTP = require("./smtp");
|
const SMTP = require("./smtp");
|
||||||
|
|
||||||
|
@ -181,3 +182,66 @@ describe("notification to act properly on error from transport", () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("notification to get proper data from Notification.send", () => {
|
||||||
|
it("should call sendMail with proper data", async () => {
|
||||||
|
let sender = jest.fn()
|
||||||
|
.mockResolvedValue(() => {
|
||||||
|
return;
|
||||||
|
});
|
||||||
|
mockNodeMailer.createTransport.mockImplementationOnce(() => {
|
||||||
|
return { sendMail: sender };
|
||||||
|
});
|
||||||
|
|
||||||
|
let notificationConf = {
|
||||||
|
type: "smtp",
|
||||||
|
smtpHost: "host",
|
||||||
|
smtpPort: "port",
|
||||||
|
smtpSecure: "secure",
|
||||||
|
smtpUsername: "username",
|
||||||
|
smtpPassword: "password",
|
||||||
|
customSubject: "",
|
||||||
|
smtpFrom: "From",
|
||||||
|
smtpCC: "CC",
|
||||||
|
smtpBCC: "BCC",
|
||||||
|
smtpTo: "To",
|
||||||
|
};
|
||||||
|
let monitorConf = {
|
||||||
|
type: "http",
|
||||||
|
url: "https://www.google.com",
|
||||||
|
name: "testing",
|
||||||
|
};
|
||||||
|
let heartbeatConf = {
|
||||||
|
status: UP,
|
||||||
|
};
|
||||||
|
|
||||||
|
NotificationSend.Notification.init();
|
||||||
|
let res = await NotificationSend.Notification.send(notificationConf, "simple message", monitorConf, heartbeatConf);
|
||||||
|
|
||||||
|
expect(res).toBe("Sent Successfully.");
|
||||||
|
|
||||||
|
expect(mockNodeMailer.createTransport).toHaveBeenCalledTimes(1);
|
||||||
|
expect(mockNodeMailer.createTransport).toHaveBeenCalledWith({
|
||||||
|
auth: {
|
||||||
|
pass: "password",
|
||||||
|
user: "username",
|
||||||
|
},
|
||||||
|
host: "host",
|
||||||
|
port: "port",
|
||||||
|
secure: "secure",
|
||||||
|
});
|
||||||
|
expect(sender).toHaveBeenCalledTimes(1);
|
||||||
|
expect(sender).toHaveBeenCalledWith({
|
||||||
|
bcc: "BCC",
|
||||||
|
cc: "CC",
|
||||||
|
from: "From",
|
||||||
|
subject: "simple message",
|
||||||
|
text: "simple message\nTime (UTC): undefined",
|
||||||
|
tls: {
|
||||||
|
rejectUnauthorized: false,
|
||||||
|
},
|
||||||
|
to: "To",
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue