1
0
mirror of https://github.com/eleith/emailjs.git synced 2024-07-05 20:10:37 +00:00
emailjs/test/server.js

64 lines
1.4 KiB
JavaScript
Raw Normal View History

const assert = require('assert');
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;
beforeEach(function() {
if (require.cache[emailModulePath]) {
delete require.cache[emailModulePath];
}
2018-07-06 20:31:11 +00:00
email = require(emailModulePath);
});
it('Should not call callback multiple times with wrong server configuration', function(done) {
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();
}
);
});
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',
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
);
connectionOptions.timeout = null;
2018-07-06 17:42:46 +00:00
assert.strictEqual(
email.server.connect(connectionOptions).smtp.timeout,
email.SMTP.DEFAULT_TIMEOUT
);
connectionOptions.timeout = undefined;
2018-07-06 17:42:46 +00:00
assert.strictEqual(
email.server.connect(connectionOptions).smtp.timeout,
email.SMTP.DEFAULT_TIMEOUT
);
done();
});
});