Skip to content

Commit cedf80c

Browse files
committed
use withClient for some tests
1 parent dcffd13 commit cedf80c

File tree

1 file changed

+48
-70
lines changed

1 file changed

+48
-70
lines changed

test/functional/ignore_undefined.test.js

Lines changed: 48 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ var test = require('./shared').assert;
33
const { expect } = require('chai');
44
var setupDatabase = require('./shared').setupDatabase;
55
const { ObjectId } = require('../../src');
6+
const withClient = require('./shared').withClient;
67

78
describe('Ignore Undefined', function () {
89
before(function () {
@@ -152,23 +153,23 @@ describe('Ignore Undefined', function () {
152153
it('Should correctly inherit ignore undefined field from db during insert', {
153154
metadata: { requires: { topology: ['single'] } },
154155

155-
test: function (done) {
156+
test: function () {
156157
var configuration = this.configuration;
157158
var client = configuration.newClient(configuration.writeConcernMax(), {
158159
poolSize: 1,
159160
ignoreUndefined: false
160161
});
161162

162-
client.connect(function (err, client) {
163+
return withClient(client, (client, done) => {
163164
var db = client.db(configuration.db, { ignoreUndefined: true });
164165
var collection = db.collection('shouldCorrectlyIgnoreUndefinedValue3');
165166

166167
// 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 => {
168169
expect(err).to.not.exist;
169170

170171
// Locate the doument
171-
collection.findOne(function (err, item) {
172+
collection.findOne((err, item) => {
172173
test.equal(1, item.a);
173174
test.ok(item.b === undefined);
174175
client.close(done);
@@ -178,134 +179,111 @@ describe('Ignore Undefined', function () {
178179
}
179180
});
180181

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) {
190185
client.connect(function (err, client) {
191-
var db = client.db(configuration.db, { ignoreUndefined: false });
186+
var db = client.db('shouldCorrectlyIgnoreUndefinedValue4', { ignoreUndefined: false });
192187
var collection = db.collection('shouldCorrectlyIgnoreUndefinedValue4', {
193188
ignoreUndefined: true
194189
});
195190

196191
// Ignore the undefined field
197-
collection.insert({ a: 1, b: undefined }, configuration.writeConcernMax(), function (err) {
192+
collection.insert({ a: 1, b: undefined }, err => {
198193
expect(err).to.not.exist;
199194

200195
// Locate the doument
201-
collection.findOne(function (err, item) {
196+
collection.findOne((err, item) => {
202197
test.equal(1, item.a);
203198
test.ok(item.b === undefined);
204-
client.close(done);
199+
done();
205200
});
206201
});
207202
});
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+
);
219205

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');
222211
var collection = db.collection('shouldCorrectlyIgnoreUndefinedValue5', {
223212
ignoreUndefined: false
224213
});
225214

226215
// 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 => {
228217
expect(err).to.not.exist;
229218

230219
// Locate the doument
231-
collection.findOne({}, function (err, item) {
220+
collection.findOne({}, (err, item) => {
232221
expect(err).to.not.exist;
233222
test.equal(1, item.a);
234223
test.ok(item.b === undefined);
235-
client.close(done);
224+
done();
236225
});
237226
});
238227
});
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+
);
251230

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+
});
255239

256-
collection.insert({ a: 1, b: 2 }, configuration.writeConcernMax(), function (err) {
240+
collection.insert({ a: 1, b: 2 }, err => {
257241
expect(err).to.not.exist;
258242

259243
// Replace the doument, ignoring undefined fields
260244
collection.findOneAndReplace(
261245
{},
262246
{ a: 1, b: undefined },
263247
{ ignoreUndefined: true },
264-
function (err) {
248+
err => {
265249
expect(err).to.not.exist;
266250

267251
// Locate the doument
268-
collection.findOne(function (err, item) {
252+
collection.findOne((err, item) => {
269253
test.equal(1, item.a);
270254
test.ok(item.b === undefined);
271-
client.close(done);
255+
done();
272256
});
273257
}
274258
);
275259
});
276260
});
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+
);
288263

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');
291269
var collection = db.collection('shouldCorrectlyIgnoreUndefinedValue7');
292270

293271
// Ignore the undefined field
294272
collection.bulkWrite(
295273
[{ insertOne: { a: 0, b: undefined } }],
296274
{ ignoreUndefined: true },
297-
function (err) {
275+
err => {
298276
expect(err).to.not.exist;
299277

300278
// Locate the doument
301-
collection.findOne(function (err, item) {
279+
collection.findOne((err, item) => {
302280
test.equal(0, item.a);
303281
test.ok(item.b === undefined);
304-
client.close(done);
282+
done();
305283
});
306284
}
307285
);
308286
});
309-
}
310-
});
287+
})
288+
);
311289
});

0 commit comments

Comments
 (0)