2015-06-13 19:48:17 +02:00
|
|
|
var should = require("should");
|
|
|
|
var sinon = require("sinon");
|
2018-05-01 18:33:05 +02:00
|
|
|
var helper = require("node-red-node-test-helper");
|
2015-06-13 19:48:17 +02:00
|
|
|
var emailNode = require('../../../social/email/61-email.js');
|
|
|
|
|
2017-02-15 19:33:05 +01:00
|
|
|
describe('email Node', function () {
|
2015-06-13 19:48:17 +02:00
|
|
|
|
2017-02-15 19:33:05 +01:00
|
|
|
beforeEach(function (done) {
|
2015-06-13 19:48:17 +02:00
|
|
|
helper.startServer(done);
|
|
|
|
});
|
|
|
|
|
2017-02-15 19:33:05 +01:00
|
|
|
afterEach(function (done) {
|
2015-06-13 19:48:17 +02:00
|
|
|
helper.unload();
|
|
|
|
helper.stopServer(done);
|
|
|
|
});
|
|
|
|
|
2017-02-15 19:33:05 +01:00
|
|
|
describe('email in', function () {
|
2015-06-19 17:54:07 +02:00
|
|
|
|
2017-02-15 19:33:05 +01:00
|
|
|
it('should load with defaults', function (done) {
|
|
|
|
var flow = [{
|
|
|
|
id: "n1",
|
|
|
|
type: "e-mail in",
|
|
|
|
name: "emailin",
|
|
|
|
wires: [
|
|
|
|
[]
|
|
|
|
]
|
|
|
|
}];
|
|
|
|
helper.load(emailNode, flow, function () {
|
2015-06-19 17:54:07 +02:00
|
|
|
var n1 = helper.getNode("n1");
|
2017-02-15 19:33:05 +01:00
|
|
|
n1.should.have.property('name', "emailin");
|
2015-06-19 17:54:07 +02:00
|
|
|
n1.should.have.property("repeat", 300000);
|
|
|
|
n1.should.have.property("inserver", "imap.gmail.com");
|
|
|
|
n1.should.have.property("inport", "993");
|
2023-03-27 21:27:47 +02:00
|
|
|
n1.should.have.property("authtype", "BASIC");
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should force input on XOAuth2', function (done) {
|
|
|
|
var flow = [{
|
|
|
|
id: "n1",
|
|
|
|
type: "e-mail in",
|
|
|
|
name: "emailin",
|
|
|
|
authtype: "XOAUTH2",
|
|
|
|
wires: [
|
|
|
|
[]
|
|
|
|
]
|
|
|
|
}];
|
|
|
|
helper.load(emailNode, flow, function () {
|
|
|
|
var n1 = helper.getNode("n1");
|
|
|
|
n1.should.have.property("repeat", 0);
|
|
|
|
n1.should.have.property("inputs", 1);
|
2015-06-19 17:54:07 +02:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-02-15 19:33:05 +01:00
|
|
|
describe('email out', function () {
|
2015-06-13 19:48:17 +02:00
|
|
|
|
2017-02-15 19:33:05 +01:00
|
|
|
it('should load with defaults', function (done) {
|
|
|
|
var flow = [{
|
|
|
|
id: "n1",
|
|
|
|
type: "e-mail",
|
|
|
|
name: "emailout",
|
2020-10-19 15:32:09 +02:00
|
|
|
port: 1025,
|
2017-02-15 19:33:05 +01:00
|
|
|
wires: [
|
|
|
|
[]
|
|
|
|
]
|
|
|
|
}];
|
|
|
|
helper.load(emailNode, flow, function () {
|
2015-06-13 19:48:17 +02:00
|
|
|
var n1 = helper.getNode("n1");
|
2017-02-15 19:33:05 +01:00
|
|
|
n1.should.have.property('name', "emailout");
|
2023-03-27 21:27:47 +02:00
|
|
|
n1.should.have.property("authtype", "BASIC");
|
2015-06-13 19:48:17 +02:00
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-02-15 19:33:05 +01:00
|
|
|
it('should fail with no payload', function (done) {
|
|
|
|
var flow = [{
|
|
|
|
id: "n1",
|
|
|
|
type: "e-mail",
|
|
|
|
name: "emailout",
|
|
|
|
wires: [
|
|
|
|
[]
|
|
|
|
]
|
|
|
|
}];
|
|
|
|
helper.load(emailNode, flow, function () {
|
|
|
|
var n1 = helper.getNode("n1");
|
|
|
|
n1.credentials = {
|
|
|
|
userid: "test",
|
|
|
|
password: "test",
|
|
|
|
};
|
|
|
|
n1.emit("input", {});
|
|
|
|
//done();
|
|
|
|
});
|
|
|
|
setTimeout(function () {
|
|
|
|
try {
|
|
|
|
var logEvents = helper.log().args.filter(function (evt) {
|
|
|
|
//console.log(evt[0].msg);
|
|
|
|
return evt[0].type == "e-mail";
|
|
|
|
});
|
|
|
|
//console.log(helper.log().args);
|
|
|
|
//console.log(helper.log());
|
|
|
|
//logEvents.should.have.length(3);
|
|
|
|
logEvents[0][0].should.have.a.property('msg');
|
2023-03-27 21:27:47 +02:00
|
|
|
logEvents[2][0].msg.toString().should.startWith("email.errors.nopayload");
|
2017-02-15 19:33:05 +01:00
|
|
|
done();
|
|
|
|
} catch (e) {
|
|
|
|
done(e);
|
|
|
|
}
|
|
|
|
//finally { smtpTransport.sendMail.restore(); }
|
2018-01-21 17:24:41 +01:00
|
|
|
}, 1500);
|
2017-02-15 19:33:05 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should fail to send an email (invalid creds)', function (done) {
|
|
|
|
//var smtpTransport = require("nodemailer").createTransport();
|
2015-06-16 10:17:06 +02:00
|
|
|
//var spy = sinon.stub(smtpTransport, 'sendMail', function(arg1,arg2,arg3,arg4) {
|
2017-02-15 19:33:05 +01:00
|
|
|
//console.log("HELLO");
|
|
|
|
//console.log(arg1,arg2,arg3,arg4);
|
|
|
|
//done();
|
|
|
|
//});
|
|
|
|
var flow = [{
|
|
|
|
id: "n1",
|
|
|
|
type: "e-mail",
|
|
|
|
name: "test@gmail.com",
|
|
|
|
server: "smtp.gmail.com",
|
|
|
|
secure: true,
|
|
|
|
port: "465",
|
|
|
|
wires: [
|
|
|
|
[]
|
|
|
|
]
|
|
|
|
}];
|
|
|
|
helper.load(emailNode, flow, function () {
|
|
|
|
var n1 = helper.getNode("n1");
|
|
|
|
n1.credentials = {
|
|
|
|
userid: "test",
|
|
|
|
password: "test",
|
|
|
|
};
|
|
|
|
n1.should.have.property('name', "test@gmail.com");
|
|
|
|
n1.emit("input", {
|
|
|
|
payload: "Hello World",
|
|
|
|
to: "test@gmail.com"
|
|
|
|
});
|
2015-06-16 10:17:06 +02:00
|
|
|
//done();
|
2017-02-15 19:33:05 +01:00
|
|
|
});
|
|
|
|
setTimeout(function () {
|
|
|
|
try {
|
|
|
|
var logEvents = helper.log().args.filter(function (evt) {
|
|
|
|
//console.log(evt[0].msg);
|
|
|
|
return evt[0].type == "e-mail";
|
|
|
|
});
|
2018-01-21 17:24:41 +01:00
|
|
|
// console.log(helper.log().args);
|
|
|
|
// console.log(helper.log());
|
|
|
|
// console.log(logEvents[0][0].msg.toString());
|
2017-02-15 19:33:05 +01:00
|
|
|
//logEvents.should.have.length(3);
|
|
|
|
logEvents[0][0].should.have.a.property('msg');
|
2023-03-27 21:27:47 +02:00
|
|
|
logEvents[2][0].msg.toString().should.startWith("Error:");
|
2017-02-15 19:33:05 +01:00
|
|
|
done();
|
|
|
|
} catch (e) {
|
|
|
|
done(e);
|
|
|
|
}
|
|
|
|
//finally { smtpTransport.sendMail.restore(); }
|
2018-01-21 17:24:41 +01:00
|
|
|
}, 1900);
|
2017-02-15 19:33:05 +01:00
|
|
|
})
|
|
|
|
|
|
|
|
it('should fail to send an email (no creds provided)', function (done) {
|
|
|
|
//var smtpTransport = require("nodemailer").createTransport();
|
|
|
|
//var spy = sinon.stub(smtpTransport, 'sendMail', function(arg1,arg2,arg3,arg4) {
|
|
|
|
//console.log("HELLO");
|
|
|
|
//console.log(arg1,arg2,arg3,arg4);
|
|
|
|
//done();
|
2015-06-16 10:17:06 +02:00
|
|
|
//});
|
2017-02-15 19:33:05 +01:00
|
|
|
var flow = [{
|
|
|
|
id: "n1",
|
|
|
|
type: "e-mail",
|
|
|
|
name: "test@gmail.com",
|
|
|
|
server: "smtp.gmail.com",
|
|
|
|
secure: true,
|
|
|
|
port: "465",
|
|
|
|
wires: [
|
|
|
|
[]
|
|
|
|
]
|
|
|
|
}];
|
|
|
|
helper.load(emailNode, flow, function () {
|
2015-06-13 19:48:17 +02:00
|
|
|
var n1 = helper.getNode("n1");
|
2017-02-15 19:33:05 +01:00
|
|
|
n1.should.have.property('name', "test@gmail.com");
|
|
|
|
n1.emit("input", {
|
|
|
|
payload: "Hello World",
|
|
|
|
to: "test@gmail.com"
|
|
|
|
});
|
2015-06-13 19:48:17 +02:00
|
|
|
//done();
|
|
|
|
});
|
2017-02-15 19:33:05 +01:00
|
|
|
setTimeout(function () {
|
2015-06-13 19:48:17 +02:00
|
|
|
try {
|
2017-02-15 19:33:05 +01:00
|
|
|
var logEvents = helper.log().args.filter(function (evt) {
|
|
|
|
//console.log(evt[0].msg);
|
2015-06-13 19:48:17 +02:00
|
|
|
return evt[0].type == "e-mail";
|
|
|
|
});
|
2017-02-15 19:33:05 +01:00
|
|
|
//console.log(helper.log().args);
|
2015-06-29 23:41:06 +02:00
|
|
|
//logEvents.should.have.length(3);
|
|
|
|
logEvents[0][0].should.have.a.property('msg');
|
2023-03-27 21:27:47 +02:00
|
|
|
logEvents[2][0].msg.toString().should.startWith("Error:");
|
2015-06-13 19:48:17 +02:00
|
|
|
done();
|
2017-02-15 19:33:05 +01:00
|
|
|
} catch (e) {
|
|
|
|
done(e);
|
2015-06-13 19:48:17 +02:00
|
|
|
}
|
2015-06-16 10:17:06 +02:00
|
|
|
//finally { smtpTransport.sendMail.restore(); }
|
2018-01-21 17:24:41 +01:00
|
|
|
}, 1900);
|
2015-06-13 19:48:17 +02:00
|
|
|
})
|
|
|
|
|
|
|
|
});
|
2020-10-19 15:32:09 +02:00
|
|
|
|
|
|
|
describe('email mta', function () {
|
|
|
|
|
|
|
|
it('should catch an email send to localhost 1025', function (done) {
|
|
|
|
var flow = [{
|
|
|
|
id: "n1",
|
|
|
|
type: "e-mail mta",
|
|
|
|
name: "emailmta",
|
|
|
|
port: 1025,
|
|
|
|
wires: [
|
|
|
|
["n2"]
|
|
|
|
]
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id:"n2",
|
|
|
|
type:"helper"
|
|
|
|
},
|
|
|
|
{
|
|
|
|
id: "n3",
|
|
|
|
type: "e-mail",
|
|
|
|
dname: "testout",
|
|
|
|
server: "localhost",
|
|
|
|
secure: false,
|
|
|
|
port: 1025,
|
|
|
|
wires: [
|
|
|
|
[]
|
|
|
|
]
|
|
|
|
}];
|
|
|
|
helper.load(emailNode, flow, function () {
|
|
|
|
var n1 = helper.getNode("n1");
|
|
|
|
var n2 = helper.getNode("n2");
|
|
|
|
var n3 = helper.getNode("n3");
|
|
|
|
n1.should.have.property('port', 1025);
|
|
|
|
|
|
|
|
n2.on("input", function(msg) {
|
|
|
|
//console.log("GOT",msg);
|
2020-10-19 22:33:32 +02:00
|
|
|
try {
|
|
|
|
msg.should.have.a.property("payload",'Hello World\n');
|
|
|
|
msg.should.have.a.property("topic","Test");
|
|
|
|
msg.should.have.a.property("from",'foo@example.com');
|
|
|
|
msg.should.have.a.property("to",'bar@example.com');
|
|
|
|
msg.should.have.a.property("attachments");
|
|
|
|
msg.should.have.a.property("header");
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
catch(e) {
|
|
|
|
done(e)
|
|
|
|
}
|
2020-10-19 15:32:09 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
n3.emit("input", {
|
|
|
|
payload: "Hello World",
|
|
|
|
topic: "Test",
|
|
|
|
from: "foo@example.com",
|
|
|
|
to: "bar@example.com"
|
|
|
|
});
|
|
|
|
//done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2018-01-21 17:24:41 +01:00
|
|
|
});
|