@@ -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 , MongoServerError } from '../mongodb' ;
7
+ import {
8
+ type Collection ,
9
+ type Document ,
10
+ type MongoClient ,
11
+ MongoServerError ,
12
+ ObjectId
13
+ } from '../mongodb' ;
8
14
9
15
class TimeoutController extends AbortController {
10
16
timeoutId : NodeJS . Timeout ;
@@ -284,156 +290,163 @@ describe('Index Management Prose Tests', function () {
284
290
}
285
291
) ;
286
292
287
- it ( 'Case 7: Driver can successfully handle search index types when creating indexes' , metadata , async function ( ) {
288
- // 01. Create a collection with the "create" command using a randomly generated name (referred to as `coll0`).
289
- const coll0 = collection ;
290
- {
291
- // 02. Create a new search index on `coll0` with the `createSearchIndex` helper. Use the following definition:
292
- // ```typescript
293
- // {
294
- // name: 'test-search-index-case7-implicit',
295
- // definition: {
296
- // mappings: { dynamic: false }
297
- // }
298
- // }
299
- // ```
300
- const indexName = await coll0 . createSearchIndex ( {
301
- name : 'test-search-index-case7-implicit' ,
302
- definition : {
303
- mappings : { dynamic : false }
304
- }
305
- } )
306
- // 03. Assert that the command returns the name of the index: `"test-search-index-case7-implicit"`.
307
- expect ( indexName ) . to . equal ( 'test-search-index-case7-implicit' )
308
- // 04. Run `coll0.listSearchIndexes('test-search-index-case7-implicit')` repeatedly every 5 seconds until the following
309
- // condition is satisfied and store the value in a variable `index1`:
310
-
311
- // - An index with the `name` of `test-search-index-case7-implicit` is present and the index has a field `queryable`
312
- // with a value of `true`.
313
-
314
- const [ index1 ] = await waitForIndexes ( {
315
- predicate : indexes => indexes . every ( index => index . queryable ) ,
316
- indexNames : 'test-search-index-case7-implicit'
317
- } ) ;
318
-
319
- // 05. Assert that `index1` has a property `type` whose value is `search`.
320
- expect ( index1 ) . to . have . property ( 'type' , 'search' ) ;
321
- }
322
- {
323
- // 06. Create a new search index on `coll0` with the `createSearchIndex` helper. Use the following definition:
324
- // ```typescript
325
- // {
326
- // name: 'test-search-index-case7-explicit',
327
- // type: 'search',
328
- // definition: {
329
- // mappings: { dynamic: false }
330
- // }
331
- // }
332
- // ```
333
- const indexName = await coll0 . createSearchIndex ( {
334
- name : 'test-search-index-case7-explicit' ,
335
- type : 'search' ,
336
- definition : {
337
- mappings : { dynamic : false }
338
- }
293
+ it (
294
+ 'Case 7: Driver can successfully handle search index types when creating indexes' ,
295
+ metadata ,
296
+ async function ( ) {
297
+ // 01. Create a collection with the "create" command using a randomly generated name (referred to as `coll0`).
298
+ const coll0 = collection ;
299
+ {
300
+ // 02. Create a new search index on `coll0` with the `createSearchIndex` helper. Use the following definition:
301
+ // ```typescript
302
+ // {
303
+ // name: 'test-search-index-case7-implicit',
304
+ // definition: {
305
+ // mappings: { dynamic: false }
306
+ // }
307
+ // }
308
+ // ```
309
+ const indexName = await coll0 . createSearchIndex ( {
310
+ name : 'test-search-index-case7-implicit' ,
311
+ definition : {
312
+ mappings : { dynamic : false }
313
+ }
314
+ } ) ;
315
+ // 03. Assert that the command returns the name of the index: `"test-search-index-case7-implicit"`.
316
+ expect ( indexName ) . to . equal ( 'test-search-index-case7-implicit' ) ;
317
+ // 04. Run `coll0.listSearchIndexes('test-search-index-case7-implicit')` repeatedly every 5 seconds until the following
318
+ // condition is satisfied and store the value in a variable `index1`:
319
+
320
+ // - An index with the `name` of `test-search-index-case7-implicit` is present and the index has a field `queryable`
321
+ // with a value of `true`.
322
+
323
+ const [ index1 ] = await waitForIndexes ( {
324
+ predicate : indexes => indexes . every ( index => index . queryable ) ,
325
+ indexNames : 'test-search-index-case7-implicit'
326
+ } ) ;
327
+
328
+ // 05. Assert that `index1` has a property `type` whose value is `search`.
329
+ expect ( index1 ) . to . have . property ( 'type' , 'search' ) ;
330
+ }
331
+ {
332
+ // 06. Create a new search index on `coll0` with the `createSearchIndex` helper. Use the following definition:
333
+ // ```typescript
334
+ // {
335
+ // name: 'test-search-index-case7-explicit',
336
+ // type: 'search',
337
+ // definition: {
338
+ // mappings: { dynamic: false }
339
+ // }
340
+ // }
341
+ // ```
342
+ const indexName = await coll0 . createSearchIndex ( {
343
+ name : 'test-search-index-case7-explicit' ,
344
+ type : 'search' ,
345
+ definition : {
346
+ mappings : { dynamic : false }
347
+ }
348
+ } ) ;
349
+ // 07. Assert that the command returns the name of the index: `"test-search-index-case7-explicit"`.
350
+ expect ( indexName ) . to . equal ( 'test-search-index-case7-explicit' ) ;
351
+ // 08. Run `coll0.listSearchIndexes('test-search-index-case7-explicit')` repeatedly every 5 seconds until the following
352
+ // condition is satisfied and store the value in a variable `index2`:
353
+
354
+ // - An index with the `name` of `test-search-index-case7-explicit` is present and the index has a field `queryable`
355
+ // with a value of `true`.
356
+
357
+ const [ index2 ] = await waitForIndexes ( {
358
+ predicate : indexes => indexes . every ( index => index . queryable ) ,
359
+ indexNames : 'test-search-index-case7-explicit'
360
+ } ) ;
361
+ // 09. Assert that `index2` has a property `type` whose value is `search`.
362
+ expect ( index2 ) . to . have . property ( 'type' , 'search' ) ;
363
+ }
364
+ {
365
+ // 10. Create a new vector search index on `coll0` with the `createSearchIndex` helper. Use the following definition:
366
+ // ```typescript
367
+ // {
368
+ // name: 'test-search-index-case7-vector',
369
+ // type: 'vectorSearch',
370
+ // definition: {
371
+ // "fields": [
372
+ // {
373
+ // "type": "vector",
374
+ // "path": "plot_embedding",
375
+ // "numDimensions": 1536,
376
+ // "similarity": "euclidean",
377
+ // },
378
+ // ]
379
+ // }
380
+ // }
381
+ // ```
382
+
383
+ const indexName = await coll0 . createSearchIndex ( {
384
+ name : 'test-search-index-case7-vector' ,
385
+ type : 'vectorSearch' ,
386
+ definition : {
387
+ fields : [
388
+ {
389
+ type : 'vector' ,
390
+ path : 'plot_embedding' ,
391
+ numDimensions : 1536 ,
392
+ similarity : 'euclidean'
393
+ }
394
+ ]
395
+ }
396
+ } ) ;
397
+ // 11. Assert that the command returns the name of the index: `"test-search-index-case7-vector"`.
398
+ expect ( indexName ) . to . equal ( 'test-search-index-case7-vector' ) ;
399
+ // 12. Run `coll0.listSearchIndexes('test-search-index-case7-vector')` repeatedly every 5 seconds until the following
400
+ // condition is satisfied and store the value in a variable `index3`:
401
+ // - An index with the `name` of `test-search-index-case7-vector` is present and the index has a field `queryable` with
402
+ // a value of `true`.
403
+ const [ index3 ] = await waitForIndexes ( {
404
+ predicate : indexes => indexes . every ( index => index . queryable ) ,
405
+ indexNames : 'test-search-index-case7-vector'
406
+ } ) ;
407
+
408
+ // 13. Assert that `index3` has a property `type` whose value is `vectorSearch`.
409
+ expect ( index3 ) . to . have . property ( 'type' , 'vectorSearch' ) ;
339
410
}
340
- )
341
- // 07. Assert that the command returns the name of the index: `"test-search-index-case7-explicit"`.
342
- expect ( indexName ) . to . equal ( 'test-search-index-case7-explicit' )
343
- // 08. Run `coll0.listSearchIndexes('test-search-index-case7-explicit')` repeatedly every 5 seconds until the following
344
- // condition is satisfied and store the value in a variable `index2`:
345
-
346
- // - An index with the `name` of `test-search-index-case7-explicit` is present and the index has a field `queryable`
347
- // with a value of `true`.
348
-
349
- const [ index2 ] = await waitForIndexes ( {
350
- predicate : indexes => indexes . every ( index => index . queryable ) ,
351
- indexNames : 'test-search-index-case7-explicit'
352
- } ) ;
353
- // 09. Assert that `index2` has a property `type` whose value is `search`.
354
- expect ( index2 ) . to . have . property ( 'type' , 'search' ) ;
355
411
}
356
- {
357
- // 10. Create a new vector search index on `coll0` with the `createSearchIndex` helper. Use the following definition:
358
- // ```typescript
359
- // {
360
- // name: 'test-search-index-case7-vector',
361
- // type: 'vectorSearch',
362
- // definition: {
363
- // "fields": [
364
- // {
365
- // "type": "vector",
366
- // "path": "plot_embedding",
367
- // "numDimensions": 1536,
368
- // "similarity": "euclidean",
369
- // },
370
- // ]
371
- // }
372
- // }
373
- // ```
412
+ ) ;
374
413
375
- const indexName = await coll0 . createSearchIndex ( {
376
- name : 'test-search-index-case7-vector' ,
377
- type : 'vectorSearch' ,
378
- definition : {
379
- "fields" : [
380
- {
381
- "type" : "vector" ,
382
- "path" : "plot_embedding" ,
383
- "numDimensions" : 1536 ,
384
- "similarity" : "euclidean" ,
385
- } ,
386
- ]
387
- }
414
+ it ( 'Case 8: Driver requires explicit type to create a vector search index' , async function ( ) {
415
+ // 1. Create a collection with the "create" command using a randomly generated name (referred to as `coll0`).
416
+ const coll0 = collection ;
417
+
418
+ // 2. Create a new vector search index on `coll0` with the `createSearchIndex` helper. Use the following definition:
419
+ // {
420
+ // name: 'test-search-index-case8-error',
421
+ // definition: {
422
+ // fields: [
423
+ // {
424
+ // type: 'vector',
425
+ // path: 'plot_embedding',
426
+ // numDimensions: 1536,
427
+ // similarity: 'euclidean',
428
+ // },
429
+ // ]
430
+ // }
431
+ // }
432
+ const definition = {
433
+ name : 'test-search-index-case8-error' ,
434
+ definition : {
435
+ fields : [
436
+ {
437
+ type : 'vector' ,
438
+ path : 'plot_embedding' ,
439
+ numDimensions : 1536 ,
440
+ similarity : 'euclidean'
441
+ }
442
+ ]
388
443
}
389
- )
390
- // 11. Assert that the command returns the name of the index: `"test-search-index-case7-vector"`.
391
- expect ( indexName ) . to . equal ( "test-search-index-case7-vector" ) ;
392
- // 12. Run `coll0.listSearchIndexes('test-search-index-case7-vector')` repeatedly every 5 seconds until the following
393
- // condition is satisfied and store the value in a variable `index3`:
394
- // - An index with the `name` of `test-search-index-case7-vector` is present and the index has a field `queryable` with
395
- // a value of `true`.
396
- const [ index3 ] = await waitForIndexes ( {
397
- predicate : indexes => indexes . every ( index => index . queryable ) ,
398
- indexNames : 'test-search-index-case7-vector'
399
- } ) ;
444
+ } ;
445
+ const error = await coll0 . createSearchIndex ( definition ) . catch ( e => e ) ;
400
446
401
- // 13. Assert that `index3` has a property `type` whose value is `vectorSearch`.
402
- expect ( index3 ) . to . have . property ( 'type' , 'vectorSearch' ) ;
403
- }
404
- {
405
- // 14. Create a new vector search index on `coll0` with the `createSearchIndex` helper. Use the following definition:
406
- // ```typescript
407
- // {
408
- // name: 'test-search-index-case7-error',
409
- // definition: {
410
- // "fields": [
411
- // {
412
- // "type": "vector",
413
- // "path": "plot_embedding",
414
- // "numDimensions": 1536,
415
- // "similarity": "euclidean",
416
- // },
417
- // ]
418
- // }
419
- // }
420
- // ```
421
- const error = await coll0 . createSearchIndex ( {
422
- name : 'test-search-index-case7-error' ,
423
- definition : {
424
- "fields" : [
425
- {
426
- "type" : "vector" ,
427
- "path" : "plot_embedding" ,
428
- "numDimensions" : 1536 ,
429
- "similarity" : "euclidean" ,
430
- } ,
431
- ]
432
- }
433
- } ) . catch ( e => e )
434
- // 15. Assert that the command throws an exception due to the `mappings` field missing.
435
- expect ( error ) . to . be . instanceOf ( MongoServerError ) . to . match ( / m a p p i n g s / i) ;
436
- }
437
- } )
447
+ // 3. Assert that the command throws an exception containing the string "Attribute mappings missing" due to the `mappings`
448
+ // field missing.
449
+ expect ( error ) . to . match ( / A t t r i b u t e m a p p i n g s m i s s i n g / i) ;
450
+ } ) ;
438
451
} ) ;
439
452
} ) ;
0 commit comments