Skip to content

test(NODE-6438): check that BSON undefined is returned from deserialize #721

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

Merged
merged 3 commits into from
Oct 22, 2024

Conversation

nbbeeken
Copy link
Contributor

Description

What is changing?

  • Prevent deserialize from changing the value returned for BSON undefined
  • Reorganize tests around ignoreUndefined
Is there new documentation needed for these changes?

Yes

What is the motivation for this change?

I noticed no test fails if I change BSON_DATA_UNDEFINED handling, seems worthy of coverage given how the serializer special cases that same value.

Double check the following

  • Ran npm run check:lint script
  • Self-review completed using the steps outlined here
  • PR title follows the correct format: type(NODE-xxxx)[!]: description
    • Example: feat(NODE-1234)!: rewriting everything in coffeescript
  • Changes are covered by tests
  • New TODOs have a related JIRA ticket

@nbbeeken nbbeeken marked this pull request as ready for review October 21, 2024 17:21
describe('when serialize is given a javascript object that contains undefined', () => {
describe('when ignoreUndefined is set to false', function () {
it('serializes to document with a set to BSON null (type=10)', () => {
const jsObject = BSON.deserialize(bsonDocWithUndefined);
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
const jsObject = BSON.deserialize(bsonDocWithUndefined);
const jsObject = { a: undefined };

Is there a reason we can't use an object literal?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point, fixed

const jsObject = BSON.deserialize(bsonDocWithUndefined);
const bytes = BSON.serialize(jsObject, { ignoreUndefined: false });
expect(bytes).to.have.lengthOf(8);
expect(bytes).to.have.own.property('4', BSON_DATA_NULL);
Copy link
Contributor

@baileympearson baileympearson Oct 21, 2024

Choose a reason for hiding this comment

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

What is happening in this assertion? Does haveOwnProperty check for index access if the object is a Buffer?

Could we use parseToElementsToArray to re-parse the serialized bytes and confirm the serialized bytes contain one BSON null?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good use of parseToElements

@baileympearson baileympearson self-assigned this Oct 21, 2024
@baileympearson baileympearson added the Primary Review In Review with primary reviewer, not yet ready for team's eyes label Oct 21, 2024
@baileympearson baileympearson merged commit fedfaa1 into main Oct 22, 2024
6 of 8 checks passed
@baileympearson baileympearson deleted the test-undefined branch October 22, 2024 00:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Primary Review In Review with primary reviewer, not yet ready for team's eyes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants