@@ -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,111 @@ 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
188
- } ) ;
189
-
182
+ it (
183
+ 'Should correctly inherit ignore undefined field from collection during insert' ,
184
+ withClient ( function ( client , done ) {
190
185
client . connect ( function ( err , client ) {
191
- var db = client . db ( configuration . db , { ignoreUndefined : false } ) ;
186
+ var db = client . db ( 'shouldCorrectlyIgnoreUndefinedValue4' , { ignoreUndefined : false } ) ;
192
187
var collection = db . collection ( 'shouldCorrectlyIgnoreUndefinedValue4' , {
193
188
ignoreUndefined : true
194
189
} ) ;
195
190
196
191
// Ignore the undefined field
197
- collection . insert ( { a : 1 , b : undefined } , configuration . writeConcernMax ( ) , function ( err ) {
192
+ collection . insert ( { a : 1 , b : undefined } , err => {
198
193
expect ( err ) . to . not . exist ;
199
194
200
195
// Locate the doument
201
- collection . findOne ( function ( err , item ) {
196
+ collection . findOne ( ( err , item ) => {
202
197
test . equal ( 1 , item . a ) ;
203
198
test . ok ( item . b === undefined ) ;
204
- client . close ( done ) ;
199
+ done ( ) ;
205
200
} ) ;
206
201
} ) ;
207
202
} ) ;
208
- }
209
- } ) ;
210
-
211
- it ( 'Should correctly inherit ignore undefined field from operation during insert' , {
212
- metadata : { requires : { topology : [ 'single' ] } } ,
213
-
214
- test : function ( done ) {
215
- var configuration = this . configuration ;
216
- var client = configuration . newClient ( configuration . writeConcernMax ( ) , {
217
- poolSize : 1
218
- } ) ;
203
+ } )
204
+ ) ;
219
205
220
- client . connect ( function ( err , client ) {
221
- var db = client . db ( configuration . db ) ;
206
+ it (
207
+ 'Should correctly inherit ignore undefined field from operation during insert' ,
208
+ withClient ( function ( client , done ) {
209
+ client . connect ( ( err , client ) => {
210
+ var db = client . db ( 'shouldCorrectlyIgnoreUndefinedValue5' ) ;
222
211
var collection = db . collection ( 'shouldCorrectlyIgnoreUndefinedValue5' , {
223
212
ignoreUndefined : false
224
213
} ) ;
225
214
226
215
// Ignore the undefined field
227
- collection . insert ( { a : 1 , b : undefined } , { ignoreUndefined : true } , function ( err ) {
216
+ collection . insert ( { a : 1 , b : undefined } , { ignoreUndefined : true } , err => {
228
217
expect ( err ) . to . not . exist ;
229
218
230
219
// Locate the doument
231
- collection . findOne ( { } , function ( err , item ) {
220
+ collection . findOne ( { } , ( err , item ) => {
232
221
expect ( err ) . to . not . exist ;
233
222
test . equal ( 1 , item . a ) ;
234
223
test . ok ( item . b === undefined ) ;
235
- client . close ( done ) ;
224
+ done ( ) ;
236
225
} ) ;
237
226
} ) ;
238
227
} ) ;
239
- }
240
- } ) ;
241
-
242
- it ( 'Should correctly inherit ignore undefined field from operation during findOneAndReplace' , {
243
- metadata : { requires : { topology : [ 'single' ] } } ,
244
-
245
- test : function ( done ) {
246
- var configuration = this . configuration ;
247
- var client = configuration . newClient ( configuration . writeConcernMax ( ) , {
248
- poolSize : 1 ,
249
- ignoreUndefined : false
250
- } ) ;
228
+ } )
229
+ ) ;
251
230
252
- client . connect ( function ( err , client ) {
253
- var db = client . db ( configuration . db ) ;
254
- var collection = db . collection ( 'shouldCorrectlyIgnoreUndefinedValue6' ) ;
231
+ it (
232
+ 'Should correctly inherit ignore undefined field from operation during findOneAndReplace' ,
233
+ withClient ( function ( client , done ) {
234
+ client . connect ( ( err , client ) => {
235
+ var db = client . db ( 'shouldCorrectlyIgnoreUndefinedValue6' ) ;
236
+ var collection = db . collection ( 'shouldCorrectlyIgnoreUndefinedValue6' , {
237
+ ignoreUndefined : false
238
+ } ) ;
255
239
256
- collection . insert ( { a : 1 , b : 2 } , configuration . writeConcernMax ( ) , function ( err ) {
240
+ collection . insert ( { a : 1 , b : 2 } , err => {
257
241
expect ( err ) . to . not . exist ;
258
242
259
243
// Replace the doument, ignoring undefined fields
260
244
collection . findOneAndReplace (
261
245
{ } ,
262
246
{ a : 1 , b : undefined } ,
263
247
{ ignoreUndefined : true } ,
264
- function ( err ) {
248
+ err => {
265
249
expect ( err ) . to . not . exist ;
266
250
267
251
// Locate the doument
268
- collection . findOne ( function ( err , item ) {
252
+ collection . findOne ( ( err , item ) => {
269
253
test . equal ( 1 , item . a ) ;
270
254
test . ok ( item . b === undefined ) ;
271
- client . close ( done ) ;
255
+ done ( ) ;
272
256
} ) ;
273
257
}
274
258
) ;
275
259
} ) ;
276
260
} ) ;
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
- } ) ;
261
+ } )
262
+ ) ;
288
263
289
- client . connect ( function ( err , client ) {
290
- var db = client . db ( configuration . db ) ;
264
+ it (
265
+ 'Should correctly ignore undefined field during bulk write' ,
266
+ withClient ( function ( client , done ) {
267
+ client . connect ( ( err , client ) => {
268
+ var db = client . db ( 'shouldCorrectlyIgnoreUndefinedValue7' ) ;
291
269
var collection = db . collection ( 'shouldCorrectlyIgnoreUndefinedValue7' ) ;
292
270
293
271
// Ignore the undefined field
294
272
collection . bulkWrite (
295
273
[ { insertOne : { a : 0 , b : undefined } } ] ,
296
274
{ ignoreUndefined : true } ,
297
- function ( err ) {
275
+ err => {
298
276
expect ( err ) . to . not . exist ;
299
277
300
278
// Locate the doument
301
- collection . findOne ( function ( err , item ) {
279
+ collection . findOne ( ( err , item ) => {
302
280
test . equal ( 0 , item . a ) ;
303
281
test . ok ( item . b === undefined ) ;
304
- client . close ( done ) ;
282
+ done ( ) ;
305
283
} ) ;
306
284
}
307
285
) ;
308
286
} ) ;
309
- }
310
- } ) ;
287
+ } )
288
+ ) ;
311
289
} ) ;
0 commit comments