Skip to content

Commit 329f658

Browse files
misc test fixes
1 parent fe7d039 commit 329f658

File tree

2 files changed

+23
-56
lines changed

2 files changed

+23
-56
lines changed

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

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -389,20 +389,10 @@ describe('Collection', function () {
389389
);
390390
});
391391

392-
it('should support createIndex with no options', function (done) {
393-
db.createCollection('create_index_without_options', {}, (err, collection) => {
394-
collection.createIndex({ createdAt: 1 }, err => {
395-
expect(err).to.not.exist;
396-
397-
collection.indexInformation({ full: true }, (err, indexes) => {
398-
expect(err).to.not.exist;
399-
const indexNames = indexes.map(i => i.name);
400-
expect(indexNames).to.include('createdAt_1');
401-
402-
done();
403-
});
404-
});
405-
});
392+
it('should support createIndex with no options', async function () {
393+
const collection = await db.createCollection('create_index_without_options', {});
394+
await collection.createIndex({ createdAt: 1 });
395+
expect(await collection.indexExists('createdAt_1')).to.be.true;
406396
});
407397
});
408398

test/integration/index_management.test.js

Lines changed: 19 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -459,48 +459,25 @@ describe('Indexes', function () {
459459
}
460460
});
461461

462-
it('shouldCorrectlyCreateAndUseSparseIndex', {
463-
metadata: {
464-
requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] }
465-
},
466-
467-
test: function (done) {
468-
var configuration = this.configuration;
469-
var client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 });
470-
var db = client.db(configuration.db);
471-
db.createCollection('create_and_use_sparse_index_test', function (err) {
472-
expect(err).to.not.exist;
473-
const collection = db.collection('create_and_use_sparse_index_test');
474-
collection.createIndex(
475-
{ title: 1 },
476-
{ sparse: true, writeConcern: { w: 1 } },
477-
function (err) {
478-
expect(err).to.not.exist;
479-
collection.insert(
480-
[{ name: 'Jim' }, { name: 'Sarah', title: 'Princess' }],
481-
configuration.writeConcernMax(),
482-
function (err) {
483-
expect(err).to.not.exist;
484-
collection
485-
.find({ title: { $ne: null } })
486-
.sort({ title: 1 })
487-
.toArray(function (err, items) {
488-
test.equal(1, items.length);
489-
test.equal('Sarah', items[0].name);
490-
491-
// Fetch the info for the indexes
492-
collection.indexInformation({ full: true }, function (err, indexInfo) {
493-
expect(err).to.not.exist;
494-
test.equal(2, indexInfo.length);
495-
client.close(done);
496-
});
497-
});
498-
}
499-
);
500-
}
501-
);
502-
});
503-
}
462+
it('shouldCorrectlyCreateAndUseSparseIndex', async function () {
463+
const db = client.db(this.configuration.db);
464+
await db.createCollection('create_and_use_sparse_index_test');
465+
const collection = db.collection('create_and_use_sparse_index_test');
466+
await collection.createIndex({ title: 1 }, { sparse: true, writeConcern: { w: 1 } });
467+
await collection.insertMany(
468+
[{ name: 'Jim' }, { name: 'Sarah', title: 'Princess' }],
469+
this.configuration.writeConcernMax()
470+
);
471+
const items = await collection
472+
.find({ title: { $ne: null } })
473+
.sort({ title: 1 })
474+
.toArray();
475+
expect(items).to.have.lengthOf(1);
476+
expect(items[0]).to.have.property('name', 'Sarah');
477+
478+
// Fetch the info for the indexes
479+
const indexInfo = await collection.indexInformation({ full: true });
480+
expect(indexInfo).to.have.lengthOf(2);
504481
});
505482

506483
it('shouldCorrectlyHandleGeospatialIndexes', {

0 commit comments

Comments
 (0)