@@ -222,4 +222,72 @@ describe('Client Side Encryption Functional', function () {
222
222
} ) ;
223
223
} ) ;
224
224
} ) ;
225
+
226
+ describe ( 'key order aware command properties' , ( ) => {
227
+ let client ;
228
+ let collection ;
229
+
230
+ beforeEach ( async function ( ) {
231
+ const encryptionOptions = {
232
+ monitorCommands : true ,
233
+ autoEncryption : {
234
+ keyVaultNamespace,
235
+ kmsProviders : { local : { key : 'A' . repeat ( 128 ) } }
236
+ }
237
+ } ;
238
+ client = this . configuration . newClient ( { } , encryptionOptions ) ;
239
+ collection = client . db ( dataDbName ) . collection ( 'keyOrder' ) ;
240
+ } ) ;
241
+
242
+ afterEach ( async ( ) => {
243
+ if ( client ) await client . close ( ) ;
244
+ } ) ;
245
+
246
+ describe ( 'find' , ( ) => {
247
+ it ( 'should maintain ordered sort' , async function ( ) {
248
+ const events = [ ] ;
249
+ client . on ( 'commandStarted' , ev => events . push ( ev ) ) ;
250
+ const sort = new Map ( [
251
+ [ '1' , 1 ] ,
252
+ [ '0' , 1 ]
253
+ ] ) ;
254
+ await collection . findOne ( { } , { sort } ) ;
255
+ const findEvent = events . find ( event => ! ! event . command . find ) ;
256
+ expect ( findEvent ) . to . have . property ( 'commandName' , 'find' ) ;
257
+ expect ( findEvent . command . sort ) . to . deep . equal ( sort ) ;
258
+ } ) ;
259
+ } ) ;
260
+
261
+ describe ( 'findAndModify' , ( ) => {
262
+ it ( 'should maintain ordered sort' , async function ( ) {
263
+ const events = [ ] ;
264
+ client . on ( 'commandStarted' , ev => events . push ( ev ) ) ;
265
+ const sort = new Map ( [
266
+ [ '1' , 1 ] ,
267
+ [ '0' , 1 ]
268
+ ] ) ;
269
+ await collection . findOneAndUpdate ( { } , { $setOnInsert : { a : 1 } } , { sort } ) ;
270
+ const findAndModifyEvent = events . find ( event => ! ! event . command . findAndModify ) ;
271
+ expect ( findAndModifyEvent ) . to . have . property ( 'commandName' , 'findAndModify' ) ;
272
+ expect ( findAndModifyEvent . command . sort ) . to . deep . equal ( sort ) ;
273
+ } ) ;
274
+ } ) ;
275
+
276
+ describe ( 'createIndexes' , ( ) => {
277
+ it ( 'should maintain ordered index keys' , async function ( ) {
278
+ const events = [ ] ;
279
+ client . on ( 'commandStarted' , ev => events . push ( ev ) ) ;
280
+ const indexDescription = new Map ( [
281
+ [ '1' , 1 ] ,
282
+ [ '0' , 1 ]
283
+ ] ) ;
284
+ await collection . createIndex ( indexDescription , { name : 'myIndex' } ) ;
285
+ const createIndexEvent = events . find ( event => ! ! event . command . createIndexes ) ;
286
+ expect ( createIndexEvent ) . to . have . property ( 'commandName' , 'createIndexes' ) ;
287
+ expect ( createIndexEvent . command . indexes ) . to . have . lengthOf ( 1 ) ;
288
+ const index = createIndexEvent . command . indexes [ 0 ] ;
289
+ expect ( index . key ) . to . deep . equal ( indexDescription ) ;
290
+ } ) ;
291
+ } ) ;
292
+ } ) ;
225
293
} ) ;
0 commit comments