2017-05-20 14:49:05 +07:00
|
|
|
|
|
|
|
import * as sinon from "sinon";
|
|
|
|
import * as BluebirdPromise from "bluebird";
|
|
|
|
import * as assert from "assert";
|
|
|
|
|
2017-10-07 05:09:42 +07:00
|
|
|
import { NotifierFactory } from "../../src/lib/notifiers/NotifierFactory";
|
|
|
|
import { GMailNotifier } from "../../src/lib/notifiers/GMailNotifier";
|
|
|
|
import { SmtpNotifier } from "../../src/lib/notifiers/SmtpNotifier";
|
2017-05-20 14:49:05 +07:00
|
|
|
|
2017-05-22 03:45:54 +07:00
|
|
|
import NodemailerMock = require("../mocks/nodemailer");
|
2017-05-20 14:49:05 +07:00
|
|
|
|
|
|
|
|
2017-05-21 03:55:37 +07:00
|
|
|
describe("test notifier factory", function() {
|
2017-05-22 03:45:54 +07:00
|
|
|
let nodemailerMock: NodemailerMock.NodemailerMock;
|
2017-05-20 14:49:05 +07:00
|
|
|
it("should build a Gmail Notifier", function() {
|
|
|
|
const options = {
|
|
|
|
gmail: {
|
|
|
|
username: "abc",
|
|
|
|
password: "password"
|
|
|
|
}
|
|
|
|
};
|
2017-05-22 03:45:54 +07:00
|
|
|
nodemailerMock = NodemailerMock.NodemailerMock();
|
2017-09-25 01:55:11 +07:00
|
|
|
const transporterMock = NodemailerMock.NodemailerTransporterMock();
|
|
|
|
nodemailerMock.createTransport.returns(transporterMock);
|
2017-05-21 03:55:37 +07:00
|
|
|
assert(NotifierFactory.build(options, nodemailerMock) instanceof GMailNotifier);
|
2017-05-20 14:49:05 +07:00
|
|
|
});
|
|
|
|
|
2017-09-25 01:55:11 +07:00
|
|
|
it("should build a SMTP Notifier", function() {
|
2017-05-20 14:49:05 +07:00
|
|
|
const options = {
|
2017-09-25 01:55:11 +07:00
|
|
|
smtp: {
|
|
|
|
username: "user",
|
|
|
|
password: "pass",
|
|
|
|
secure: true,
|
|
|
|
host: "localhost",
|
|
|
|
port: 25
|
2017-05-20 14:49:05 +07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-09-25 01:55:11 +07:00
|
|
|
nodemailerMock = NodemailerMock.NodemailerMock();
|
|
|
|
const transporterMock = NodemailerMock.NodemailerTransporterMock();
|
|
|
|
nodemailerMock.createTransport.returns(transporterMock);
|
|
|
|
assert(NotifierFactory.build(options, nodemailerMock) instanceof SmtpNotifier);
|
2017-05-20 14:49:05 +07:00
|
|
|
});
|
|
|
|
});
|