1
+ import type { DropDatabaseResult } from './cli-service-provider' ;
1
2
import CliServiceProvider from './cli-service-provider' ;
2
3
import CompassServiceProvider from './compass/compass-service-provider' ;
3
4
import { expect } from 'chai' ;
4
5
import { EventEmitter } from 'events' ;
5
6
import { MongoClient } from 'mongodb' ;
6
- import type { Db } from 'mongodb' ;
7
+ import type {
8
+ AggregationCursor ,
9
+ BulkWriteResult ,
10
+ Db ,
11
+ DeleteResult ,
12
+ Document ,
13
+ FindCursor ,
14
+ InsertManyResult ,
15
+ InsertOneResult ,
16
+ UpdateResult ,
17
+ } from 'mongodb' ;
7
18
import {
8
19
skipIfServerVersion ,
9
20
startSharedTestServer ,
@@ -157,7 +168,7 @@ describe('CliServiceProvider [integration]', function () {
157
168
'topology' ,
158
169
'extraInfo' ,
159
170
] ) ;
160
- expect ( connectionInfo . buildInfo . version . length > 1 ) ;
171
+ expect ( connectionInfo . buildInfo ? .version . length ) . to . be . greaterThan ( 1 ) ;
161
172
} ) ;
162
173
} ) ;
163
174
@@ -171,7 +182,7 @@ describe('CliServiceProvider [integration]', function () {
171
182
'topology' ,
172
183
'extraInfo' ,
173
184
] ) ;
174
- expect ( connectionInfo . buildInfo . version . length > 1 ) ;
185
+ expect ( connectionInfo . buildInfo ? .version . length ) . to . be . greaterThan ( 1 ) ;
175
186
} ) ;
176
187
} ) ;
177
188
} ) ;
@@ -182,15 +193,15 @@ describe('CliServiceProvider [integration]', function () {
182
193
function ( ) {
183
194
skipIfServerVersion ( testServer , '< 4.4' ) ;
184
195
185
- let result ;
196
+ let result : AggregationCursor ;
186
197
187
198
beforeEach ( function ( ) {
188
199
const pipeline = [
189
200
{
190
201
$addFields : {
191
202
'attr.namespace' : {
192
203
$function : {
193
- body : function ( value ) : any {
204
+ body : function ( value : any ) : any {
194
205
if ( value ) {
195
206
return value ;
196
207
}
@@ -213,7 +224,7 @@ describe('CliServiceProvider [integration]', function () {
213
224
) ;
214
225
215
226
context ( 'when running against a collection' , function ( ) {
216
- let result ;
227
+ let result : AggregationCursor ;
217
228
218
229
beforeEach ( function ( ) {
219
230
result = serviceProvider . aggregate ( 'music' , 'bands' , [
@@ -228,7 +239,7 @@ describe('CliServiceProvider [integration]', function () {
228
239
} ) ;
229
240
230
241
context ( 'when running against a database' , function ( ) {
231
- let result ;
242
+ let result : AggregationCursor ;
232
243
233
244
beforeEach ( function ( ) {
234
245
result = serviceProvider . aggregateDb ( 'admin' , [ { $currentOp : { } } ] ) ;
@@ -243,7 +254,7 @@ describe('CliServiceProvider [integration]', function () {
243
254
244
255
describe ( '#bulkWrite' , function ( ) {
245
256
context ( 'when the filter is empty' , function ( ) {
246
- let result ;
257
+ let result : BulkWriteResult ;
247
258
const requests = [
248
259
{
249
260
insertOne : { name : 'Aphex Twin' } ,
@@ -259,14 +270,14 @@ describe('CliServiceProvider [integration]', function () {
259
270
} ) ;
260
271
261
272
it ( 'executes the count with an empty filter and resolves the result' , function ( ) {
262
- expect ( result . result . nInserted ) . to . equal ( 1 ) ;
273
+ expect ( ( result as any ) . result . nInserted ) . to . equal ( 1 ) ;
263
274
} ) ;
264
275
} ) ;
265
276
} ) ;
266
277
267
278
describe ( '#count' , function ( ) {
268
279
context ( 'when the filter is empty' , function ( ) {
269
- let result ;
280
+ let result : number ;
270
281
271
282
beforeEach ( async function ( ) {
272
283
result = await serviceProvider . count ( 'music' , 'bands' ) ;
@@ -280,7 +291,7 @@ describe('CliServiceProvider [integration]', function () {
280
291
281
292
describe ( '#countDocuments' , function ( ) {
282
293
context ( 'when the filter is empty' , function ( ) {
283
- let result ;
294
+ let result : number ;
284
295
285
296
beforeEach ( async function ( ) {
286
297
result = await serviceProvider . countDocuments ( 'music' , 'bands' ) ;
@@ -294,7 +305,7 @@ describe('CliServiceProvider [integration]', function () {
294
305
295
306
describe ( '#deleteMany' , function ( ) {
296
307
context ( 'when the filter is empty' , function ( ) {
297
- let result ;
308
+ let result : DeleteResult ;
298
309
299
310
beforeEach ( async function ( ) {
300
311
result = await serviceProvider . deleteMany ( 'music' , 'bands' , { } ) ;
@@ -308,7 +319,7 @@ describe('CliServiceProvider [integration]', function () {
308
319
309
320
describe ( '#deleteOne' , function ( ) {
310
321
context ( 'when the filter is empty' , function ( ) {
311
- let result ;
322
+ let result : DeleteResult ;
312
323
313
324
beforeEach ( async function ( ) {
314
325
result = await serviceProvider . deleteOne ( 'music' , 'bands' , { } ) ;
@@ -322,7 +333,7 @@ describe('CliServiceProvider [integration]', function () {
322
333
323
334
describe ( '#distinct' , function ( ) {
324
335
context ( 'when the distinct is valid' , function ( ) {
325
- let result ;
336
+ let result : Document [ ] ;
326
337
327
338
beforeEach ( async function ( ) {
328
339
result = await serviceProvider . distinct ( 'music' , 'bands' , 'name' ) ;
@@ -336,7 +347,7 @@ describe('CliServiceProvider [integration]', function () {
336
347
337
348
describe ( '#estimatedDocumentCount' , function ( ) {
338
349
context ( 'when no options are provided' , function ( ) {
339
- let result ;
350
+ let result : number ;
340
351
341
352
beforeEach ( async function ( ) {
342
353
result = await serviceProvider . estimatedDocumentCount ( 'music' , 'bands' ) ;
@@ -350,7 +361,7 @@ describe('CliServiceProvider [integration]', function () {
350
361
351
362
describe ( '#find' , function ( ) {
352
363
context ( 'when the find is valid' , function ( ) {
353
- let result ;
364
+ let result : FindCursor ;
354
365
355
366
beforeEach ( function ( ) {
356
367
result = serviceProvider . find ( 'music' , 'bands' , { name : 'Aphex Twin' } ) ;
@@ -365,7 +376,7 @@ describe('CliServiceProvider [integration]', function () {
365
376
366
377
describe ( '#findOneAndDelete' , function ( ) {
367
378
context ( 'when the find is valid' , function ( ) {
368
- let result ;
379
+ let result : Document | null ;
369
380
const filter = { name : 'Aphex Twin' } ;
370
381
371
382
beforeEach ( async function ( ) {
@@ -377,14 +388,14 @@ describe('CliServiceProvider [integration]', function () {
377
388
} ) ;
378
389
379
390
it ( 'executes the command and resolves the result' , function ( ) {
380
- expect ( result . ok ) . to . equal ( 1 ) ;
391
+ expect ( result ? .ok ) . to . equal ( 1 ) ;
381
392
} ) ;
382
393
} ) ;
383
394
} ) ;
384
395
385
396
describe ( '#findOneAndReplace' , function ( ) {
386
397
context ( 'when the find is valid' , function ( ) {
387
- let result ;
398
+ let result : Document ;
388
399
const filter = { name : 'Aphex Twin' } ;
389
400
const replacement = { name : 'Richard James' } ;
390
401
@@ -405,7 +416,7 @@ describe('CliServiceProvider [integration]', function () {
405
416
406
417
describe ( '#findOneAndUpdate' , function ( ) {
407
418
context ( 'when the find is valid' , function ( ) {
408
- let result ;
419
+ let result : Document ;
409
420
const filter = { name : 'Aphex Twin' } ;
410
421
const update = { $set : { name : 'Richard James' } } ;
411
422
@@ -426,7 +437,7 @@ describe('CliServiceProvider [integration]', function () {
426
437
427
438
describe ( '#insertMany' , function ( ) {
428
439
context ( 'when the insert is valid' , function ( ) {
429
- let result ;
440
+ let result : InsertManyResult ;
430
441
431
442
beforeEach ( async function ( ) {
432
443
result = await serviceProvider . insertMany ( 'music' , 'bands' , [
@@ -446,7 +457,7 @@ describe('CliServiceProvider [integration]', function () {
446
457
447
458
describe ( '#insertOne' , function ( ) {
448
459
context ( 'when the insert is valid' , function ( ) {
449
- let result ;
460
+ let result : InsertOneResult ;
450
461
451
462
beforeEach ( async function ( ) {
452
463
result = await serviceProvider . insertOne ( 'music' , 'bands' , {
@@ -465,15 +476,17 @@ describe('CliServiceProvider [integration]', function () {
465
476
} ) ;
466
477
467
478
describe ( '#listDatabases' , function ( ) {
468
- let result ;
479
+ let result : Document ;
469
480
470
481
beforeEach ( async function ( ) {
471
482
result = await serviceProvider . listDatabases ( 'admin' ) ;
472
483
} ) ;
473
484
474
485
it ( 'returns a list of databases' , function ( ) {
475
486
expect ( result . ok ) . to . equal ( 1 ) ;
476
- expect ( result . databases . map ( ( db ) => db . name ) ) . to . include ( 'admin' ) ;
487
+ expect (
488
+ result . databases . map ( ( db : { name : string } ) => db . name )
489
+ ) . to . include ( 'admin' ) ;
477
490
} ) ;
478
491
} ) ;
479
492
@@ -482,7 +495,7 @@ describe('CliServiceProvider [integration]', function () {
482
495
const replacement = { name : 'Richard James' } ;
483
496
484
497
context ( 'when the filter is empty' , function ( ) {
485
- let result ;
498
+ let result : UpdateResult ;
486
499
487
500
beforeEach ( async function ( ) {
488
501
result = await serviceProvider . replaceOne (
@@ -501,7 +514,7 @@ describe('CliServiceProvider [integration]', function () {
501
514
502
515
describe ( '#runCommand' , function ( ) {
503
516
context ( 'when the command is valid' , function ( ) {
504
- let result ;
517
+ let result : Document ;
505
518
506
519
beforeEach ( async function ( ) {
507
520
result = await serviceProvider . runCommand ( 'admin' , { ismaster : true } ) ;
@@ -517,7 +530,7 @@ describe('CliServiceProvider [integration]', function () {
517
530
const filter = { name : 'Aphex Twin' } ;
518
531
const update = { $set : { name : 'Richard James' } } ;
519
532
context ( 'when the filter is empty' , function ( ) {
520
- let result ;
533
+ let result : UpdateResult ;
521
534
522
535
beforeEach ( async function ( ) {
523
536
result = await serviceProvider . updateMany (
@@ -538,7 +551,7 @@ describe('CliServiceProvider [integration]', function () {
538
551
const filter = { name : 'Aphex Twin' } ;
539
552
const update = { $set : { name : 'Richard James' } } ;
540
553
context ( 'when the filter is empty' , function ( ) {
541
- let result ;
554
+ let result : UpdateResult ;
542
555
543
556
beforeEach ( async function ( ) {
544
557
result = await serviceProvider . updateOne (
@@ -570,7 +583,7 @@ describe('CliServiceProvider [integration]', function () {
570
583
571
584
describe ( '#dropDatabase' , function ( ) {
572
585
context ( 'when a database does not exist' , function ( ) {
573
- let result ;
586
+ let result : DropDatabaseResult ;
574
587
575
588
it ( 'returns {ok: 1}' , async function ( ) {
576
589
result = await serviceProvider . dropDatabase ( `test-db-${ Date . now ( ) } ` ) ;
@@ -579,7 +592,7 @@ describe('CliServiceProvider [integration]', function () {
579
592
} ) ;
580
593
581
594
context ( 'when a database exists' , function ( ) {
582
- let result ;
595
+ let result : DropDatabaseResult ;
583
596
584
597
const dbExists = async ( ) : Promise < boolean > => {
585
598
return ( await db . admin ( ) . listDatabases ( ) ) . databases
@@ -734,7 +747,7 @@ describe('CliServiceProvider [integration]', function () {
734
747
( collection ) => collection . name === 'coll1'
735
748
) ;
736
749
expect ( matchingCollection ) . to . not . be . undefined ;
737
- expect ( matchingCollection . options ) . to . deep . contain ( {
750
+ expect ( matchingCollection ? .options ) . to . deep . contain ( {
738
751
clusteredIndex : {
739
752
v : 2 ,
740
753
key : { _id : 1 } ,
@@ -792,7 +805,7 @@ describe('CliServiceProvider [integration]', function () {
792
805
793
806
describe ( '#driverMetadata' , function ( ) {
794
807
it ( 'returns information about the driver instance' , function ( ) {
795
- expect ( serviceProvider . driverMetadata . driver . name ) . to . equal ( 'nodejs' ) ;
808
+ expect ( serviceProvider . driverMetadata ? .driver . name ) . to . equal ( 'nodejs' ) ;
796
809
} ) ;
797
810
} ) ;
798
811
0 commit comments