2017-10-07 22:46:57 +00:00
|
|
|
|
|
|
|
import { MailSenderBuilder } from "../../src/lib/notifiers/MailSenderBuilder";
|
|
|
|
import Nodemailer = require("nodemailer");
|
|
|
|
import Sinon = require("sinon");
|
|
|
|
import Assert = require("assert");
|
|
|
|
|
|
|
|
describe("test MailSenderBuilder", function() {
|
|
|
|
let createTransportStub: Sinon.SinonStub;
|
|
|
|
beforeEach(function() {
|
|
|
|
createTransportStub = Sinon.stub(Nodemailer, "createTransport");
|
|
|
|
});
|
|
|
|
|
|
|
|
afterEach(function() {
|
|
|
|
createTransportStub.restore();
|
|
|
|
});
|
|
|
|
|
2017-10-25 08:28:56 +00:00
|
|
|
it("should create a email mail sender", function() {
|
2017-10-07 22:46:57 +00:00
|
|
|
const mailSenderBuilder = new MailSenderBuilder(Nodemailer);
|
2017-10-25 08:28:56 +00:00
|
|
|
mailSenderBuilder.buildEmail({
|
2017-10-07 22:46:57 +00:00
|
|
|
username: "user_gmail",
|
2017-10-09 22:07:12 +00:00
|
|
|
password: "pass_gmail",
|
2017-10-25 08:28:56 +00:00
|
|
|
sender: "admin@example.com",
|
|
|
|
service: "gmail"
|
2017-10-07 22:46:57 +00:00
|
|
|
});
|
|
|
|
Assert.equal(createTransportStub.getCall(0).args[0].auth.user, "user_gmail");
|
|
|
|
Assert.equal(createTransportStub.getCall(0).args[0].auth.pass, "pass_gmail");
|
2017-10-25 08:28:56 +00:00
|
|
|
Assert.equal(createTransportStub.getCall(0).args[0].service, "gmail");
|
2017-10-07 22:46:57 +00:00
|
|
|
});
|
|
|
|
|
2017-10-15 20:41:18 +00:00
|
|
|
describe("build smtp mail sender", function() {
|
|
|
|
it("should create a smtp mail sender with authenticated user", function() {
|
|
|
|
const mailSenderBuilder = new MailSenderBuilder(Nodemailer);
|
|
|
|
mailSenderBuilder.buildSmtp({
|
|
|
|
host: "mail.example.com",
|
|
|
|
password: "password",
|
|
|
|
port: 25,
|
|
|
|
secure: true,
|
|
|
|
username: "user",
|
|
|
|
sender: "admin@example.com"
|
|
|
|
});
|
|
|
|
Assert.deepStrictEqual(createTransportStub.getCall(0).args[0], {
|
|
|
|
host: "mail.example.com",
|
|
|
|
auth: {
|
|
|
|
pass: "password",
|
|
|
|
user: "user"
|
|
|
|
},
|
|
|
|
port: 25,
|
|
|
|
secure: true,
|
|
|
|
});
|
2017-10-07 22:46:57 +00:00
|
|
|
});
|
2017-10-15 20:41:18 +00:00
|
|
|
|
|
|
|
it("should create a smtp mail sender with anonymous user", function() {
|
|
|
|
const mailSenderBuilder = new MailSenderBuilder(Nodemailer);
|
|
|
|
mailSenderBuilder.buildSmtp({
|
|
|
|
host: "mail.example.com",
|
|
|
|
port: 25,
|
|
|
|
secure: true,
|
|
|
|
sender: "admin@example.com"
|
|
|
|
});
|
|
|
|
Assert.deepStrictEqual(createTransportStub.getCall(0).args[0], {
|
|
|
|
host: "mail.example.com",
|
|
|
|
port: 25,
|
|
|
|
secure: true,
|
|
|
|
});
|
2017-10-07 22:46:57 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|