-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add test for dropIndexIfExists and not existing index
- Loading branch information
Showing
1 changed file
with
45 additions
and
0 deletions.
There are no files selected for viewing
45 changes: 45 additions & 0 deletions
45
test/helpers/dropIndexIfExists/withNotExistingIndex.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
}); |