@@ -2,7 +2,6 @@ import * as fs from 'node:fs/promises';
22import * as path from 'node:path' ;
33
44import { expect } from 'chai' ;
5- import { type Test } from 'mocha' ;
65import { type MongoCryptOptions } from 'mongodb-client-encryption' ;
76import * as sinon from 'sinon' ;
87
@@ -15,7 +14,7 @@ const defaultMetadata: MongoDBMetadataUI = {
1514 requires : {
1615 topology : '!single' ,
1716 clientSideEncryption : '>=6.3.0' ,
18- mongodb : '>=8.1 .0'
17+ mongodb : '>=7.0 .0'
1918 }
2019} ;
2120
@@ -31,6 +30,7 @@ const newEncryptedClient = ({ configuration }: { configuration: TestConfiguratio
3130 configuration . newClient (
3231 { } ,
3332 {
33+ writeConcern : { w : 'majority' } ,
3434 autoEncryption : {
3535 keyVaultNamespace : 'db.keyvault' ,
3636 kmsProviders : { local : getCSFLEKMSProviders ( ) . local } ,
@@ -41,9 +41,7 @@ const newEncryptedClient = ({ configuration }: { configuration: TestConfiguratio
4141
4242describe ( '$lookup support' , defaultMetadata , function ( ) {
4343 before ( async function ( ) {
44- const mochaTest = {
45- metadata : defaultMetadata
46- } as unknown as Test ;
44+ const mochaTest = { metadata : defaultMetadata } ;
4745
4846 if ( ! this . configuration . filters . MongoDBVersionFilter . filter ( mochaTest ) ) {
4947 return ;
@@ -57,16 +55,26 @@ describe('$lookup support', defaultMetadata, function () {
5755 return ;
5856 }
5957
60- let client : MongoClient , encryptedClient : MongoClient ;
58+ let unencryptedClient : MongoClient , encryptedClient : MongoClient ;
6159 try {
62- /** Create an unencrypted MongoClient. */
63- client = this . configuration . newClient ( ) ;
60+ /**
61+ * Create an encrypted MongoClient configured with:
62+ *
63+ * ```txt
64+ * AutoEncryptionOpts(
65+ * keyVaultNamespace="db.keyvault",
66+ * kmsProviders={"local": { "key": "<base64 decoding of LOCAL_MASTERKEY>" }}
67+ * )
68+ * ```
69+ */
70+ encryptedClient = newEncryptedClient ( this ) ;
71+
6472 /** Drop database db. */
65- await client . db ( 'db' ) . dropDatabase ( ) ;
73+ await encryptedClient . db ( 'db' ) . dropDatabase ( ) ;
6674
6775 /** Insert `key-doc.json` into db.keyvault. */
6876 const keyDoc = await readFixture ( 'key-doc.json' ) ;
69- await client . db ( 'db' ) . collection ( 'keyvault' ) . insertOne ( keyDoc ) ;
77+ await encryptedClient . db ( 'db' ) . collection ( 'keyvault' ) . insertOne ( keyDoc ) ;
7078
7179 /**
7280 * Create the following collections:
@@ -113,20 +121,11 @@ describe('$lookup support', defaultMetadata, function () {
113121 ] ;
114122
115123 for ( const { name, options } of collections ) {
116- await client . db ( 'db' ) . createCollection ( name , options ) ;
124+ await encryptedClient . db ( 'db' ) . createCollection ( name , options ) ;
117125 }
118126
119- /**
120- * Create an encrypted MongoClient configured with:
121- *
122- * ```txt
123- * AutoEncryptionOpts(
124- * keyVaultNamespace="db.keyvault",
125- * kmsProviders={"local": { "key": "<base64 decoding of LOCAL_MASTERKEY>" }}
126- * )
127- * ```
128- */
129- encryptedClient = newEncryptedClient ( this ) ;
127+ /** Create an unencrypted MongoClient. */
128+ unencryptedClient = this . configuration . newClient ( { } , { writeConcern : { w : 'majority' } } ) ;
130129
131130 /**
132131 * ```
@@ -147,12 +146,12 @@ describe('$lookup support', defaultMetadata, function () {
147146
148147 if ( name . startsWith ( 'no_' ) ) continue ;
149148
150- expect ( await client . db ( 'db' ) . collection ( name ) . findOne ( insertedId ) )
149+ expect ( await unencryptedClient . db ( 'db' ) . collection ( name ) . findOne ( insertedId ) )
151150 . to . have . property ( Object . keys ( document ) [ 0 ] )
152151 . that . has . property ( '_bsontype' , 'Binary' ) ;
153152 }
154153 } finally {
155- await client ?. close ( ) ;
154+ await unencryptedClient ?. close ( ) ;
156155 await encryptedClient ?. close ( ) ;
157156 }
158157 } ) ;
@@ -161,7 +160,7 @@ describe('$lookup support', defaultMetadata, function () {
161160 title : string ,
162161 collName : string ,
163162 pipeline : Document [ ] ,
164- expected : Document ,
163+ expected : Document | RegExp ,
165164 metadata ?: MongoDBMetadataUI
166165 ) {
167166 describe ( title . slice ( 0 , title . indexOf ( ':' ) ) , function ( ) {
@@ -182,12 +181,11 @@ describe('$lookup support', defaultMetadata, function () {
182181 . toArray ( )
183182 . catch ( error => error ) ;
184183
185- const expectedError = expected instanceof Error ;
184+ const expectedError = expected instanceof RegExp ;
186185
187186 if ( expectedError ) {
188187 expect ( actual ) . to . be . instanceOf ( Error ) ;
189- const expectedErrorMessage = new RegExp ( expected . message , 'i' ) ;
190- if ( ! expectedErrorMessage . test ( actual . message ) ) {
188+ if ( ! expected . test ( actual . message ) ) {
191189 throw actual ;
192190 }
193191 } else if ( actual instanceof Error ) {
@@ -214,7 +212,8 @@ describe('$lookup support', defaultMetadata, function () {
214212 } ,
215213 { $project : { _id : 0 } }
216214 ] ,
217- { csfle : 'csfle' , matched : [ { no_schema : 'no_schema' } ] }
215+ { csfle : 'csfle' , matched : [ { no_schema : 'no_schema' } ] } ,
216+ { requires : { ...defaultMetadata . requires , mongodb : '>=8.1.0' } }
218217 ) ;
219218
220219 test (
@@ -234,7 +233,8 @@ describe('$lookup support', defaultMetadata, function () {
234233 } ,
235234 { $project : { _id : 0 , __safeContent__ : 0 } }
236235 ] ,
237- { qe : 'qe' , matched : [ { no_schema : 'no_schema' } ] }
236+ { qe : 'qe' , matched : [ { no_schema : 'no_schema' } ] } ,
237+ { requires : { ...defaultMetadata . requires , mongodb : '>=8.1.0' } }
238238 ) ;
239239
240240 test (
@@ -251,7 +251,8 @@ describe('$lookup support', defaultMetadata, function () {
251251 } ,
252252 { $project : { _id : 0 } }
253253 ] ,
254- { no_schema : 'no_schema' , matched : [ { csfle : 'csfle' } ] }
254+ { no_schema : 'no_schema' , matched : [ { csfle : 'csfle' } ] } ,
255+ { requires : { ...defaultMetadata . requires , mongodb : '>=8.1.0' } }
255256 ) ;
256257
257258 test (
@@ -268,7 +269,8 @@ describe('$lookup support', defaultMetadata, function () {
268269 } ,
269270 { $project : { _id : 0 } }
270271 ] ,
271- { no_schema : 'no_schema' , matched : [ { qe : 'qe' } ] }
272+ { no_schema : 'no_schema' , matched : [ { qe : 'qe' } ] } ,
273+ { requires : { ...defaultMetadata . requires , mongodb : '>=8.1.0' } }
272274 ) ;
273275
274276 test (
@@ -285,7 +287,8 @@ describe('$lookup support', defaultMetadata, function () {
285287 } ,
286288 { $project : { _id : 0 } }
287289 ] ,
288- { csfle : 'csfle' , matched : [ { csfle2 : 'csfle2' } ] }
290+ { csfle : 'csfle' , matched : [ { csfle2 : 'csfle2' } ] } ,
291+ { requires : { ...defaultMetadata . requires , mongodb : '>=8.1.0' } }
289292 ) ;
290293
291294 test (
@@ -302,7 +305,8 @@ describe('$lookup support', defaultMetadata, function () {
302305 } ,
303306 { $project : { _id : 0 , __safeContent__ : 0 } }
304307 ] ,
305- { qe : 'qe' , matched : [ { qe2 : 'qe2' } ] }
308+ { qe : 'qe' , matched : [ { qe2 : 'qe2' } ] } ,
309+ { requires : { ...defaultMetadata . requires , mongodb : '>=8.1.0' } }
306310 ) ;
307311
308312 test (
@@ -319,7 +323,8 @@ describe('$lookup support', defaultMetadata, function () {
319323 } ,
320324 { $project : { _id : 0 } }
321325 ] ,
322- { no_schema : 'no_schema' , matched : [ { no_schema2 : 'no_schema2' } ] }
326+ { no_schema : 'no_schema' , matched : [ { no_schema2 : 'no_schema2' } ] } ,
327+ { requires : { ...defaultMetadata . requires , mongodb : '>=8.1.0' } }
323328 ) ;
324329
325330 test (
@@ -336,7 +341,8 @@ describe('$lookup support', defaultMetadata, function () {
336341 } ,
337342 { $project : { _id : 0 } }
338343 ] ,
339- new Error ( 'not supported' )
344+ / n o t s u p p o r t e d / i,
345+ { requires : { ...defaultMetadata . requires , mongodb : '>=8.1.0' } }
340346 ) ;
341347
342348 test (
@@ -353,7 +359,7 @@ describe('$lookup support', defaultMetadata, function () {
353359 } ,
354360 { $project : { _id : 0 } }
355361 ] ,
356- new Error ( ' Upgrade' ) ,
362+ / U p g r a d e / i ,
357363 { requires : { ...defaultMetadata . requires , mongodb : '<8.1.0' } }
358364 ) ;
359365
@@ -362,9 +368,7 @@ describe('$lookup support', defaultMetadata, function () {
362368 let client : MongoClient ;
363369
364370 beforeEach ( async function ( ) {
365- const mochaTest = {
366- metadata : defaultMetadata
367- } as unknown as Test ;
371+ const mochaTest = { metadata : defaultMetadata } ;
368372
369373 if ( ! this . configuration . filters . MongoDBVersionFilter . filter ( mochaTest ) ) {
370374 return ;
@@ -390,16 +394,7 @@ describe('$lookup support', defaultMetadata, function () {
390394 } ;
391395 } ) ;
392396
393- client = this . configuration . newClient (
394- { } ,
395- {
396- autoEncryption : {
397- keyVaultNamespace : 'db.keyvault' ,
398- kmsProviders : { local : getCSFLEKMSProviders ( ) . local } ,
399- extraOptions : getEncryptExtraOptions ( )
400- }
401- }
402- ) ;
397+ client = newEncryptedClient ( this ) ;
403398 } ) ;
404399
405400 afterEach ( async function ( ) {
0 commit comments