@@ -3,6 +3,7 @@ var test = require('./shared').assert;
3
3
const { expect } = require ( 'chai' ) ;
4
4
var setupDatabase = require ( './shared' ) . setupDatabase ;
5
5
const { ObjectId } = require ( '../../src' ) ;
6
+ const withClient = require ( './shared' ) . withClient ;
6
7
7
8
describe ( 'Ignore Undefined' , function ( ) {
8
9
before ( function ( ) {
@@ -152,23 +153,23 @@ describe('Ignore Undefined', function () {
152
153
it ( 'Should correctly inherit ignore undefined field from db during insert' , {
153
154
metadata : { requires : { topology : [ 'single' ] } } ,
154
155
155
- test : function ( done ) {
156
+ test : function ( ) {
156
157
var configuration = this . configuration ;
157
158
var client = configuration . newClient ( configuration . writeConcernMax ( ) , {
158
159
poolSize : 1 ,
159
160
ignoreUndefined : false
160
161
} ) ;
161
162
162
- client . connect ( function ( err , client ) {
163
+ return withClient ( client , ( client , done ) => {
163
164
var db = client . db ( configuration . db , { ignoreUndefined : true } ) ;
164
165
var collection = db . collection ( 'shouldCorrectlyIgnoreUndefinedValue3' ) ;
165
166
166
167
// Ignore the undefined field
167
- collection . insert ( { a : 1 , b : undefined } , configuration . writeConcernMax ( ) , function ( err ) {
168
+ collection . insert ( { a : 1 , b : undefined } , configuration . writeConcernMax ( ) , err => {
168
169
expect ( err ) . to . not . exist ;
169
170
170
171
// Locate the doument
171
- collection . findOne ( function ( err , item ) {
172
+ collection . findOne ( ( err , item ) => {
172
173
test . equal ( 1 , item . a ) ;
173
174
test . ok ( item . b === undefined ) ;
174
175
client . close ( done ) ;
@@ -178,134 +179,98 @@ describe('Ignore Undefined', function () {
178
179
}
179
180
} ) ;
180
181
181
- it ( 'Should correctly inherit ignore undefined field from collection during insert' , {
182
- metadata : { requires : { topology : [ 'single' ] } } ,
183
-
184
- test : function ( done ) {
185
- var configuration = this . configuration ;
186
- var client = configuration . newClient ( configuration . writeConcernMax ( ) , {
187
- poolSize : 1
182
+ it (
183
+ 'Should correctly inherit ignore undefined field from collection during insert' ,
184
+ withClient ( function ( client , done ) {
185
+ var db = client . db ( 'shouldCorrectlyIgnoreUndefinedValue4' , { ignoreUndefined : false } ) ;
186
+ var collection = db . collection ( 'shouldCorrectlyIgnoreUndefinedValue4' , {
187
+ ignoreUndefined : true
188
188
} ) ;
189
189
190
- client . connect ( function ( err , client ) {
191
- var db = client . db ( configuration . db , { ignoreUndefined : false } ) ;
192
- var collection = db . collection ( 'shouldCorrectlyIgnoreUndefinedValue4' , {
193
- ignoreUndefined : true
194
- } ) ;
195
-
196
- // Ignore the undefined field
197
- collection . insert ( { a : 1 , b : undefined } , configuration . writeConcernMax ( ) , function ( err ) {
198
- expect ( err ) . to . not . exist ;
190
+ // Ignore the undefined field
191
+ collection . insert ( { a : 1 , b : undefined } , err => {
192
+ expect ( err ) . to . not . exist ;
199
193
200
- // Locate the doument
201
- collection . findOne ( function ( err , item ) {
202
- test . equal ( 1 , item . a ) ;
203
- test . ok ( item . b === undefined ) ;
204
- client . close ( done ) ;
205
- } ) ;
194
+ // Locate the doument
195
+ collection . findOne ( ( err , item ) => {
196
+ test . equal ( 1 , item . a ) ;
197
+ test . ok ( item . b === undefined ) ;
198
+ done ( ) ;
206
199
} ) ;
207
200
} ) ;
208
- }
209
- } ) ;
210
-
211
- it ( 'Should correctly inherit ignore undefined field from operation during insert' , {
212
- metadata : { requires : { topology : [ 'single' ] } } ,
201
+ } )
202
+ ) ;
213
203
214
- test : function ( done ) {
215
- var configuration = this . configuration ;
216
- var client = configuration . newClient ( configuration . writeConcernMax ( ) , {
217
- poolSize : 1
204
+ it (
205
+ 'Should correctly inherit ignore undefined field from operation during insert' ,
206
+ withClient ( function ( client , done ) {
207
+ var db = client . db ( 'shouldCorrectlyIgnoreUndefinedValue5' ) ;
208
+ var collection = db . collection ( 'shouldCorrectlyIgnoreUndefinedValue5' , {
209
+ ignoreUndefined : false
218
210
} ) ;
219
211
220
- client . connect ( function ( err , client ) {
221
- var db = client . db ( configuration . db ) ;
222
- var collection = db . collection ( 'shouldCorrectlyIgnoreUndefinedValue5' , {
223
- ignoreUndefined : false
224
- } ) ;
212
+ // Ignore the undefined field
213
+ collection . insert ( { a : 1 , b : undefined } , { ignoreUndefined : true } , err => {
214
+ expect ( err ) . to . not . exist ;
225
215
226
- // Ignore the undefined field
227
- collection . insert ( { a : 1 , b : undefined } , { ignoreUndefined : true } , function ( err ) {
216
+ // Locate the doument
217
+ collection . findOne ( { } , ( err , item ) => {
228
218
expect ( err ) . to . not . exist ;
229
-
230
- // Locate the doument
231
- collection . findOne ( { } , function ( err , item ) {
232
- expect ( err ) . to . not . exist ;
233
- test . equal ( 1 , item . a ) ;
234
- test . ok ( item . b === undefined ) ;
235
- client . close ( done ) ;
236
- } ) ;
219
+ test . equal ( 1 , item . a ) ;
220
+ test . ok ( item . b === undefined ) ;
221
+ done ( ) ;
237
222
} ) ;
238
223
} ) ;
239
- }
240
- } ) ;
241
-
242
- it ( 'Should correctly inherit ignore undefined field from operation during findOneAndReplace' , {
243
- metadata : { requires : { topology : [ 'single' ] } } ,
224
+ } )
225
+ ) ;
244
226
245
- test : function ( done ) {
246
- var configuration = this . configuration ;
247
- var client = configuration . newClient ( configuration . writeConcernMax ( ) , {
248
- poolSize : 1 ,
227
+ it (
228
+ 'Should correctly inherit ignore undefined field from operation during findOneAndReplace' ,
229
+ withClient ( function ( client , done ) {
230
+ var db = client . db ( 'shouldCorrectlyIgnoreUndefinedValue6' ) ;
231
+ var collection = db . collection ( 'shouldCorrectlyIgnoreUndefinedValue6' , {
249
232
ignoreUndefined : false
250
233
} ) ;
251
234
252
- client . connect ( function ( err , client ) {
253
- var db = client . db ( configuration . db ) ;
254
- var collection = db . collection ( 'shouldCorrectlyIgnoreUndefinedValue6' ) ;
235
+ collection . insert ( { a : 1 , b : 2 } , err => {
236
+ expect ( err ) . to . not . exist ;
255
237
256
- collection . insert ( { a : 1 , b : 2 } , configuration . writeConcernMax ( ) , function ( err ) {
238
+ // Replace the doument, ignoring undefined fields
239
+ collection . findOneAndReplace ( { } , { a : 1 , b : undefined } , { ignoreUndefined : true } , err => {
257
240
expect ( err ) . to . not . exist ;
258
241
259
- // Replace the doument, ignoring undefined fields
260
- collection . findOneAndReplace (
261
- { } ,
262
- { a : 1 , b : undefined } ,
263
- { ignoreUndefined : true } ,
264
- function ( err ) {
265
- expect ( err ) . to . not . exist ;
266
-
267
- // Locate the doument
268
- collection . findOne ( function ( err , item ) {
269
- test . equal ( 1 , item . a ) ;
270
- test . ok ( item . b === undefined ) ;
271
- client . close ( done ) ;
272
- } ) ;
273
- }
274
- ) ;
242
+ // Locate the doument
243
+ collection . findOne ( ( err , item ) => {
244
+ test . equal ( 1 , item . a ) ;
245
+ test . ok ( item . b === undefined ) ;
246
+ done ( ) ;
247
+ } ) ;
275
248
} ) ;
276
249
} ) ;
277
- }
278
- } ) ;
279
-
280
- it ( 'Should correctly ignore undefined field during bulk write' , {
281
- metadata : { requires : { topology : [ 'single' ] } } ,
282
-
283
- test : function ( done ) {
284
- var configuration = this . configuration ;
285
- var client = configuration . newClient ( configuration . writeConcernMax ( ) , {
286
- poolSize : 1
287
- } ) ;
288
-
289
- client . connect ( function ( err , client ) {
290
- var db = client . db ( configuration . db ) ;
291
- var collection = db . collection ( 'shouldCorrectlyIgnoreUndefinedValue7' ) ;
250
+ } )
251
+ ) ;
292
252
293
- // Ignore the undefined field
294
- collection . bulkWrite (
295
- [ { insertOne : { a : 0 , b : undefined } } ] ,
296
- { ignoreUndefined : true } ,
297
- function ( err ) {
298
- expect ( err ) . to . not . exist ;
253
+ it (
254
+ 'Should correctly ignore undefined field during bulk write' ,
255
+ withClient ( function ( client , done ) {
256
+ var db = client . db ( 'shouldCorrectlyIgnoreUndefinedValue7' ) ;
257
+ var collection = db . collection ( 'shouldCorrectlyIgnoreUndefinedValue7' ) ;
258
+
259
+ // Ignore the undefined field
260
+ collection . bulkWrite (
261
+ [ { insertOne : { a : 0 , b : undefined } } ] ,
262
+ { ignoreUndefined : true } ,
263
+ err => {
264
+ expect ( err ) . to . not . exist ;
299
265
300
- // Locate the doument
301
- collection . findOne ( function ( err , item ) {
302
- test . equal ( 0 , item . a ) ;
303
- test . ok ( item . b === undefined ) ;
304
- client . close ( done ) ;
305
- } ) ;
306
- }
307
- ) ;
308
- } ) ;
309
- }
310
- } ) ;
266
+ // Locate the doument
267
+ collection . findOne ( ( err , item ) => {
268
+ test . equal ( 0 , item . a ) ;
269
+ test . ok ( item . b === undefined ) ;
270
+ done ( ) ;
271
+ } ) ;
272
+ }
273
+ ) ;
274
+ } )
275
+ ) ;
311
276
} ) ;
0 commit comments