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-10-08 05:46:57 +07:00
|
|
|
import { MailSenderStub } from "../mocks/notifiers/MailSenderStub";
|
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 () {
|
2017-10-08 05:46:57 +07:00
|
|
|
it("should send an email to given user", function () {
|
|
|
|
const mailSender = new MailSenderStub();
|
|
|
|
const options = {
|
|
|
|
username: "user_gmail",
|
|
|
|
password: "pass_gmail"
|
|
|
|
};
|
|
|
|
|
|
|
|
mailSender.sendStub.returns(BluebirdPromise.resolve());
|
|
|
|
const sender = new GMailNotifier.GMailNotifier(options, mailSender);
|
|
|
|
const subject = "subject";
|
|
|
|
|
|
|
|
const identity = {
|
|
|
|
userid: "user",
|
|
|
|
email: "user@example.com"
|
2017-05-20 14:49:05 +07:00
|
|
|
};
|
|
|
|
|
2017-10-08 05:46:57 +07:00
|
|
|
const url = "http://test.com";
|
|
|
|
|
|
|
|
return sender.notify(identity, subject, url)
|
|
|
|
.then(function () {
|
|
|
|
assert.equal(mailSender.sendStub.getCall(0).args[0].to, "user@example.com");
|
|
|
|
assert.equal(mailSender.sendStub.getCall(0).args[0].subject, "subject");
|
|
|
|
return BluebirdPromise.resolve();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it("should fail while sending an email", function () {
|
|
|
|
const mailSender = new MailSenderStub();
|
2017-05-20 14:49:05 +07:00
|
|
|
const options = {
|
|
|
|
username: "user_gmail",
|
|
|
|
password: "pass_gmail"
|
|
|
|
};
|
|
|
|
|
2017-10-08 05:46:57 +07:00
|
|
|
mailSender.sendStub.returns(BluebirdPromise.reject(new Error("Failed to send mail")));
|
|
|
|
const sender = new GMailNotifier.GMailNotifier(options, mailSender);
|
2017-05-20 14:49:05 +07:00
|
|
|
const subject = "subject";
|
|
|
|
|
|
|
|
const identity = {
|
|
|
|
userid: "user",
|
|
|
|
email: "user@example.com"
|
|
|
|
};
|
|
|
|
|
|
|
|
const url = "http://test.com";
|
|
|
|
|
|
|
|
return sender.notify(identity, subject, url)
|
|
|
|
.then(function () {
|
2017-10-08 05:46:57 +07:00
|
|
|
return BluebirdPromise.reject(new Error());
|
|
|
|
}, function() {
|
2017-05-25 20:09:29 +07:00
|
|
|
return BluebirdPromise.resolve();
|
2017-05-20 14:49:05 +07:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|