2017-05-20 14:49:05 +07:00
|
|
|
import * as sinon from "sinon";
|
|
|
|
import * as assert from "assert";
|
2017-05-25 20:09:29 +07:00
|
|
|
import BluebirdPromise = require("bluebird");
|
2017-05-20 14:49:05 +07:00
|
|
|
|
2017-05-22 03:45:54 +07:00
|
|
|
import NodemailerMock = require("../mocks/nodemailer");
|
2017-10-07 05:09:42 +07:00
|
|
|
import GMailNotifier = require("../../src/lib/notifiers/GMailNotifier");
|
2017-05-20 14:49:05 +07:00
|
|
|
|
|
|
|
|
|
|
|
describe("test gmail notifier", function () {
|
|
|
|
it("should send an email", function () {
|
|
|
|
const transporter = {
|
|
|
|
sendMail: sinon.stub().yields()
|
|
|
|
};
|
2017-05-22 03:45:54 +07:00
|
|
|
const nodemailerMock = NodemailerMock.NodemailerMock();
|
2017-05-20 14:49:05 +07:00
|
|
|
nodemailerMock.createTransport.returns(transporter);
|
|
|
|
|
|
|
|
const options = {
|
|
|
|
username: "user_gmail",
|
|
|
|
password: "pass_gmail"
|
|
|
|
};
|
|
|
|
|
|
|
|
const sender = new GMailNotifier.GMailNotifier(options, nodemailerMock);
|
|
|
|
const subject = "subject";
|
|
|
|
|
|
|
|
const identity = {
|
|
|
|
userid: "user",
|
|
|
|
email: "user@example.com"
|
|
|
|
};
|
|
|
|
|
|
|
|
const url = "http://test.com";
|
|
|
|
|
|
|
|
return sender.notify(identity, subject, url)
|
|
|
|
.then(function () {
|
|
|
|
assert.equal(nodemailerMock.createTransport.getCall(0).args[0].auth.user, "user_gmail");
|
|
|
|
assert.equal(nodemailerMock.createTransport.getCall(0).args[0].auth.pass, "pass_gmail");
|
|
|
|
assert.equal(transporter.sendMail.getCall(0).args[0].to, "user@example.com");
|
|
|
|
assert.equal(transporter.sendMail.getCall(0).args[0].subject, "subject");
|
2017-05-25 20:09:29 +07:00
|
|
|
return BluebirdPromise.resolve();
|
2017-05-20 14:49:05 +07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|