Skip to content

Commit 83bce00

Browse files
test(NODE-4917): remove grouped callback style tests (#3512)
Co-authored-by: Bailey Pearson <[email protected]>
1 parent 8f8ea45 commit 83bce00

File tree

11 files changed

+1045
-7652
lines changed

11 files changed

+1045
-7652
lines changed

test/integration/change-streams/change_stream.test.ts

Lines changed: 0 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -214,66 +214,6 @@ describe('Change Streams', function () {
214214
}
215215
});
216216

217-
it(
218-
'should create a ChangeStream on a collection and get change events through imperative callback form',
219-
{
220-
metadata: { requires: { topology: 'replicaset' } },
221-
222-
test: function (done) {
223-
const configuration = this.configuration;
224-
const client = configuration.newClient();
225-
226-
client.connect((err, client) => {
227-
expect(err).to.not.exist;
228-
this.defer(() => client.close());
229-
230-
const collection = client.db('integration_tests').collection('docsCallback');
231-
const changeStream = collection.watch(pipeline);
232-
this.defer(() => changeStream.close());
233-
234-
// Fetch the change notification
235-
changeStream.hasNext((err, hasNext) => {
236-
expect(err).to.not.exist;
237-
238-
assert.equal(true, hasNext);
239-
changeStream.next((err, change) => {
240-
expect(err).to.not.exist;
241-
expect(change).to.have.property('operationType', 'insert');
242-
expect(change).to.have.nested.property('fullDocument.e', 5);
243-
expect(change).to.have.nested.property('ns.db', 'integration_tests');
244-
expect(change).to.have.nested.property('ns.coll', 'docsCallback');
245-
expect(change).to.not.have.property('documentKey');
246-
expect(change).to.have.property(
247-
'comment',
248-
'The documentKey field has been projected out of this document.'
249-
);
250-
251-
// Trigger the second database event
252-
collection.updateOne({ e: 5 }, { $inc: { e: 2 } }, err => {
253-
expect(err).to.not.exist;
254-
changeStream.hasNext((err, hasNext) => {
255-
expect(err).to.not.exist;
256-
assert.equal(true, hasNext);
257-
changeStream.next((err, change) => {
258-
expect(err).to.not.exist;
259-
assert.equal(change.operationType, 'update');
260-
261-
done();
262-
});
263-
});
264-
});
265-
});
266-
});
267-
268-
// Trigger the first database event
269-
// NOTE: this needs to be triggered after the changeStream call so
270-
// that the cursor is run
271-
this.defer(collection.insertOne({ e: 5 }));
272-
});
273-
}
274-
}
275-
);
276-
277217
it('should support creating multiple simultaneous ChangeStreams', {
278218
metadata: { requires: { topology: 'replicaset' } },
279219

test/integration/collection-management/collection.test.ts

Lines changed: 4 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -578,31 +578,10 @@ describe('Collection', function () {
578578
});
579579
});
580580

581-
context('when no callback passed', function () {
582-
it('returns a promise', function () {
583-
const docsPromise = collection.countDocuments();
584-
expect(docsPromise).to.exist.and.to.be.an.instanceof(Promise);
585-
return docsPromise.then(result => expect(result).to.equal(1));
586-
});
587-
});
588-
589-
context('when a callback is passed', function () {
590-
it('does not return a promise', function (done) {
591-
const notPromise = collection.countDocuments({ a: 1 }, () => {
592-
expect(notPromise).to.be.undefined;
593-
done();
594-
});
595-
});
596-
597-
it('calls the callback', function (done) {
598-
const docs = [{ a: 1 }, { a: 2 }];
599-
collection.insertMany(docs).then(() =>
600-
collection.countDocuments({ a: 1 }, (err, data) => {
601-
expect(data).to.equal(1);
602-
done(err);
603-
})
604-
);
605-
});
581+
it('returns a promise', function () {
582+
const docsPromise = collection.countDocuments();
583+
expect(docsPromise).to.exist.and.to.be.an.instanceof(Promise);
584+
return docsPromise.then(result => expect(result).to.equal(1));
606585
});
607586
});
608587

test/integration/collection-management/promise_collection_db_management.test.ts renamed to test/integration/collection-management/collection_db_management.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { assert as test, setupDatabase } from '../shared';
22

