@@ -38,24 +38,23 @@ describe('Index Management Prose Tests', function () {
38
38
let timeoutController : TimeoutController ;
39
39
let collection : Collection ;
40
40
41
- /** creates a readable stream that emits every \<interval\> ms */
42
- const interval = ( interval : number , signal : AbortSignal ) =>
43
- Readable . from ( setInterval ( interval , undefined , { signal, ref : false } ) ) ;
44
-
45
41
/**
46
42
* waits until the search indexes for `collection` satisfy `predicate`, optionally pre-filtering
47
43
* for indexes with name = `indexName`
48
44
*/
49
- const waitForIndexes = ( {
45
+ function waitForIndexes ( {
50
46
predicate,
51
47
indexName
52
48
} : {
53
49
predicate : ( arg0 : Array < Document > ) => boolean ;
54
50
indexName ?: string ;
55
- } ) : Promise < Array < Document > > =>
56
- interval ( 5000 , timeoutController . signal )
51
+ } ) : Promise < Array < Document > > {
52
+ return Readable . from (
53
+ setInterval ( 5000 , undefined , { signal : timeoutController . signal , ref : false } )
54
+ )
57
55
. map ( ( ) => collection . listSearchIndexes ( indexName ) . toArray ( ) )
58
56
. find ( predicate ) ;
57
+ }
59
58
60
59
before ( function ( ) {
61
60
this . configuration = this . configuration . makeAtlasTestConfiguration ( ) ;
@@ -87,13 +86,15 @@ describe('Index Management Prose Tests', function () {
87
86
'Case 1: Driver can successfully create and list search indexes' ,
88
87
metadata ,
89
88
async function ( ) {
90
- await collection . createSearchIndex ( {
89
+ const name = await collection . createSearchIndex ( {
91
90
name : 'test-search-index' ,
92
91
definition : {
93
92
mappings : { dynamic : false }
94
93
}
95
94
} ) ;
96
95
96
+ expect ( name ) . to . equal ( 'test-search-index' ) ;
97
+
97
98
const [ index ] = await waitForIndexes ( {
98
99
predicate : indexes => indexes . every ( index => index . queryable ) ,
99
100
indexName : 'test-search-index'
@@ -125,7 +126,8 @@ describe('Index Management Prose Tests', function () {
125
126
}
126
127
] ;
127
128
128
- await collection . createSearchIndexes ( indexDefinitions ) ;
129
+ const names = await collection . createSearchIndexes ( indexDefinitions ) ;
130
+ expect ( names ) . to . deep . equal ( [ 'test-search-index-1' , 'test-search-index-2' ] ) ;
129
131
130
132
const indexes = await waitForIndexes ( {
131
133
predicate : indexes => indexes . every ( index => index . queryable )
@@ -143,13 +145,15 @@ describe('Index Management Prose Tests', function () {
143
145
) ;
144
146
145
147
it ( 'Case 3: Driver can successfully drop search indexes' , metadata , async function ( ) {
146
- await collection . createSearchIndex ( {
148
+ const name = await collection . createSearchIndex ( {
147
149
name : 'test-search-index' ,
148
150
definition : {
149
151
mappings : { dynamic : false }
150
152
}
151
153
} ) ;
152
154
155
+ expect ( name ) . to . equal ( 'test-search-index' ) ;
156
+
153
157
await waitForIndexes ( {
154
158
predicate : indexes => indexes . every ( index => index . queryable ) ,
155
159
indexName : 'test-search-index'
@@ -166,13 +170,15 @@ describe('Index Management Prose Tests', function () {
166
170
} ) ;
167
171
168
172
it ( 'Case 4: Driver can update a search index' , metadata , async function ( ) {
169
- await collection . createSearchIndex ( {
173
+ const name = await collection . createSearchIndex ( {
170
174
name : 'test-search-index' ,
171
175
definition : {
172
176
mappings : { dynamic : false }
173
177
}
174
178
} ) ;
175
179
180
+ expect ( name ) . to . equal ( 'test-search-index' ) ;
181
+
176
182
await waitForIndexes ( {
177
183
predicate : indexes => indexes . every ( index => index . queryable ) ,
178
184
indexName : 'test-search-index'
0 commit comments