From 8b9f7acacd463183bf51a2444f074cdf834c2f28 Mon Sep 17 00:00:00 2001 From: Sergey Zelenov Date: Mon, 22 Sep 2025 10:44:13 +0200 Subject: [PATCH 1/2] test(NODE-7165): convert to .ts --- .../{decimal128.test.js => decimal128.test.ts} | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) rename test/integration/bson-decimal128/{decimal128.test.js => decimal128.test.ts} (62%) diff --git a/test/integration/bson-decimal128/decimal128.test.js b/test/integration/bson-decimal128/decimal128.test.ts similarity index 62% rename from test/integration/bson-decimal128/decimal128.test.js rename to test/integration/bson-decimal128/decimal128.test.ts index 81b33ce6a46..11cd87c4c7c 100644 --- a/test/integration/bson-decimal128/decimal128.test.js +++ b/test/integration/bson-decimal128/decimal128.test.ts @@ -1,8 +1,7 @@ -'use strict'; -const { assert: test } = require('../shared'); -const { expect } = require('chai'); -const { setupDatabase } = require('../shared'); -const { Decimal128 } = require('../../mongodb'); +import { expect } from 'chai'; + +import { Decimal128 } from '../../mongodb'; +import { assert as test, setupDatabase } from '../shared'; describe('Decimal128', function () { before(function () { @@ -10,10 +9,10 @@ describe('Decimal128', function () { }); it('should correctly insert decimal128 value', function (done) { - var configuration = this.configuration; - var client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 }); - var db = client.db(configuration.db); - var object = { + const configuration = this.configuration; + const client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 }); + const db = client.db(configuration.db); + const object = { id: 1, value: Decimal128.fromString('1.28') }; From 78dfe9e27fcbcc082d928cb29e33564a5a76849a Mon Sep 17 00:00:00 2001 From: Sergey Zelenov Date: Mon, 22 Sep 2025 11:05:32 +0200 Subject: [PATCH 2/2] test(NODE-7165): use direct import from `src`, use `async/await` --- .../bson-decimal128/decimal128.test.ts | 42 ++++++++----------- 1 file changed, 18 insertions(+), 24 deletions(-) diff --git a/test/integration/bson-decimal128/decimal128.test.ts b/test/integration/bson-decimal128/decimal128.test.ts index 11cd87c4c7c..73e7bab69a4 100644 --- a/test/integration/bson-decimal128/decimal128.test.ts +++ b/test/integration/bson-decimal128/decimal128.test.ts @@ -1,37 +1,31 @@ import { expect } from 'chai'; -import { Decimal128 } from '../../mongodb'; -import { assert as test, setupDatabase } from '../shared'; +import { type Collection, Decimal128, type MongoClient } from '../../../src'; describe('Decimal128', function () { - before(function () { - return setupDatabase(this.configuration); + let client: MongoClient; + let collection: Collection; + + beforeEach(async function () { + client = this.configuration.newClient(); + collection = client.db('decimal128').collection('decimal128'); + }); + + afterEach(async function () { + await client.close(); }); - it('should correctly insert decimal128 value', function (done) { - const configuration = this.configuration; - const client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 }); - const db = client.db(configuration.db); + it('should correctly insert decimal128 value', async function () { const object = { id: 1, value: Decimal128.fromString('1.28') }; - - db.collection('decimal128').insertOne(object, function (err) { - expect(err).to.not.exist; - - db.collection('decimal128').findOne( - { - id: 1 - }, - function (err, doc) { - expect(err).to.not.exist; - test.ok(doc.value instanceof Decimal128); - test.equal('1.28', doc.value.toString()); - - client.close(done); - } - ); + await collection.insertOne(object); + const doc = await collection.findOne({ + id: 1 }); + + expect(doc.value).to.be.instanceof(Decimal128); + expect(doc.value.toString()).to.equal('1.28'); }); });