Skip to content

Commit 9fc1d45

Browse files
authored
test(NODE-7200): migrate integration/crud/remove tests (#4731)
1 parent 1535739 commit 9fc1d45

File tree

2 files changed

+56
-134
lines changed

2 files changed

+56
-134
lines changed

test/integration/crud/remove.test.js

Lines changed: 0 additions & 134 deletions
This file was deleted.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import { expect } from 'chai';
2+
3+
import { type MongoClient } from '../../../src';
4+
5+
describe('Remove', function () {
6+
let client: MongoClient;
7+
8+
beforeEach(async function () {
9+
client = this.configuration.newClient();
10+
});
11+
12+
afterEach(async function () {
13+
await client.close();
14+
});
15+
16+
it('should correctly clear out collection', async function () {
17+
const db = client.db();
18+
19+
const collection = await db.createCollection('test_clear');
20+
21+
await collection.insertOne({ i: 1 }, { writeConcern: { w: 1 } });
22+
23+
await collection.insertOne({ i: 2 }, { writeConcern: { w: 1 } });
24+
const count = await collection.countDocuments();
25+
expect(count).to.equal(2);
26+
27+
// Clear the collection
28+
const r = await collection.deleteMany({}, { writeConcern: { w: 1 } });
29+
expect(r).property('deletedCount').to.equal(2);
30+
31+
const c = await collection.countDocuments();
32+
expect(c).to.equal(0);
33+
});
34+
35+
it('should correctly remove document using RegExp', async function () {
36+
const db = client.db(this.configuration.db);
37+
38+
const collection = await db.createCollection('test_remove_regexp');
39+
40+
await collection.insertOne({ address: '485 7th ave new york' }, { writeConcern: { w: 1 } });
41+
42+
// Clear the collection
43+
const r = await collection.deleteMany({ address: /485 7th ave/ }, { writeConcern: { w: 1 } });
44+
expect(r).property('deletedCount').to.equal(1);
45+
46+
const count = await collection.countDocuments();
47+
expect(count).to.equal(0);
48+
});
49+
50+
it('should not throw error on empty remove', async function () {
51+
const db = client.db(this.configuration.db);
52+
const collection = db.collection('remove_test');
53+
54+
await collection.deleteMany({});
55+
});
56+
});

0 commit comments

Comments
 (0)