-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for compound PKs in test suite
- also added new backend feature support flag to check support of
- Loading branch information
Showing
2 changed files
with
43 additions
and
4 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -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'; | ||
|
@@ -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 || { | ||
|
@@ -292,7 +292,25 @@ 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', pk: true }, | ||
{ field: 'email', pk: true }, | ||
], | ||
} | ||
} | ||
|
||
storageManager.registry.registerCollections(collectionDefinitions) | ||
await storageManager.finishInitialization() | ||
await storageManager.backend.migrate() | ||
return { storageManager } | ||
|
@@ -621,7 +639,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: '[email protected]' }) | ||
|
||
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 }) | ||
|
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