Skip to content

Commit b59aec4

Browse files
committed
test: remove remove usage
1 parent 672ddc1 commit b59aec4

File tree

6 files changed

+17
-65
lines changed

6 files changed

+17
-65
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,7 @@ describe('Collection', function () {
235235
expect(err).to.not.exist;
236236
collection.insertOne({ c: 1 }, configuration.writeConcernMax(), err => {
237237
expect(err).to.not.exist;
238-
collection.remove({ a: 1 }, configuration.writeConcernMax(), err => {
238+
collection.deleteMany({ a: 1 }, configuration.writeConcernMax(), err => {
239239
expect(err).to.not.exist;
240240
// Let's perform a count
241241
collection.countDocuments((err, count) => {

test/integration/crud/crud_api.test.ts

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -666,27 +666,6 @@ describe('CRUD API', function () {
666666
client.connect(function (err, client) {
667667
const db = client.db();
668668

669-
//
670-
// Legacy update method
671-
// -------------------------------------------------
672-
const legacyRemove = function () {
673-
db.collection('t4_1').insertMany(
674-
[{ a: 1 }, { a: 1 }],
675-
{ writeConcern: { w: 1 } },
676-
function (err, r) {
677-
expect(err).to.not.exist;
678-
test.equal(2, r.insertedCount);
679-
680-
db.collection('t4_1').remove({ a: 1 }, { single: true }, function (err, r) {
681-
expect(err).to.not.exist;
682-
test.equal(1, r.deletedCount);
683-
684-
deleteOne();
685-
});
686-
}
687-
);
688-
};
689-
690669
//
691670
// Update one method
692671
// -------------------------------------------------
@@ -728,8 +707,6 @@ describe('CRUD API', function () {
728707
}
729708
);
730709
};
731-
732-
legacyRemove();
733710
});
734711
}
735712
});

test/integration/crud/insert.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ describe('crud - insert', function () {
325325
db.createCollection(
326326
'users',
327327
getResult(function (user_collection) {
328-
user_collection.remove({}, configuration.writeConcernMax(), function (err) {
328+
user_collection.deleteMany({}, configuration.writeConcernMax(), function (err) {
329329
expect(err).to.not.exist;
330330

331331
//first, create a user object
@@ -806,7 +806,7 @@ describe('crud - insert', function () {
806806
expect(err).to.not.exist;
807807
test.ok(result);
808808

809-
collection.remove(
809+
collection.deleteMany(
810810
{ a: 2 },
811811
configuration.writeConcernMax(),
812812
function (err, result) {
@@ -1522,7 +1522,7 @@ describe('crud - insert', function () {
15221522
client.connect(function (err, client) {
15231523
var db = client.db(configuration.db);
15241524
var collection = db.collection('gh-completely1');
1525-
collection.remove({ a: 1 }, { writeConcern: { w: 0 } }, cb);
1525+
collection.deleteMany({ a: 1 }, { writeConcern: { w: 0 } }, cb);
15261526
});
15271527
}
15281528
});

test/integration/crud/remove.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ describe('Remove', function () {
3535
expect(count).to.equal(2);
3636

3737
// Clear the collection
38-
collection.remove({}, { writeConcern: { w: 1 } }, function (err, r) {
38+
collection.deleteMany({}, { writeConcern: { w: 1 } }, function (err, r) {
3939
expect(err).to.not.exist;
4040
expect(r).property('deletedCount').to.equal(2);
4141

@@ -81,7 +81,7 @@ describe('Remove', function () {
8181
expect(err).to.not.exist;
8282

8383
// Clear the collection
84-
collection.remove(
84+
collection.deleteMany(
8585
{ address: /485 7th ave/ },
8686
{ writeConcern: { w: 1 } },
8787
function (err, r) {
@@ -130,7 +130,7 @@ describe('Remove', function () {
130130
expect(err).to.not.exist;
131131

132132
// Remove the first
133-
collection.remove(
133+
collection.deleteMany(
134134
{ a: 1 },
135135
{ writeConcern: { w: 1 }, single: true },
136136
function (err, r) {

test/integration/node-specific/auto_connect.test.ts

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -483,15 +483,6 @@ describe('When executing an operation for the first time', () => {
483483
});
484484
});
485485

486-
describe(`#insert()`, () => {
487-
it('should connect the client', async () => {
488-
const c = client.db().collection('test');
489-
// @ts-expect-error: deprecated API
490-
await c.insert({ a: 1 });
491-
expect(client).to.have.property('topology').that.is.instanceOf(Topology);
492-
});
493-
});
494-
495486
describe(`#insertMany()`, () => {
496487
it('should connect the client', async () => {
497488
const c = client.db().collection('test');
@@ -542,15 +533,6 @@ describe('When executing an operation for the first time', () => {
542533
});
543534
});
544535

545-
describe(`#remove()`, () => {
546-
it('should connect the client', async () => {
547-
const c = client.db().collection('test');
548-
// @ts-expect-error: deprecated API
549-
await c.remove({ a: 1 });
550-
expect(client).to.have.property('topology').that.is.instanceOf(Topology);
551-
});
552-
});
553-
554536
describe(`#rename()`, () => {
555537
it('should connect the client', async () => {
556538
const c = client.db().collection('test0');
@@ -575,15 +557,6 @@ describe('When executing an operation for the first time', () => {
575557
});
576558
});
577559

578-
describe(`#update()`, () => {
579-
it('should connect the client', async () => {
580-
const c = client.db().collection('test');
581-
// @ts-expect-error: deprecated API
582-
await c.update({ a: 1 }, { $set: { a: 2 } });
583-
expect(client).to.have.property('topology').that.is.instanceOf(Topology);
584-
});
585-
});
586-
587560
describe(`#updateMany()`, () => {
588561
it('should connect the client', async () => {
589562
const c = client.db().collection('test');

test/tools/runner/hooks/legacy.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,15 @@
11
import { Collection } from '../../../../src';
22

33
// Setup legacy shims for tests that use removed or changed APIs
4+
const counts = {
5+
insert: 0,
6+
update: 0,
7+
remove: 0
8+
};
49

510
// @ts-expect-error: Method no longer exists on Collection
611
Collection.prototype.insert = function (docs, options, callback) {
12+
counts.insert += 1;
713
callback =
814
typeof callback === 'function' ? callback : typeof options === 'function' ? options : undefined;
915
options = options != null && typeof options === 'object' ? options : { ordered: false };
@@ -15,18 +21,14 @@ Collection.prototype.insert = function (docs, options, callback) {
1521

1622
// @ts-expect-error: Method no longer exists on Collection
1723
Collection.prototype.update = function (filter, update, options, callback) {
24+
counts.update += 1;
1825
callback =
1926
typeof callback === 'function' ? callback : typeof options === 'function' ? options : undefined;
2027
options = options != null && typeof options === 'object' ? options : {};
2128

2229
return this.updateMany(filter, update, options, callback);
2330
};
2431

25-
// @ts-expect-error: Method no longer exists on Collection
26-
Collection.prototype.remove = function (filter, options, callback) {
27-
callback =
28-
typeof callback === 'function' ? callback : typeof options === 'function' ? options : undefined;
29-
options = options != null && typeof options === 'object' ? options : {};
30-
31-
return this.deleteMany(filter, options, callback);
32-
};
32+
process.on('beforeExit', () => {
33+
console.dir(counts);
34+
});

0 commit comments

Comments
 (0)