@@ -83,35 +83,32 @@ describe('Collection', function () {
83
83
db . createCollection ( 'test.spiderman' , ( ) => {
84
84
db . createCollection ( 'test.mario' , ( ) => {
85
85
// Insert test documents (creates collections)
86
- db . collection ( 'test.spiderman' , ( err , spiderman_collection ) => {
87
- spiderman_collection . insertOne ( { foo : 5 } , configuration . writeConcernMax ( ) , err => {
86
+ const spiderman_collection = db . collection ( 'test.spiderman' ) ;
87
+ spiderman_collection . insertOne ( { foo : 5 } , configuration . writeConcernMax ( ) , err => {
88
+ expect ( err ) . to . not . exist ;
89
+ const mario_collection = db . collection ( 'test.mario' ) ;
90
+ mario_collection . insertOne ( { bar : 0 } , configuration . writeConcernMax ( ) , err => {
88
91
expect ( err ) . to . not . exist ;
89
- db . collection ( 'test.mario' , ( err , mario_collection ) => {
90
- mario_collection . insertOne ( { bar : 0 } , configuration . writeConcernMax ( ) , err => {
91
- expect ( err ) . to . not . exist ;
92
- // Assert collections
93
- db . collections ( ( err , collections ) => {
94
- expect ( err ) . to . not . exist ;
92
+ // Assert collections
93
+ db . collections ( ( err , collections ) => {
94
+ expect ( err ) . to . not . exist ;
95
95
96
- let found_spiderman = false ;
97
- let found_mario = false ;
98
- let found_does_not_exist = false ;
99
-
100
- collections . forEach ( collection => {
101
- if ( collection . collectionName === 'test.spiderman' ) {
102
- found_spiderman = true ;
103
- }
104
- if ( collection . collectionName === 'test.mario' ) found_mario = true ;
105
- if ( collection . collectionName === 'does_not_exist' )
106
- found_does_not_exist = true ;
107
- } ) ;
96
+ let found_spiderman = false ;
97
+ let found_mario = false ;
98
+ let found_does_not_exist = false ;
108
99
109
- expect ( found_spiderman ) . to . be . true ;
110
- expect ( found_mario ) . to . be . true ;
111
- expect ( found_does_not_exist ) . to . be . false ;
112
- done ( ) ;
113
- } ) ;
100
+ collections . forEach ( collection => {
101
+ if ( collection . collectionName === 'test.spiderman' ) {
102
+ found_spiderman = true ;
103
+ }
104
+ if ( collection . collectionName === 'test.mario' ) found_mario = true ;
105
+ if ( collection . collectionName === 'does_not_exist' ) found_does_not_exist = true ;
114
106
} ) ;
107
+
108
+ expect ( found_spiderman ) . to . be . true ;
109
+ expect ( found_mario ) . to . be . true ;
110
+ expect ( found_does_not_exist ) . to . be . false ;
111
+ done ( ) ;
115
112
} ) ;
116
113
} ) ;
117
114
} ) ;
@@ -166,23 +163,6 @@ describe('Collection', function () {
166
163
} ) ;
167
164
} ) ;
168
165
169
- it ( 'should ensure strict access collection' , function ( done ) {
170
- db . collection ( 'does-not-exist' , { strict : true } , err => {
171
- expect ( err ) . to . be . an . instanceof ( Error ) ;
172
- expect ( err . message ) . to . equal (
173
- 'Collection does-not-exist does not exist. Currently in strict mode.'
174
- ) ;
175
- db . createCollection ( 'test_strict_access_collection' , err => {
176
- expect ( err ) . to . not . exist ;
177
- db . collection ( 'test_strict_access_collection' , configuration . writeConcernMax ( ) , err => {
178
- expect ( err ) . to . not . exist ;
179
- // Let's close the db
180
- done ( ) ;
181
- } ) ;
182
- } ) ;
183
- } ) ;
184
- } ) ;
185
-
186
166
it ( 'should fail to insert due to illegal keys' , function ( done ) {
187
167
db . createCollection ( 'test_invalid_key_names' , ( err , collection ) => {
188
168
// Legal inserts
@@ -280,39 +260,25 @@ describe('Collection', function () {
280
260
} ) ;
281
261
282
262
it ( 'should fail due to illegal listCollections' , function ( done ) {
283
- db . collection ( 5 , err => {
284
- expect ( err . message ) . to . equal ( 'collection name must be a String' ) ;
285
- } ) ;
286
-
287
- db . collection ( '' , err => {
288
- expect ( err . message ) . to . equal ( 'collection names cannot be empty' ) ;
289
- } ) ;
290
-
291
- db . collection ( 'te$t' , err => {
292
- expect ( err . message ) . to . equal ( "collection names must not contain '$'" ) ;
293
- } ) ;
294
-
295
- db . collection ( '.test' , err => {
296
- expect ( err . message ) . to . equal ( "collection names must not start or end with '.'" ) ;
297
- } ) ;
298
-
299
- db . collection ( 'test.' , err => {
300
- expect ( err . message ) . to . equal ( "collection names must not start or end with '.'" ) ;
301
- } ) ;
302
-
303
- db . collection ( 'test..t' , err => {
304
- expect ( err . message ) . to . equal ( 'collection names cannot be empty' ) ;
305
- done ( ) ;
306
- } ) ;
263
+ expect ( ( ) => db . collection ( 5 ) ) . to . throw ( 'collection name must be a String' ) ;
264
+ expect ( ( ) => db . collection ( '' ) ) . to . throw ( 'collection names cannot be empty' ) ;
265
+ expect ( ( ) => db . collection ( 'te$t' ) ) . to . throw ( "collection names must not contain '$'" ) ;
266
+ expect ( ( ) => db . collection ( '.test' ) ) . to . throw (
267
+ "collection names must not start or end with '.'"
268
+ ) ;
269
+ expect ( ( ) => db . collection ( 'test.' ) ) . to . throw (
270
+ "collection names must not start or end with '.'"
271
+ ) ;
272
+ expect ( ( ) => db . collection ( 'test..t' ) ) . to . throw ( 'collection names cannot be empty' ) ;
273
+ done ( ) ;
307
274
} ) ;
308
275
309
276
it ( 'should correctly count on non-existent collection' , function ( done ) {
310
- db . collection ( 'test_multiple_insert_2' , ( err , collection ) => {
311
- collection . countDocuments ( ( err , count ) => {
312
- expect ( count ) . to . equal ( 0 ) ;
313
- // Let's close the db
314
- done ( ) ;
315
- } ) ;
277
+ const collection = db . collection ( 'test_multiple_insert_2' ) ;
278
+ collection . countDocuments ( ( err , count ) => {
279
+ expect ( count ) . to . equal ( 0 ) ;
280
+ // Let's close the db
281
+ done ( ) ;
316
282
} ) ;
317
283
} ) ;
318
284
@@ -351,22 +317,20 @@ describe('Collection', function () {
351
317
} ) ;
352
318
353
319
it ( 'should perform collection remove with no callback' , function ( done ) {
354
- db . collection ( 'remove_with_no_callback_bug_test' , ( err , collection ) => {
320
+ const collection = db . collection ( 'remove_with_no_callback_bug_test' ) ;
321
+ collection . insertOne ( { a : 1 } , configuration . writeConcernMax ( ) , err => {
355
322
expect ( err ) . to . not . exist ;
356
- collection . insertOne ( { a : 1 } , configuration . writeConcernMax ( ) , err => {
323
+ collection . insertOne ( { b : 1 } , configuration . writeConcernMax ( ) , err => {
357
324
expect ( err ) . to . not . exist ;
358
- collection . insertOne ( { b : 1 } , configuration . writeConcernMax ( ) , err => {
325
+ collection . insertOne ( { c : 1 } , configuration . writeConcernMax ( ) , err => {
359
326
expect ( err ) . to . not . exist ;
360
- collection . insertOne ( { c : 1 } , configuration . writeConcernMax ( ) , err => {
327
+ collection . remove ( { a : 1 } , configuration . writeConcernMax ( ) , err => {
361
328
expect ( err ) . to . not . exist ;
362
- collection . remove ( { a : 1 } , configuration . writeConcernMax ( ) , err => {
329
+ // Let's perform a count
330
+ collection . countDocuments ( ( err , count ) => {
363
331
expect ( err ) . to . not . exist ;
364
- // Let's perform a count
365
- collection . countDocuments ( ( err , count ) => {
366
- expect ( err ) . to . not . exist ;
367
- expect ( count ) . to . equal ( 2 ) ;
368
- done ( ) ;
369
- } ) ;
332
+ expect ( count ) . to . equal ( 2 ) ;
333
+ done ( ) ;
370
334
} ) ;
371
335
} ) ;
372
336
} ) ;
0 commit comments