From bfff6d0207ef14134deeaf7fe6625110e4459c93 Mon Sep 17 00:00:00 2001 From: Jeffrey Koehler Date: Wed, 20 Oct 2021 23:26:33 -0500 Subject: [PATCH] SMTP notification tests --- config/jest-backend.config.js | 2 +- server/notification-providers/smtp.spec.js | 50 ++++++++++++++++++++++ 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 server/notification-providers/smtp.spec.js diff --git a/config/jest-backend.config.js b/config/jest-backend.config.js index 1a88d9a6b..db3951291 100644 --- a/config/jest-backend.config.js +++ b/config/jest-backend.config.js @@ -1,5 +1,5 @@ module.exports = { "rootDir": "..", - "testRegex": "./test/backend.spec.js", + "testRegex": ["./test/backend.spec.js", "./server/.*.spec.js"], }; diff --git a/server/notification-providers/smtp.spec.js b/server/notification-providers/smtp.spec.js new file mode 100644 index 000000000..2cf0876fc --- /dev/null +++ b/server/notification-providers/smtp.spec.js @@ -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."); + }); +});