Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for compound PK batch ops in test suite #16

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 41 additions & 4 deletions ts/index.tests.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as expect from 'expect'
import StorageManager from '.'
import { StorageBackend, FieldType, CollectionFields, Relationship, PrimitiveFieldType } from './types'
import { StorageBackend, FieldType, CollectionFields, Relationship, PrimitiveFieldType, CollectionDefinitionMap } from './types'
import { StorageBackendFeatureSupport } from './types/backend-features';
import { FieldTypeRegistry } from './fields';
import { Field } from './fields/types';
Expand Down Expand Up @@ -276,7 +276,7 @@ export function testStorageBackendOperations(backendCreator : StorexBackendTestB
const relationshipType = options.relationshipType || 'childOf'

const storageManager = new StorageManager({ backend: options.backend })
storageManager.registry.registerCollections({
const collectionDefinitions: CollectionDefinitionMap = {
user: {
version: new Date(2019, 1, 1),
fields: options.userFields || {
Expand All @@ -292,7 +292,24 @@ export function testStorageBackendOperations(backendCreator : StorexBackendTestB
{ [relationshipType as any]: 'user', ...relationshipOptions } as any
]
}
})
}

if (options.backend.supports('compoundPrimaryKeys')) {
collectionDefinitions.tag = {
version: new Date(2019, 1, 1),
fields: {
name: { type: 'string' },
},
relationships: [
{ childOf: 'email', reverseAlias: 'tags', alias: 'email' },
],
indices: [
{ field: ['name', 'email'], pk: true },
],
}
}

storageManager.registry.registerCollections(collectionDefinitions)
await storageManager.finishInitialization()
await storageManager.backend.migrate()
return { storageManager }
Expand Down Expand Up @@ -621,7 +638,27 @@ export function testStorageBackendOperations(backendCreator : StorexBackendTestB
await storageManager.operation('executeBatch', [])
})

it('should support batch operations with compound primary keys')
it('should support batch operations with compound primary keys', { shouldSupport: ['compoundPrimaryKeys'] }, async function (context) {
const { storageManager } = await setupChildOfTest({ backend: context.backend })
expect(storageManager.registry.collections['tag'].pkIndex)
.toEqual(expect.arrayContaining(['name', 'email']))

const { object: user1 } = await storageManager.collection('user').createObject({displayName: 'Jack'})
const { object: email1 } = await storageManager.collection('email').createObject({ user: user1.id, address: 'jack@jack.com' })

await storageManager.operation('executeBatch', [
{ operation: 'createObject', collection: 'tag', args: { email: email1.id, name: 'cool' } },
{ operation: 'createObject', collection: 'tag', args: { email: email1.id, name: 'groovy' } },
{ operation: 'createObject', collection: 'tag', args: { email: email1.id, name: 'rad' } },
])

expect(await storageManager.collection('tag').findObjects({ email: email1.id }))
.toEqual(expect.arrayContaining([
{ email: email1.id, name: 'cool' },
{ email: email1.id, name: 'groovy' },
{ email: email1.id, name: 'rad' },
]))
})

it('should support batches with updateObjects operations', { shouldSupport: ['executeBatch'] }, async function (context : TestContext) {
const { storageManager } = await setupChildOfTest({ backend: context.backend })
Expand Down
1 change: 1 addition & 0 deletions ts/types/backend-features.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export interface StorageBackendFeatureSupport {
updateWithRelationships? : boolean
relationshipFetching? : boolean
crossRelationshipQueries? : boolean
compoundPrimaryKeys?: boolean
executeBatch? : boolean
batchCreates? : boolean
resultLimiting? : boolean
Expand Down