diff --git a/social/email/61-email.js b/social/email/61-email.js index bf315fed..195d390d 100644 --- a/social/email/61-email.js +++ b/social/email/61-email.js @@ -127,8 +127,8 @@ module.exports = function(RED) { RED.nodes.createNode(this,n); this.name = n.name; this.repeat = n.repeat * 1000 || 300000; - this.inserver = n.server || globalkeys.server || "imap.gmail.com"; - this.inport = n.port || globalkeys.port || "993"; + this.inserver = n.server || (globalkeys && globalkeys.server) || "imap.gmail.com"; + this.inport = n.port || (globalkeys && globalkeys.port) || "993"; this.box = n.box || "INBOX"; var flag = false; diff --git a/test/social/email/61-email_spec.js b/test/social/email/61-email_spec.js index 030a5b30..9aba594d 100644 --- a/test/social/email/61-email_spec.js +++ b/test/social/email/61-email_spec.js @@ -30,56 +30,13 @@ describe('email Node', function() { helper.stopServer(done); }); - describe.skip('email out', function() { + describe('email in', function() { it('should load with defaults', function(done) { - var flow = [ { id:"n1", type:"e-mail", name:"emailout", wires:[[]] } ]; - helper.load(emailNode, flow, function() { - var n1 = helper.getNode("n1"); - n1.should.have.property('name', "emailout"); - done(); - }); - }); - - it('should send an email', 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(); - //}); - var flow = [ { id:"n1", type:"e-mail", name:"emailout", outserver:"smtp.gmail.com", outport:"465", wires:[[]] } ]; - helper.load(emailNode, flow, function() { - var n1 = helper.getNode("n1"); - n1.should.have.property('name', "emailout"); - n1.emit("input", {payload:"Hello World"}); - //done(); - }); - setTimeout(function() { - try { - var logEvents = helper.log().args.filter(function(evt) { - return evt[0].type == "e-mail"; - }); - //console.log(logEvents); - logEvents.should.have.length(1); - logEvents[0][0].should.have.a.property('msg'); - logEvents[0][0].msg.toString().should.startWith("Error: connect ECONNREFUSED"); - done(); - } - catch(e) { done(e); } - //finally { smtpTransport.sendMail.restore(); } - },150); - }) - - }); - - describe.skip('email in', function() { - - it('should load with defaults', function(done) { - var flow = [ { id:"n1", type:"e-mail in", wires:[["n2"]] }, - {id:"n2", type:"helper"} ]; + var flow = [ { id:"n1", type:"e-mail in", name:"emailin", wires:[[]] } ]; helper.load(emailNode, flow, function() { var n1 = helper.getNode("n1"); + n1.should.have.property('name', "emailin"); n1.should.have.property("repeat", 300000); n1.should.have.property("inserver", "imap.gmail.com"); n1.should.have.property("inport", "993"); @@ -104,4 +61,47 @@ describe('email Node', function() { }); + describe('email out', function() { + + it('should load with defaults', function(done) { + var flow = [ { id:"n1", type:"e-mail", name:"emailout", wires:[[]] } ]; + helper.load(emailNode, flow, function() { + var n1 = helper.getNode("n1"); + n1.should.have.property('name', "emailout"); + done(); + }); + }); + + it('should fail to send an email (no valid creds)', 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(); + //}); + var flow = [ { id:"n1", type:"e-mail", name:"emailout", outserver:"smtp.gmail.com", outport:"465", wires:[[]] } ]; + helper.load(emailNode, flow, function() { + var n1 = helper.getNode("n1"); + n1.should.have.property('name', "emailout"); + n1.emit("input", {payload:"Hello World"}); + //done(); + }); + setTimeout(function() { + try { + var logEvents = helper.log().args.filter(function(evt) { + return evt[0].type == "e-mail"; + }); + //console.log(logEvents); + logEvents.should.have.length(3); + logEvents[2][0].should.have.a.property('msg'); + logEvents[2][0].msg.toString().should.startWith("Error: connect ECONNREFUSED"); + done(); + } + catch(e) { done(e); } + //finally { smtpTransport.sendMail.restore(); } + },150); + }) + + }); + });