authelia/server/test/notifiers/GMailNotifier.test.ts

42 lines
1.3 KiB
TypeScript
Raw Normal View History

2017-05-20 14:49:05 +07:00
import * as sinon from "sinon";
import * as assert from "assert";
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");
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");
return BluebirdPromise.resolve();
2017-05-20 14:49:05 +07:00
});
});
});