Skip to content

Conversation

tadjik1
Copy link
Contributor

@tadjik1 tadjik1 commented Oct 6, 2025

Description

Summary of Changes

This PR migrates the integration tests for crud/document_validation. The changes include:

  • Convert file in typescript
  • Refactor callbacks to async/await
  • Direct import from the src folder
Notes for Reviewers

To simplify the review process there is a separate commit for .js -> .ts conversion.

What is the motivation for this change?

This work is part of a larger, ongoing initiative to convert all tests to use async/await, with the ultimate goal of removing the legacy driver wrapper.

Double check the following

  • Lint is passing (npm run check:lint)
  • 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


// Ensure validation was correctly applied
const err = await col.insertOne({ b: 1 }).catch(err => err);
test.ok(err instanceof MongoServerError);
Copy link
Contributor Author

@tadjik1 tadjik1 Oct 6, 2025

Choose a reason for hiding this comment

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

We use slightly different approach here to assert an error, in previous version it was test.ok(err != null); and it worked well with callbacks, but with out current promise-based approach this won't work as err will be initialized in both (successful and failed) scenarios.

const err = await col
.updateOne({ b: 1 }, { $set: { b: 1 } }, { upsert: true })
.catch(err => err);
expect(err).to.be.instanceOf(MongoServerError);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same as above, the original test has expect(err).to.exist;.

@tadjik1 tadjik1 marked this pull request as ready for review October 6, 2025 08:25
@tadjik1 tadjik1 requested a review from a team as a code owner October 6, 2025 08:25
@durran durran self-assigned this Oct 6, 2025
@durran durran added the Primary Review In Review with primary reviewer, not yet ready for team's eyes label Oct 6, 2025

// Ensure validation was correctly applied
const err = await col.insertOne({ b: 1 }).catch(err => err);
test.ok(err instanceof MongoServerError);
Copy link
Member

Choose a reason for hiding this comment

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

Can we use chai for assertions here?

expect(err).to.be.instanceOf(MongoServerError)

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