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

fix(NODE-3662): error checking to make sure that ObjectId results in object with correct properties #467

Merged
merged 17 commits into from Nov 2, 2021

Conversation

gjchong25
Copy link
Contributor

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.

@gjchong25 gjchong25 added Primary Review In Review with primary reviewer, not yet ready for team's eyes and removed Primary Review In Review with primary reviewer, not yet ready for team's eyes labels Oct 26, 2021
@dariakp dariakp self-requested a review October 26, 2021 21:25
@dariakp dariakp added the Primary Review In Review with primary reviewer, not yet ready for team's eyes label Oct 26, 2021
src/objectid.ts Outdated Show resolved Hide resolved
test/node/object_id_tests.js Outdated Show resolved Hide resolved
test/node/object_id_tests.js Show resolved Hide resolved
Copy link
Contributor

@dariakp dariakp left a 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).

test/node/object_id_tests.js Outdated Show resolved Hide resolved
@gjchong25 gjchong25 changed the title refactor(NODE-3662): error checking to make sure that ObjectId results in object with correct properties fix(NODE-3662): error checking to make sure that ObjectId results in object with correct properties Oct 27, 2021
@dariakp dariakp added Team Review Needs review from team and removed Primary Review In Review with primary reviewer, not yet ready for team's eyes labels Oct 27, 2021
test/node/object_id_tests.js Outdated Show resolved Hide resolved
src/objectid.ts Outdated Show resolved Hide resolved
src/objectid.ts Outdated Show resolved Hide resolved
test/node/object_id_tests.js Outdated Show resolved Hide resolved
Copy link
Contributor

@dariakp dariakp left a 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:

src/objectid.ts Outdated Show resolved Hide resolved
Copy link
Contributor

@nbbeeken nbbeeken left a 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 :)

src/objectid.ts Show resolved Hide resolved
test/node/object_id_tests.js Outdated Show resolved Hide resolved
test/node/object_id_tests.js Outdated Show resolved Hide resolved
test/node/object_id_tests.js Outdated Show resolved Hide resolved
test/node/object_id_tests.js Outdated Show resolved Hide resolved
test/node/object_id_tests.js Outdated Show resolved Hide resolved
test/node/object_id_tests.js Outdated Show resolved Hide resolved
test/node/object_id_tests.js Outdated Show resolved Hide resolved
test/node/object_id_tests.js Outdated Show resolved Hide resolved
test/node/object_id_tests.js Show resolved Hide resolved
test/node/object_id_tests.js Show resolved Hide resolved
test/node/object_id_tests.js Outdated Show resolved Hide resolved
test/node/object_id_tests.js Show resolved Hide resolved
Copy link
Contributor

@dariakp dariakp left a 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!

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();
Copy link
Contributor

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.

@dariakp dariakp merged commit 5f99b1b into master Nov 2, 2021
@dariakp dariakp deleted the NODE-3662 branch November 2, 2021 19:33
gjchong25 added a commit that referenced this pull request Nov 2, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Team Review Needs review from team
Projects
None yet
3 participants