2018-05-14 23:02:16 +00:00
|
|
|
const assert = require('assert');
|
2014-11-27 13:24:28 +00:00
|
|
|
|
2018-05-14 23:02:16 +00:00
|
|
|
describe('Connect to wrong email server', function() {
|
2018-07-06 20:31:11 +00:00
|
|
|
const emailModulePath = require.resolve('../email.js');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @type {typeof import('../email.js')}
|
|
|
|
*/
|
|
|
|
let email = null;
|
2014-11-27 13:24:28 +00:00
|
|
|
|
|
|
|
beforeEach(function() {
|
|
|
|
if (require.cache[emailModulePath]) {
|
|
|
|
delete require.cache[emailModulePath];
|
|
|
|
}
|
2018-07-06 20:31:11 +00:00
|
|
|
email = require(emailModulePath);
|
2014-11-27 13:24:28 +00:00
|
|
|
});
|
|
|
|
|
2018-05-14 23:02:16 +00:00
|
|
|
it('Should not call callback multiple times with wrong server configuration', function(done) {
|
2014-11-27 13:24:28 +00:00
|
|
|
this.timeout(5000);
|
2018-07-06 20:31:11 +00:00
|
|
|
const server = email.server.connect({ host: 'bar.baz' });
|
2018-05-27 04:25:08 +00:00
|
|
|
server.send(
|
|
|
|
{
|
|
|
|
from: 'foo@bar.baz',
|
|
|
|
to: 'foo@bar.baz',
|
|
|
|
subject: 'hello world',
|
|
|
|
text: 'hello world',
|
|
|
|
},
|
|
|
|
function(err) {
|
|
|
|
assert.notEqual(err, null);
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
);
|
2014-11-27 13:24:28 +00:00
|
|
|
});
|
2018-07-02 22:32:20 +00:00
|
|
|
|
|
|
|
it('should have a default timeout', function(done) {
|
|
|
|
const connectionOptions = {
|
2018-07-06 17:42:46 +00:00
|
|
|
user: 'username',
|
|
|
|
password: 'password',
|
|
|
|
host: '127.0.0.1',
|
2018-07-02 22:32:20 +00:00
|
|
|
port: 1234,
|
|
|
|
};
|
|
|
|
|
2018-07-06 17:42:46 +00:00
|
|
|
const email = require(emailModulePath);
|
|
|
|
assert.strictEqual(
|
|
|
|
email.server.connect(connectionOptions).smtp.timeout,
|
|
|
|
email.SMTP.DEFAULT_TIMEOUT
|
|
|
|
);
|
2018-07-02 22:32:20 +00:00
|
|
|
|
|
|
|
connectionOptions.timeout = null;
|
2018-07-06 17:42:46 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
email.server.connect(connectionOptions).smtp.timeout,
|
|
|
|
email.SMTP.DEFAULT_TIMEOUT
|
|
|
|
);
|
2018-07-02 22:32:20 +00:00
|
|
|
|
|
|
|
connectionOptions.timeout = undefined;
|
2018-07-06 17:42:46 +00:00
|
|
|
assert.strictEqual(
|
|
|
|
email.server.connect(connectionOptions).smtp.timeout,
|
|
|
|
email.SMTP.DEFAULT_TIMEOUT
|
|
|
|
);
|
2018-07-02 22:32:20 +00:00
|
|
|
|
|
|
|
done();
|
|
|
|
});
|
2014-11-27 13:24:28 +00:00
|
|
|
});
|