Skip to content

Commit

Permalink
misc test fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
baileympearson committed Mar 14, 2024
1 parent fe7d039 commit 329f658
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 56 deletions.
18 changes: 4 additions & 14 deletions test/integration/collection-management/collection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -389,20 +389,10 @@ describe('Collection', function () {
);
});

it('should support createIndex with no options', function (done) {
db.createCollection('create_index_without_options', {}, (err, collection) => {
collection.createIndex({ createdAt: 1 }, err => {
expect(err).to.not.exist;

collection.indexInformation({ full: true }, (err, indexes) => {
expect(err).to.not.exist;
const indexNames = indexes.map(i => i.name);
expect(indexNames).to.include('createdAt_1');

done();
});
});
});
it('should support createIndex with no options', async function () {
const collection = await db.createCollection('create_index_without_options', {});
await collection.createIndex({ createdAt: 1 });
expect(await collection.indexExists('createdAt_1')).to.be.true;
});
});

Expand Down
61 changes: 19 additions & 42 deletions test/integration/index_management.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,48 +459,25 @@ describe('Indexes', function () {
}
});

it('shouldCorrectlyCreateAndUseSparseIndex', {
metadata: {
requires: { topology: ['single', 'replicaset', 'sharded', 'ssl', 'heap', 'wiredtiger'] }
},

test: function (done) {
var configuration = this.configuration;
var client = configuration.newClient(configuration.writeConcernMax(), { maxPoolSize: 1 });
var db = client.db(configuration.db);
db.createCollection('create_and_use_sparse_index_test', function (err) {
expect(err).to.not.exist;
const collection = db.collection('create_and_use_sparse_index_test');
collection.createIndex(
{ title: 1 },
{ sparse: true, writeConcern: { w: 1 } },
function (err) {
expect(err).to.not.exist;
collection.insert(
[{ name: 'Jim' }, { name: 'Sarah', title: 'Princess' }],
configuration.writeConcernMax(),
function (err) {
expect(err).to.not.exist;
collection
.find({ title: { $ne: null } })
.sort({ title: 1 })
.toArray(function (err, items) {
test.equal(1, items.length);
test.equal('Sarah', items[0].name);

// Fetch the info for the indexes
collection.indexInformation({ full: true }, function (err, indexInfo) {
expect(err).to.not.exist;
test.equal(2, indexInfo.length);
client.close(done);
});
});
}
);
}
);
});
}
it('shouldCorrectlyCreateAndUseSparseIndex', async function () {
const db = client.db(this.configuration.db);
await db.createCollection('create_and_use_sparse_index_test');
const collection = db.collection('create_and_use_sparse_index_test');
await collection.createIndex({ title: 1 }, { sparse: true, writeConcern: { w: 1 } });
await collection.insertMany(
[{ name: 'Jim' }, { name: 'Sarah', title: 'Princess' }],
this.configuration.writeConcernMax()
);
const items = await collection
.find({ title: { $ne: null } })
.sort({ title: 1 })
.toArray();
expect(items).to.have.lengthOf(1);
expect(items[0]).to.have.property('name', 'Sarah');

// Fetch the info for the indexes
const indexInfo = await collection.indexInformation({ full: true });
expect(indexInfo).to.have.lengthOf(2);
});

it('shouldCorrectlyHandleGeospatialIndexes', {
Expand Down

0 comments on commit 329f658

Please sign in to comment.