1
1
import * as expect from 'expect'
2
2
import StorageManager from '.'
3
- import { StorageBackend , FieldType , CollectionFields , Relationship , PrimitiveFieldType } from './types'
3
+ import { StorageBackend , FieldType , CollectionFields , Relationship , PrimitiveFieldType , CollectionDefinitionMap } from './types'
4
4
import { StorageBackendFeatureSupport } from './types/backend-features' ;
5
5
import { FieldTypeRegistry } from './fields' ;
6
6
import { Field } from './fields/types' ;
@@ -276,7 +276,7 @@ export function testStorageBackendOperations(backendCreator : StorexBackendTestB
276
276
const relationshipType = options . relationshipType || 'childOf'
277
277
278
278
const storageManager = new StorageManager ( { backend : options . backend } )
279
- storageManager . registry . registerCollections ( {
279
+ const collectionDefinitions : CollectionDefinitionMap = {
280
280
user : {
281
281
version : new Date ( 2019 , 1 , 1 ) ,
282
282
fields : options . userFields || {
@@ -292,7 +292,24 @@ export function testStorageBackendOperations(backendCreator : StorexBackendTestB
292
292
{ [ relationshipType as any ] : 'user' , ...relationshipOptions } as any
293
293
]
294
294
}
295
- } )
295
+ }
296
+
297
+ if ( options . backend . supports ( 'compoundPrimaryKeys' ) ) {
298
+ collectionDefinitions . tag = {
299
+ version : new Date ( 2019 , 1 , 1 ) ,
300
+ fields : {
301
+ name : { type : 'string' } ,
302
+ } ,
303
+ relationships : [
304
+ { childOf : 'email' , reverseAlias : 'tags' , alias : 'email' } ,
305
+ ] ,
306
+ indices : [
307
+ { field : [ 'name' , 'email' ] , pk : true } ,
308
+ ] ,
309
+ }
310
+ }
311
+
312
+ storageManager . registry . registerCollections ( collectionDefinitions )
296
313
await storageManager . finishInitialization ( )
297
314
await storageManager . backend . migrate ( )
298
315
return { storageManager }
@@ -621,7 +638,27 @@ export function testStorageBackendOperations(backendCreator : StorexBackendTestB
621
638
await storageManager . operation ( 'executeBatch' , [ ] )
622
639
} )
623
640
624
- it ( 'should support batch operations with compound primary keys' )
641
+ it ( 'should support batch operations with compound primary keys' , { shouldSupport : [ 'compoundPrimaryKeys' ] } , async function ( context ) {
642
+ const { storageManager } = await setupChildOfTest ( { backend : context . backend } )
643
+ expect ( storageManager . registry . collections [ 'tag' ] . pkIndex )
644
+ . toEqual ( expect . arrayContaining ( [ 'name' , 'email' ] ) )
645
+
646
+ const { object : user1 } = await storageManager . collection ( 'user' ) . createObject ( { displayName : 'Jack' } )
647
+ const { object :
email1 } = await storageManager . collection ( 'email' ) . createObject ( { user :
user1 . id , address :
'[email protected] ' } )
648
+
649
+ await storageManager . operation ( 'executeBatch' , [
650
+ { operation : 'createObject' , collection : 'tag' , args : { email : email1 . id , name : 'cool' } } ,
651
+ { operation : 'createObject' , collection : 'tag' , args : { email : email1 . id , name : 'groovy' } } ,
652
+ { operation : 'createObject' , collection : 'tag' , args : { email : email1 . id , name : 'rad' } } ,
653
+ ] )
654
+
655
+ expect ( await storageManager . collection ( 'tag' ) . findObjects ( { email : email1 . id } ) )
656
+ . toEqual ( expect . arrayContaining ( [
657
+ { email : email1 . id , name : 'cool' } ,
658
+ { email : email1 . id , name : 'groovy' } ,
659
+ { email : email1 . id , name : 'rad' } ,
660
+ ] ) )
661
+ } )
625
662
626
663
it ( 'should support batches with updateObjects operations' , { shouldSupport : [ 'executeBatch' ] } , async function ( context : TestContext ) {
627
664
const { storageManager } = await setupChildOfTest ( { backend : context . backend } )
0 commit comments