-
Notifications
You must be signed in to change notification settings - Fork 256
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
fix(NODE-3662): error checking to make sure that ObjectId results in object with correct properties #467
Conversation
…s in object with correct properties
…and add test for invalid id type
…tructor to test for errors
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for adding the extra test cases, just a small suggestion for improving the effectiveness of the tests here. Also, since we are fixing a bug, the title of the PR should start with fix(NODE-3662) ...
so that it will be picked up and listed in our automatically generated docs (refactor and test type commits are skipped in the docs).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Based on our discussion, capturing the desired change notes:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looking good, some nits and notes :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One tiny comment here, but looking great otherwise. Thank you for doing all this clean up!
test/node/object_id_tests.js
Outdated
expect(Buffer.from([0, 0, 0, 1])).to.deep.equal(a.id.slice(0, 4)); | ||
expect(1000).to.equal(a.getTimestamp().getTime()); | ||
|
||
var b = new ObjectId(); | ||
let b = new ObjectId(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This and the declaration in L10 can be a const
. One somewhat weird thing in JS that you might not be aware of is that const
does not mean "unchanging", it only means "unchanging reference", so even though we set a property on b
in L14, as far as JS is concerned, b
is still a const, because its reference is unchanged.
…object with correct properties (#467)
Tightens the logic within the ObjectId constructor to make sure that inputs to the constructor are of the proper types, otherwise throws a TypeError. Tests to make sure that invalid inputs have an error thrown (rather than creating a "broken" ObjectId object with no 'id' property, for instance) are added.