11import { expect } from 'chai' ;
22
3- import { type MongoClient } from '../../mongodb ' ;
3+ import { type MongoClient } from '../../../src ' ;
44
55describe ( 'Remove' , function ( ) {
66 let client : MongoClient ;
@@ -13,123 +13,44 @@ describe('Remove', function () {
1313 await client . close ( ) ;
1414 } ) ;
1515
16- it ( 'should correctly clear out collection' , {
17- metadata : {
18- requires : { topology : [ 'single' , 'replicaset' , 'sharded' , 'ssl' , 'heap' , 'wiredtiger' ] }
19- } ,
16+ it ( 'should correctly clear out collection' , async function ( ) {
17+ const db = client . db ( ) ;
2018
21- test : function ( done ) {
22- const db = client . db ( ) ;
19+ const collection = await db . createCollection ( 'test_clear' ) ;
2320
24- db . createCollection ( 'test_clear' , function ( err ) {
25- expect ( err ) . to . not . exist ;
21+ await collection . insertOne ( { i : 1 } , { writeConcern : { w : 1 } } ) ;
2622
27- const collection = db . collection ( 'test_clear' ) ;
23+ await collection . insertOne ( { i : 2 } , { writeConcern : { w : 1 } } ) ;
24+ const count = await collection . countDocuments ( ) ;
25+ expect ( count ) . to . equal ( 2 ) ;
2826
29- collection . insert ( { i : 1 } , { writeConcern : { w : 1 } } , function ( err ) {
30- expect ( err ) . to . not . exist ;
27+ // Clear the collection
28+ const r = await collection . deleteMany ( { } , { writeConcern : { w : 1 } } ) ;
29+ expect ( r ) . property ( 'deletedCount' ) . to . equal ( 2 ) ;
3130
32- collection . insert ( { i : 2 } , { writeConcern : { w : 1 } } , function ( err ) {
33- expect ( err ) . to . not . exist ;
31+ const c = await collection . countDocuments ( ) ;
32+ expect ( c ) . to . equal ( 0 ) ;
33+ } ) ;
3434
35- collection . count ( function ( err , count ) {
36- expect ( err ) . to . not . exist ;
37- expect ( count ) . to . equal ( 2 ) ;
35+ it ( 'should correctly remove document using RegExp' , async function ( ) {
36+ const db = client . db ( this . configuration . db ) ;
3837
39- // Clear the collection
40- collection . deleteMany ( { } , { writeConcern : { w : 1 } } , function ( err , r ) {
41- expect ( err ) . to . not . exist ;
42- expect ( r ) . property ( 'deletedCount' ) . to . equal ( 2 ) ;
38+ const collection = await db . createCollection ( 'test_remove_regexp' ) ;
4339
44- collection . count ( function ( err , count ) {
45- expect ( err ) . to . not . exist ;
46- expect ( count ) . to . equal ( 0 ) ;
40+ await collection . insertOne ( { address : '485 7th ave new york' } , { writeConcern : { w : 1 } } ) ;
4741
48- // Let's close the db
49- client . close ( done ) ;
50- } ) ;
51- } ) ;
52- } ) ;
53- } ) ;
54- } ) ;
55- } ) ;
56- }
57- } ) ;
42+ // Clear the collection
43+ const r = await collection . deleteMany ( { address : / 4 8 5 7 t h a v e / } , { writeConcern : { w : 1 } } ) ;
44+ expect ( r ) . property ( 'deletedCount' ) . to . equal ( 1 ) ;
5845
59- it ( 'should correctly remove document using RegExp' , {
60- metadata : {
61- requires : { topology : [ 'single' , 'replicaset' , 'sharded' , 'ssl' , 'heap' , 'wiredtiger' ] }
62- } ,
63-
64- test : function ( done ) {
65- const self = this ;
66- const client = self . configuration . newClient ( self . configuration . writeConcernMax ( ) , {
67- maxPoolSize : 1
68- } ) ;
69-
70- client . connect ( function ( err , client ) {
71- const db = client . db ( self . configuration . db ) ;
72- expect ( err ) . to . not . exist ;
73-
74- db . createCollection ( 'test_remove_regexp' , function ( err ) {
75- expect ( err ) . to . not . exist ;
76-
77- const collection = db . collection ( 'test_remove_regexp' ) ;
78-
79- collection . insert (
80- { address : '485 7th ave new york' } ,
81- { writeConcern : { w : 1 } } ,
82- function ( err ) {
83- expect ( err ) . to . not . exist ;
84-
85- // Clear the collection
86- collection . deleteMany (
87- { address : / 4 8 5 7 t h a v e / } ,
88- { writeConcern : { w : 1 } } ,
89- function ( err , r ) {
90- expect ( r ) . property ( 'deletedCount' ) . to . equal ( 1 ) ;
91-
92- collection . count ( function ( err , count ) {
93- expect ( err ) . to . not . exist ;
94- expect ( count ) . to . equal ( 0 ) ;
95-
96- // Let's close the db
97- client . close ( done ) ;
98- } ) ;
99- }
100- ) ;
101- }
102- ) ;
103- } ) ;
104- } ) ;
105- }
46+ const count = await collection . countDocuments ( ) ;
47+ expect ( count ) . to . equal ( 0 ) ;
10648 } ) ;
10749
108- it ( 'should not error on empty remove' , {
109- metadata : {
110- requires : { topology : [ 'single' , 'replicaset' , 'sharded' , 'ssl' , 'heap' , 'wiredtiger' ] }
111- } ,
112-
113- test : function ( done ) {
114- const self = this ;
115- const client = self . configuration . newClient ( self . configuration . writeConcernMax ( ) , {
116- maxPoolSize : 1
117- } ) ;
118-
119- client . connect ( function ( err , client ) {
120- const db = client . db ( self . configuration . db ) ;
121- expect ( err ) . to . not . exist ;
122- const collection = db . collection ( 'remove_test' ) ;
123-
124- collection . deleteMany ( { } ) . then (
125- ( ) => {
126- client . close ( done ) ;
127- } ,
128- err => {
129- client . close ( err2 => done ( err || err2 ) ) ;
130- }
131- ) ;
132- } ) ;
133- }
50+ it ( 'should not throw error on empty remove' , async function ( ) {
51+ const db = client . db ( this . configuration . db ) ;
52+ const collection = db . collection ( 'remove_test' ) ;
53+
54+ await collection . deleteMany ( { } ) ;
13455 } ) ;
13556} ) ;
0 commit comments