-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(repository): verify relation type in
resolve{Relation}Metadata
- Loading branch information
1 parent
d065e7d
commit d814165
Showing
3 changed files
with
226 additions
and
140 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
...ository/src/__tests__/integration/repositories/resolve-belongs-to-metadata.integration.ts
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,42 @@ | ||
// Copyright IBM Corp. 2019. All Rights Reserved. | ||
// Node module: @loopback/repository | ||
// This file is licensed under the MIT License. | ||
// License text available at https://opensource.org/licenses/MIT | ||
|
||
import {expect} from '@loopback/testlab'; | ||
import { | ||
BelongsToDefinition, | ||
Entity, | ||
ModelDefinition, | ||
RelationType, | ||
} from '../../..'; | ||
import {resolveBelongsToMetadata} from '../../../relations/belongs-to/belongs-to.helpers'; | ||
|
||
describe('resolveBelongsToMetadata', () => { | ||
it('throws if the wrong metadata type is used', async () => { | ||
expect(() => { | ||
resolveBelongsToMetadata(Category.definition.relations[ | ||
'category' | ||
] as BelongsToDefinition); | ||
}).to.throw( | ||
/Invalid hasOne definition for Category#category: relation type must be BelongsTo/, | ||
); | ||
}); | ||
|
||
/****** HELPERS *******/ | ||
class Category extends Entity {} | ||
|
||
Category.definition = new ModelDefinition('Category') | ||
.addProperty('id', {type: 'number', id: true, required: true}) | ||
// need <unknown> to avoid Type 'RelationType.hasOne' is not comparable | ||
// to type 'RelationType.belongsTo' | ||
.addRelation(<BelongsToDefinition>(<unknown>{ | ||
name: 'category', | ||
type: RelationType.hasOne, | ||
targetsMany: false, | ||
source: Category, | ||
keyFrom: 'id', | ||
target: () => Category, | ||
keyTo: 'categoryId', | ||
})); | ||
}); |
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
Oops, something went wrong.