@@ -4,7 +4,13 @@ import { Readable } from 'stream';
4
4
import { clearTimeout , setTimeout as setTimeoutCb } from 'timers' ;
5
5
import { setInterval } from 'timers/promises' ;
6
6
7
- import { type Collection , type Document , type MongoClient , ObjectId } from '../mongodb' ;
7
+ import {
8
+ type Collection ,
9
+ type Document ,
10
+ type MongoClient ,
11
+ ObjectId ,
12
+ ReadConcern
13
+ } from '../mongodb' ;
8
14
9
15
class TimeoutController extends AbortController {
10
16
timeoutId : NodeJS . Timeout ;
@@ -46,10 +52,12 @@ describe('Index Management Prose Tests', function () {
46
52
*/
47
53
function waitForIndexes ( {
48
54
predicate,
49
- indexNames
55
+ indexNames,
56
+ collection
50
57
} : {
51
58
predicate : ( arg0 : Array < Document > ) => boolean ;
52
59
indexNames : string | string [ ] ;
60
+ collection : Collection ;
53
61
} ) : Promise < Array < Document > > {
54
62
const names = new Set ( [ indexNames ] . flat ( ) ) ;
55
63
return Readable . from (
@@ -112,7 +120,8 @@ describe('Index Management Prose Tests', function () {
112
120
// 1. An index with the name of test-search-index is present and the index has a field queryable with a value of true.
113
121
const [ index ] = await waitForIndexes ( {
114
122
predicate : indexes => indexes . every ( index => index . queryable ) ,
115
- indexNames : 'test-search-index'
123
+ indexNames : 'test-search-index' ,
124
+ collection
116
125
} ) ;
117
126
118
127
// Assert that index has a property latestDefinition whose value is { 'mappings': { 'dynamic': false } }
@@ -165,7 +174,8 @@ describe('Index Management Prose Tests', function () {
165
174
// 2. An index with the name of test-search-index-2 is present and index has a field queryable with the value of true. Store result in index2.
166
175
const indexes = await waitForIndexes ( {
167
176
predicate : indexes => indexes . every ( index => index . queryable ) ,
168
- indexNames : [ 'test-search-index-1' , 'test-search-index-2' ]
177
+ indexNames : [ 'test-search-index-1' , 'test-search-index-2' ] ,
178
+ collection
169
179
} ) ;
170
180
171
181
const index1 = indexes . find ( ( { name } ) => name === 'test-search-index-1' ) ;
@@ -203,7 +213,8 @@ describe('Index Management Prose Tests', function () {
203
213
// 1. An index with the name of test-search-index is present and index has a field queryable with the value of true.
204
214
await waitForIndexes ( {
205
215
predicate : indexes => indexes . every ( index => index . queryable ) ,
206
- indexNames : 'test-search-index'
216
+ indexNames : 'test-search-index' ,
217
+ collection
207
218
} ) ;
208
219
209
220
// Run a dropSearchIndex on coll0, using test-search-index for the name.
@@ -213,7 +224,8 @@ describe('Index Management Prose Tests', function () {
213
224
// This test fails if it times out waiting for the deletion to succeed.
214
225
const indexes = await waitForIndexes ( {
215
226
predicate : indexes => indexes . length === 0 ,
216
- indexNames : 'test-search-index'
227
+ indexNames : 'test-search-index' ,
228
+ collection
217
229
} ) ;
218
230
219
231
expect ( indexes ) . to . deep . equal ( [ ] ) ;
@@ -241,7 +253,8 @@ describe('Index Management Prose Tests', function () {
241
253
// 1. An index with the name of test-search-index is present and index has a field queryable with the value of true.
242
254
await waitForIndexes ( {
243
255
predicate : indexes => indexes . every ( index => index . queryable ) ,
244
- indexNames : 'test-search-index'
256
+ indexNames : 'test-search-index' ,
257
+ collection
245
258
} ) ;
246
259
247
260
// Run a updateSearchIndex on coll0, using the following definition.
@@ -261,7 +274,8 @@ describe('Index Management Prose Tests', function () {
261
274
// 2. The index has a field queryable with a value of true and has a field status with the value of READY.
262
275
const [ index2 ] = await waitForIndexes ( {
263
276
predicate : indexes => indexes . every ( index => index . queryable && index . status === 'READY' ) ,
264
- indexNames : 'test-search-index'
277
+ indexNames : 'test-search-index' ,
278
+ collection
265
279
} ) ;
266
280
267
281
// Assert that an index is present with the name test-search-index and the definition has a
@@ -283,5 +297,48 @@ describe('Index Management Prose Tests', function () {
283
297
await collection . dropSearchIndex ( 'test-search-index' ) ;
284
298
}
285
299
) ;
300
+
301
+ it (
302
+ 'Case 6: Driver can successfully create and list search indexes with non-default readConcern and writeConcern' ,
303
+ metadata ,
304
+ async function ( ) {
305
+ // 1. Create a collection with the "create" command using a randomly generated name (referred to as coll0).
306
+ // 2. Apply a write concern WriteConcern(w=1) and a read concern with ReadConcern(level="majority") to coll0.
307
+ const coll0 = await client . db ( 'node-test' ) . createCollection ( new ObjectId ( ) . toHexString ( ) , {
308
+ readConcern : ReadConcern . MAJORITY ,
309
+ writeConcern : { w : 1 }
310
+ } ) ;
311
+
312
+ // 3. Create a new search index on coll0 with the createSearchIndex helper. Use the following definition:
313
+ // {
314
+ // name: 'test-search-index-case6',
315
+ // definition: {
316
+ // mappings: { dynamic: false }
317
+ // }
318
+ // }
319
+ const name = await coll0 . createSearchIndex ( {
320
+ name : 'test-search-index-case6' ,
321
+ definition : {
322
+ mappings : { dynamic : false }
323
+ }
324
+ } ) ;
325
+
326
+ // 4. Assert that the command returns the name of the index: "test-search-index-case6".
327
+ expect ( name ) . to . equal ( 'test-search-index-case6' ) ;
328
+
329
+ // 5. Run coll0.listSearchIndexes() repeatedly every 5 seconds until the following condition is satisfied and store the value in a variable index:
330
+ // - An index with the name of test-search-index-case6 is present and the index has a field queryable with a value of true.
331
+ const [ index ] = await waitForIndexes ( {
332
+ predicate : indexes => indexes . every ( index => index . queryable ) ,
333
+ indexNames : 'test-search-index-case6' ,
334
+ collection : coll0
335
+ } ) ;
336
+
337
+ // 6. Assert that index has a property latestDefinition whose value is { 'mappings': { 'dynamic': false } }
338
+ expect ( index )
339
+ . to . have . nested . property ( 'latestDefinition.mappings' )
340
+ . to . deep . equal ( { dynamic : false } ) ;
341
+ }
342
+ ) ;
286
343
} ) ;
287
344
} ) ;
0 commit comments