Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ensure timeout is set to default value (fixes #225) #226

Merged
merged 1 commit into from
Jul 6, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion smtp/smtp.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,10 @@ class SMTP extends EventEmitter {
constructor(options = {}) {
super();

if (options.timeout == null) {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i guess the way to think about this is that if timeout is not a number, then we default to TIMEOUT.

we could try to improve on default values using destructuring: https://wesbos.com/destructuring-default-values/ and then checking for proper types afterwards.

i'll merge this for now, but something to keep in mind.

options.timeout = TIMEOUT;
}

const {
timeout,
user,
Expand All @@ -63,7 +67,6 @@ class SMTP extends EventEmitter {
authentication,
} = Object.assign(
{
timeout: TIMEOUT,
domain: os.hostname(),
host: 'localhost',
ssl: false,
Expand Down Expand Up @@ -640,3 +643,4 @@ class SMTP extends EventEmitter {
exports.SMTP = SMTP;
exports.state = SMTPState;
exports.authentication = AUTH_METHODS;
exports.DEFAULT_TIMEOUT = TIMEOUT;
19 changes: 19 additions & 0 deletions test/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,23 @@ describe('Connect to wrong email server', function() {
}
);
});

it('should have a default timeout', function(done) {
const connectionOptions = {
user: "username",
password: "password",
host: "127.0.0.1",
port: 1234,
};

assert.strictEqual(email.server.connect(connectionOptions).smtp.timeout, email.SMTP.DEFAULT_TIMEOUT);

connectionOptions.timeout = null;
assert.strictEqual(email.server.connect(connectionOptions).smtp.timeout, email.SMTP.DEFAULT_TIMEOUT);

connectionOptions.timeout = undefined;
assert.strictEqual(email.server.connect(connectionOptions).smtp.timeout, email.SMTP.DEFAULT_TIMEOUT);

done();
});
});