@@ -70,7 +70,7 @@ describe('Indexes', function () {
70
70
} ) ;
71
71
72
72
it ( 'shouldCorrectlyHandleMultipleColumnIndexes' , async function ( ) {
73
- await collection . insert ( { a : 1 } ) ;
73
+ await collection . insertOne ( { a : 1 } ) ;
74
74
75
75
const indexName = await db . createIndex (
76
76
collection . collectionName ,
@@ -99,6 +99,124 @@ describe('Indexes', function () {
99
99
) ;
100
100
} ) ;
101
101
102
+ describe ( 'Collection.indexes()' , function ( ) {
103
+ beforeEach ( ( ) => collection . createIndex ( { age : 1 } ) ) ;
104
+ afterEach ( ( ) => collection . dropIndexes ( ) ) ;
105
+
106
+ context ( 'when `full` is not provided' , ( ) => {
107
+ it ( 'returns an array of indexes' , async function ( ) {
108
+ const indexes = await collection . indexes ( ) ;
109
+ expect ( indexes ) . to . be . a ( 'array' ) ;
110
+ } ) ;
111
+ } ) ;
112
+
113
+ context ( 'when `full` is set to `true`' , ( ) => {
114
+ it ( 'returns an array of indexes' , async function ( ) {
115
+ const indexes = await collection . indexes ( { full : true } ) ;
116
+ expect ( indexes ) . to . be . a ( 'array' ) ;
117
+ } ) ;
118
+ } ) ;
119
+
120
+ context ( 'when `full` is set to `false`' , ( ) => {
121
+ it ( 'returns a document mapping key to index definition' , async function ( ) {
122
+ const indexes = await collection . indexes ( { full : false } ) ;
123
+ expect ( indexes ) . to . be . a ( 'object' ) ;
124
+ expect ( indexes )
125
+ . to . have . property ( 'age_1' )
126
+ . to . deep . equal ( [ [ 'age' , 1 ] ] ) ;
127
+ } ) ;
128
+ } ) ;
129
+ } ) ;
130
+
131
+ describe ( 'Collection.indexInformation()' , function ( ) {
132
+ beforeEach ( ( ) => collection . createIndex ( { age : 1 } ) ) ;
133
+ afterEach ( ( ) => collection . dropIndexes ( ) ) ;
134
+
135
+ context ( 'when `full` is not provided' , ( ) => {
136
+ it ( 'defaults to `false` and returns a document' , async function ( ) {
137
+ const indexes = await collection . indexInformation ( ) ;
138
+ expect ( indexes ) . to . be . a ( 'object' ) ;
139
+ expect ( indexes )
140
+ . to . have . property ( 'age_1' )
141
+ . to . deep . equal ( [ [ 'age' , 1 ] ] ) ;
142
+ } ) ;
143
+ } ) ;
144
+
145
+ context ( 'when `full` is set to `true`' , ( ) => {
146
+ it ( 'returns an array of indexes' , async function ( ) {
147
+ const indexes = await collection . indexInformation ( { full : true } ) ;
148
+ expect ( indexes ) . to . be . a ( 'array' ) ;
149
+ } ) ;
150
+ } ) ;
151
+
152
+ context ( 'when `full` is set to `false`' , ( ) => {
153
+ it ( 'returns a document mapping key to index definition' , async function ( ) {
154
+ const indexes = await collection . indexInformation ( { full : false } ) ;
155
+ expect ( indexes ) . to . be . a ( 'object' ) ;
156
+ expect ( indexes )
157
+ . to . have . property ( 'age_1' )
158
+ . to . deep . equal ( [ [ 'age' , 1 ] ] ) ;
159
+ } ) ;
160
+ } ) ;
161
+ } ) ;
162
+
163
+ describe ( 'Collection.indexExists()' , function ( ) {
164
+ beforeEach ( ( ) => collection . createIndex ( { age : 1 } ) ) ;
165
+ afterEach ( ( ) => collection . dropIndexes ( ) ) ;
166
+
167
+ context ( 'when provided a string index name' , ( ) => {
168
+ it ( 'returns true when the index exists' , async ( ) => {
169
+ expect ( await collection . indexExists ( 'age_1' ) ) . to . be . true ;
170
+ } ) ;
171
+
172
+ it ( 'returns false when the index does not exist' , async ( ) => {
173
+ expect ( await collection . indexExists ( 'name_1' ) ) . to . be . false ;
174
+ } ) ;
175
+ } ) ;
176
+
177
+ context ( 'when provided an array of index names' , ( ) => {
178
+ it ( 'returns true when all indexes exists' , async ( ) => {
179
+ expect ( await collection . indexExists ( [ 'age_1' ] ) ) . to . be . true ;
180
+ } ) ;
181
+
182
+ it ( 'returns false when the none of the indexes exist' , async ( ) => {
183
+ expect ( await collection . indexExists ( [ 'name_1' ] ) ) . to . be . false ;
184
+ } ) ;
185
+
186
+ it ( 'returns false when only some of hte indexes exist' , async ( ) => {
187
+ expect ( await collection . indexExists ( [ 'name_1' , 'age_1' ] ) ) . to . be . false ;
188
+ } ) ;
189
+ } ) ;
190
+ context ( 'when `full` is true' , ( ) => {
191
+ // These tests are broken!
192
+ it ( 'returns true when all indexes exists' , async ( ) => {
193
+ expect ( await collection . indexExists ( [ 'age_1' ] , { full : true } ) ) . to . be . true ;
194
+ } ) ;
195
+
196
+ it ( 'returns false when the none of the indexes exist' , async ( ) => {
197
+ expect ( await collection . indexExists ( [ 'name_1' ] , { full : true } ) ) . to . be . false ;
198
+ } ) ;
199
+
200
+ it ( 'returns false when only some of hte indexes exist' , async ( ) => {
201
+ expect ( await collection . indexExists ( [ 'name_1' , 'age_1' ] , { full : true } ) ) . to . be . false ;
202
+ } ) ;
203
+ } ) ;
204
+
205
+ context ( 'when `full` is false' , ( ) => {
206
+ it ( 'returns true when all indexes exists' , async ( ) => {
207
+ expect ( await collection . indexExists ( [ 'age_1' ] , { full : false } ) ) . to . be . true ;
208
+ } ) ;
209
+
210
+ it ( 'returns false when the none of the indexes exist' , async ( ) => {
211
+ expect ( await collection . indexExists ( [ 'name_1' ] , { full : false } ) ) . to . be . false ;
212
+ } ) ;
213
+
214
+ it ( 'returns false when only some of hte indexes exist' , async ( ) => {
215
+ expect ( await collection . indexExists ( [ 'name_1' , 'age_1' ] , { full : false } ) ) . to . be . false ;
216
+ } ) ;
217
+ } ) ;
218
+ } ) ;
219
+
102
220
it ( 'shouldCorrectlyHandleUniqueIndex' , async function ( ) {
103
221
await db . createCollection ( 'test_unique_index' ) ;
104
222
await db . createIndex ( collection . collectionName , 'hello' , this . configuration . writeConcernMax ( ) ) ;
@@ -529,7 +647,7 @@ describe('Indexes', function () {
529
647
async function ( ) {
530
648
await collection . createIndex ( { 'a.one' : 1 , 'a.two' : 1 } , { name : 'n1' , sparse : false } ) ;
531
649
532
- const err = collection
650
+ const err = await collection
533
651
. createIndex ( { 'a.one' : 1 , 'a.two' : 1 } , { name : 'n2' , sparse : true } )
534
652
. catch ( e => e ) ;
535
653
expect ( err ) . to . be . instanceOf ( Error ) . to . have . property ( 'code' , 85 ) ;
0 commit comments