Skip to content

Commit

Permalink
add test for dropIndexIfExists and not existing index
Browse files Browse the repository at this point in the history
  • Loading branch information
okv committed Dec 25, 2019
1 parent 4b33803 commit 794fd14
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions test/helpers/dropIndexIfExists/withNotExistingIndex.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
'use strict';

const testUtils = require('../../utils');
const helpers = require('../../../lib/helpers');

const test = testUtils.test;
let adapter;

test('setup', (assert) => {
adapter = testUtils.createAdapter();

return Promise.resolve()
.then(() => adapter.connect())
.then(() => adapter.collection.dropIndexes());
});

test(
'helpers dropIndexIfExists with existing index',
(assert) => {
return Promise.resolve()
.then(() => {
return adapter.helpers.dropIndexIfExists(
adapter.collection,
{first: 1, second: -1}
);
})
.then(() => adapter.collection.indexes())
.then((indexes) => {
assert.equal(
indexes.length,
1,
'should leave only one index'
);
assert.deepEqual(
indexes[0].key,
{_id: 1},
'should leave only one index: _id'
);
});
}
);

test('teardown', (assert) => {
return adapter.disconnect();
});

0 comments on commit 794fd14

Please sign in to comment.