-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(decorator): add tests for model decorator
1 parent
eeeca92
commit a27e8e7
Showing
4 changed files
with
114 additions
and
1 deletion.
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 |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// tslint:disable:max-classes-per-file | ||
import { GSIPartitionKey } from '../index/gsi-partition-key.decorator' | ||
import { GSISortKey } from '../index/gsi-sort-key.decorator' | ||
import { LSISortKey } from '../index/lsi-sort-key.decorator' | ||
import { PartitionKey } from '../key/partition-key.decorator' | ||
import { modelErrors } from './errors.const' | ||
import { Model } from './model.decorator' | ||
|
||
const IX_NAME = 'anIndexName' | ||
|
||
describe('@model decorator', () => { | ||
describe('getGlobalSecondaryIndexes', () => { | ||
// throws on applying decorator | ||
|
||
it('throws when defining multiple partitionKeys for same gsi', () => { | ||
expect(() => { | ||
// @ts-ignore | ||
@Model() | ||
class FailModel { | ||
@GSIPartitionKey(IX_NAME) | ||
pk1: string | ||
@GSIPartitionKey(IX_NAME) | ||
pk2: string | ||
@GSISortKey(IX_NAME) | ||
sk1: string | ||
} | ||
}).toThrow(modelErrors.gsiMultiplePk(IX_NAME, 'pk2')) | ||
}) | ||
it('throws when defining multiple sortKeys for same gsi', () => { | ||
expect(() => { | ||
// @ts-ignore | ||
@Model() | ||
class FailModel { | ||
@GSIPartitionKey(IX_NAME) | ||
pk1: string | ||
@GSISortKey(IX_NAME) | ||
sk1: string | ||
@GSISortKey(IX_NAME) | ||
sk2: string | ||
} | ||
}).toThrow(modelErrors.gsiMultipleSk(IX_NAME, 'sk2')) | ||
}) | ||
}) | ||
describe('getLocalSecondaryIndexes', () => { | ||
it('throws when defining LSI sortKey but no PartitionKey', () => { | ||
expect(() => { | ||
// @ts-ignore | ||
@Model() | ||
class FailModel { | ||
@LSISortKey(IX_NAME) | ||
sk1: string | ||
} | ||
}).toThrow(modelErrors.lsiRequiresPk(IX_NAME, 'sk1')) | ||
}) | ||
it('throws when defining multiple sortKeys for same lsi', () => { | ||
expect(() => { | ||
// @ts-ignore | ||
@Model() | ||
class FailModel { | ||
@PartitionKey() | ||
pk1: string | ||
@LSISortKey(IX_NAME) | ||
sk1: string | ||
@LSISortKey(IX_NAME) | ||
sk2: string | ||
} | ||
}).toThrow(modelErrors.lsiMultipleSk(IX_NAME, 'sk2')) | ||
}) | ||
}) | ||
}) |
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
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
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
import { GSISortKey } from '../../src/decorator/impl/index/gsi-sort-key.decorator' | ||
import { Model } from '../../src/decorator/impl/model/model.decorator' | ||
import { Property } from '../../src/decorator/impl/property/property.decorator' | ||
|
||
export const FAIL_MODEL_GSI = 'failModelGsi' | ||
|
||
@Model() | ||
export class ModelWithoutPartitionKeyModel { | ||
@Property() | ||
name: string | ||
|
||
@GSISortKey(FAIL_MODEL_GSI) | ||
gsiRange: string | ||
} |