@@ -387,34 +387,34 @@ describe.only('CRUD API', function () {
387
387
} ) ;
388
388
389
389
describe ( 'should correctly execute insert methods using crud api' , function ( ) {
390
- let db : Db ;
391
-
392
- before ( function ( ) {
393
- db = client . db ( ) ;
394
- } ) ;
395
-
396
390
it ( '#insertMany()' , async function ( ) {
391
+ const db = client . db ( ) ;
397
392
const r = await db . collection ( 't2_1' ) . insertMany ( [ { a : 1 } , { a : 2 } ] ) ;
398
393
expect ( r ) . property ( 'insertedCount' ) . to . equal ( 2 ) ;
399
394
} ) ;
395
+
400
396
it ( 'bulk inserts' , async function ( ) {
397
+ await client . connect ( ) ;
398
+ const db = client . db ( ) ;
401
399
const bulk = db . collection ( 't2_2' ) . initializeOrderedBulkOp ( ) ;
402
400
bulk . insert ( { a : 1 } ) ;
403
401
bulk . insert ( { a : 1 } ) ;
404
402
await bulk . execute ( ) ;
405
403
} ) ;
406
404
407
405
it ( '#insertOne()' , async function ( ) {
406
+ const db = client . db ( ) ;
408
407
const r = await db . collection ( 't2_3' ) . insertOne ( { a : 1 } , { writeConcern : { w : 1 } } ) ;
409
408
expect ( r ) . property ( 'insertedId' ) . to . exist ;
410
409
} ) ;
411
410
412
411
it ( 'bulk write unordered' , async function ( ) {
412
+ const db = client . db ( ) ;
413
413
const i = await db . collection ( 't2_5' ) . insertMany ( [ { c : 1 } ] , { writeConcern : { w : 1 } } ) ;
414
414
expect ( i ) . property ( 'insertedCount' ) . to . equal ( 1 ) ;
415
415
416
416
const r = await db
417
- . collection ( 't2_4 ' )
417
+ . collection ( 't2_5 ' )
418
418
. bulkWrite (
419
419
[
420
420
{ insertOne : { document : { a : 1 } } } ,
@@ -442,11 +442,12 @@ describe.only('CRUD API', function () {
442
442
} ) ;
443
443
444
444
it ( 'bulk write ordered' , async function ( ) {
445
- const i = await db . collection ( 't2_7' ) . insertMany ( [ { c : 1 } ] , { writeConcern : { w : 1 } } ) ;
445
+ const db = client . db ( ) ;
446
+ const i = await db . collection ( 't2_6' ) . insertMany ( [ { c : 1 } ] , { writeConcern : { w : 1 } } ) ;
446
447
expect ( i ) . property ( 'insertedCount' ) . to . equal ( 1 ) ;
447
448
448
449
const r = await db
449
- . collection ( 't2_5 ' )
450
+ . collection ( 't2_6 ' )
450
451
. bulkWrite (
451
452
[
452
453
{ insertOne : { document : { a : 1 } } } ,
@@ -480,13 +481,8 @@ describe.only('CRUD API', function () {
480
481
requires : { topology : [ 'single' , 'replicaset' , 'sharded' ] }
481
482
} ,
482
483
function ( ) {
483
- let db : Db ;
484
-
485
- before ( function ( ) {
486
- db = client . db ( ) ;
487
- } ) ;
488
-
489
484
it ( 'legacy update' , async function ( ) {
485
+ const db = client . db ( ) ;
490
486
const r = await db
491
487
. collection ( 't3_1' )
492
488
// @ts -expect-error Not allowed in TS, but allowed for legacy compat
@@ -495,6 +491,7 @@ describe.only('CRUD API', function () {
495
491
} ) ;
496
492
497
493
it ( '#updateOne()' , async function ( ) {
494
+ const db = client . db ( ) ;
498
495
const i = await db . collection ( 't3_2' ) . insertMany ( [ { c : 1 } ] , { writeConcern : { w : 1 } } ) ;
499
496
expect ( i ) . property ( 'insertedCount' ) . to . equal ( 1 ) ;
500
497
@@ -512,6 +509,7 @@ describe.only('CRUD API', function () {
512
509
} ) ;
513
510
514
511
it ( '#replaceOne()' , async function ( ) {
512
+ const db = client . db ( ) ;
515
513
const r1 = await db . collection ( 't3_3' ) . replaceOne ( { a : 1 } , { a : 2 } , { upsert : true } ) ;
516
514
expect ( r1 ) . property ( 'upsertedCount' ) . to . equal ( 1 ) ;
517
515
test . equal ( 0 , r1 . matchedCount ) ;
@@ -524,6 +522,7 @@ describe.only('CRUD API', function () {
524
522
} ) ;
525
523
526
524
it ( '#updateMany()' , async function ( ) {
525
+ const db = client . db ( ) ;
527
526
const i = await db
528
527
. collection ( 't3_4' )
529
528
. insertMany ( [ { a : 1 } , { a : 1 } ] , { writeConcern : { w : 1 } } ) ;
@@ -889,7 +888,11 @@ describe.only('CRUD API', function () {
889
888
ops . push ( { insertOne : { _id : 0 , a : i } } ) ;
890
889
891
890
const db = client . db ( ) ;
892
- await db . collection ( 't20_1' ) . bulkWrite ( ops , { ordered : true , writeConcern : { w : 1 } } ) ;
891
+ const err = await db
892
+ . collection ( 't20_1' )
893
+ . bulkWrite ( ops , { ordered : true , writeConcern : { w : 1 } } )
894
+ . catch ( err => err ) ;
895
+ test . ok ( err != null ) ;
893
896
}
894
897
} ) ;
895
898
0 commit comments