3-
describe('Collection Management and Db Management (promise tests)', function () {
3+
describe('Collection Management and Db Management', function () {
44
before(function () {
55
return setupDatabase(this.configuration);
66
});

test/integration/crud/bulk.test.ts

Lines changed: 27 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -107,37 +107,35 @@ describe('Bulk', function () {
107107
});
108108
});
109109

110-
context('promise tests', () => {
111-
it('Should correctly execute unordered bulk operation in promise form', async function () {
112-
const db = client.db();
113-
const bulk = db
114-
.collection('unordered_bulk_promise_form')
115-
.initializeUnorderedBulkOp({ writeConcern: { w: 1 } });
116-
bulk.insert({ a: 1 });
117-
118-
const r = await bulk.execute();
119-
test.ok(r);
120-
test.deepEqual({ w: 1 }, bulk.s.writeConcern);
121-
});
110+
it('Should correctly execute unordered bulk operation', async function () {
111+
const db = client.db();
112+
const bulk = db
113+
.collection('unordered_bulk_promise_form')
114+
.initializeUnorderedBulkOp({ writeConcern: { w: 1 } });
115+
bulk.insert({ a: 1 });
116+
117+
const r = await bulk.execute();
118+
test.ok(r);
119+
test.deepEqual({ w: 1 }, bulk.s.writeConcern);
120+
});
122121

123-
it('Should correctly execute ordered bulk operation in promise form', async function () {
124-
const db = client.db();
125-
const bulk = db
126-
.collection('unordered_bulk_promise_form')
127-
.initializeOrderedBulkOp({ writeConcern: { w: 1 } });
128-
bulk.insert({ a: 1 });
129-
130-
const r = await bulk.execute();
131-
test.ok(r);
132-
test.deepEqual({ w: 1 }, bulk.s.writeConcern);
133-
});
122+
it('Should correctly execute ordered bulk operation', async function () {
123+
const db = client.db();
124+
const bulk = db
125+
.collection('unordered_bulk_promise_form')
126+
.initializeOrderedBulkOp({ writeConcern: { w: 1 } });
127+
bulk.insert({ a: 1 });
128+
129+
const r = await bulk.execute();
130+
test.ok(r);
131+
test.deepEqual({ w: 1 }, bulk.s.writeConcern);
132+
});
134133

135-
it('Should correctly handle bulkWrite with no options', async function () {
136-
const db = client.db();
137-
const col = db.collection('find_one_and_replace_with_promise_no_option');
138-
const result = await col.bulkWrite([{ insertOne: { document: { a: 1 } } }]);
139-
expect(result).to.exist;
140-
});
134+
it('Should correctly handle bulkWrite with no options', async function () {
135+
const db = client.db();
136+
const col = db.collection('find_one_and_replace_with_promise_no_option');
137+
const result = await col.bulkWrite([{ insertOne: { document: { a: 1 } } }]);
138+
expect(result).to.exist;
141139
});
142140

143141
it('should correctly handle ordered single batch api write command error', function (done) {

test/integration/crud/explain.test.js

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -744,7 +744,7 @@ describe('Explain', function () {
744744
});
745745
});
746746

747-
it('should throw a catchable error with invalid explain string (promise)', {
747+
it('should throw a catchable error with invalid explain string', {
748748
metadata: {
749749
requires: {
750750
mongodb: '>=3.4'
@@ -764,22 +764,4 @@ describe('Explain', function () {
764764
});
765765
}
766766
});
767-
768-
it('should throw a catchable error with invalid explain string (callback)', {
769-
metadata: {
770-
requires: {
771-
mongodb: '>=3.4'
772-
}
773-
},
774-
test: function (done) {
775-
const db = client.db('shouldThrowCatchableError');
776-
const collection = db.collection('test');
777-
collection.find({ a: 1 }).explain('invalidExplain', (err, result) => {
778-
expect(err).to.exist;
779-
expect(result).to.not.exist;
780-
expect(err).to.be.instanceOf(MongoServerError);
781-
done();
782-
});
783-
}
784-
});
785767
});

test/integration/crud/find_and_modify.test.js

Lines changed: 68 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -9,85 +9,83 @@ describe('Find and Modify', function () {
99
return setupDatabase(this.configuration);
1010
});
1111

12-
context('promise tests', function () {
13-
it('Should correctly execute findOneAndDelete operation With Promises and no options passed in', function (done) {
14-
var configuration = this.configuration;
15-
var client = configuration.newClient(configuration.writeConcernMax(), {
16-
maxPoolSize: 1
17-
});
18-
19-
client.connect().then(function (client) {
20-
const db = client.db(configuration.db);
21-
const col = db.collection('find_one_and_delete_with_promise_no_option');
22-
col.insertMany([{ a: 1, b: 1 }], { writeConcern: { w: 1 } }).then(function (r) {
23-
expect(r).property('insertedCount').to.equal(1);
24-
25-
col
26-
.findOneAndDelete({ a: 1 })
27-
.then(function (r) {
28-
test.equal(1, r.lastErrorObject.n);
29-
test.equal(1, r.value.b);
30-
31-
client.close(done);
32-
})
33-
.catch(function (err) {
34-
test.ok(err != null);
35-
});
36-
});
37-
});
12+
it('Should correctly execute findOneAndDelete operation and no options passed in', function (done) {
13+
var configuration = this.configuration;
14+
var client = configuration.newClient(configuration.writeConcernMax(), {
15+
maxPoolSize: 1
3816
});
3917

40-
it('Should correctly execute findOneAndUpate operation With Promises and no options passed in', function (done) {
41-
var configuration = this.configuration;
42-
var client = configuration.newClient(configuration.writeConcernMax(), {
43-
maxPoolSize: 1
18+
client.connect().then(function (client) {
19+
const db = client.db(configuration.db);
20+
const col = db.collection('find_one_and_delete_with_promise_no_option');
21+
col.insertMany([{ a: 1, b: 1 }], { writeConcern: { w: 1 } }).then(function (r) {
22+
expect(r).property('insertedCount').to.equal(1);
23+
24+
col
25+
.findOneAndDelete({ a: 1 })
26+
.then(function (r) {
27+
test.equal(1, r.lastErrorObject.n);
28+
test.equal(1, r.value.b);
29+
30+
client.close(done);
31+
})
32+
.catch(function (err) {
33+
test.ok(err != null);
34+
});
4435
});
36+
});
37+
});
4538

46-
client.connect().then(function (client) {
47-
const db = client.db(configuration.db);
48-
const col = db.collection('find_one_and_update_with_promise_no_option');
49-
col.insertMany([{ a: 1, b: 1 }], { writeConcern: { w: 1 } }).then(function (r) {
50-
expect(r).property('insertedCount').to.equal(1);
51-
52-
col
53-
.findOneAndUpdate({ a: 1 }, { $set: { a: 1 } })
54-
.then(function (r) {
55-
test.equal(1, r.lastErrorObject.n);
56-
test.equal(1, r.value.b);
57-
58-
client.close(done);
59-
})
60-
.catch(function (err) {
61-
test.ok(err != null);
62-
});
63-
});
64-
});
39+
it('Should correctly execute findOneAndUpate operation and no options passed in', function (done) {
40+
var configuration = this.configuration;
41+
var client = configuration.newClient(configuration.writeConcernMax(), {
42+
maxPoolSize: 1
6543
});
6644

67-
it('Should correctly execute findOneAndReplace operation With Promises and no options passed in', function (done) {
68-
var configuration = this.configuration;
69-
var client = configuration.newClient(configuration.writeConcernMax(), {
70-
maxPoolSize: 1
45+
client.connect().then(function (client) {
46+
const db = client.db(configuration.db);
47+
const col = db.collection('find_one_and_update_with_promise_no_option');
48+
col.insertMany([{ a: 1, b: 1 }], { writeConcern: { w: 1 } }).then(function (r) {
49+
expect(r).property('insertedCount').to.equal(1);
50+
51+
col
52+
.findOneAndUpdate({ a: 1 }, { $set: { a: 1 } })
53+
.then(function (r) {
54+
test.equal(1, r.lastErrorObject.n);
55+
test.equal(1, r.value.b);
56+
57+
client.close(done);
58+
})
59+
.catch(function (err) {
60+
test.ok(err != null);
61+
});
7162
});
63+
});
64+
});
7265

73-
client.connect().then(function (client) {
74-
const db = client.db(configuration.db);
75-
const col = db.collection('find_one_and_replace_with_promise_no_option');
76-
col.insertMany([{ a: 1, b: 1 }], { writeConcern: { w: 1 } }).then(function (r) {
77-
expect(r).property('insertedCount').to.equal(1);
78-
79-
col
80-
.findOneAndReplace({ a: 1 }, { a: 1 })
81-
.then(function (r) {
82-
test.equal(1, r.lastErrorObject.n);
83-
test.equal(1, r.value.b);
66+
it('Should correctly execute findOneAndReplace operation and no options passed in', function (done) {
67+
var configuration = this.configuration;
68+
var client = configuration.newClient(configuration.writeConcernMax(), {
69+
maxPoolSize: 1
70+
});
8471

85-
client.close(done);
86-
})
87-
.catch(function (err) {
88-
test.ok(err != null);
89-
});
90-
});
72+
client.connect().then(function (client) {
73+
const db = client.db(configuration.db);
74+
const col = db.collection('find_one_and_replace_with_promise_no_option');
75+
col.insertMany([{ a: 1, b: 1 }], { writeConcern: { w: 1 } }).then(function (r) {
76+
expect(r).property('insertedCount').to.equal(1);
77+
78+
col
79+
.findOneAndReplace({ a: 1 }, { a: 1 })
80+
.then(function (r) {
81+
test.equal(1, r.lastErrorObject.n);
82+
test.equal(1, r.value.b);
83+
84+
client.close(done);
85+
})
86+
.catch(function (err) {
87+
test.ok(err != null);
88+
});
9189
});
9290
});
9391
});

0 commit comments

Comments
 (0)