Skip to content

Commit

Permalink
fixup! apply feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
nabdelgadir committed Sep 16, 2019
1 parent 24dfb32 commit d1613b9
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('keyTo and keyFrom with resolveHasManyMetadata', () => {
});
});

it('infers keyTo if is it not provided', () => {
it('infers keyTo if it is not provided', () => {
const meta = resolveHasManyMetadata(Category.definition.relations[
'things'
] as HasManyDefinition);
Expand All @@ -62,7 +62,7 @@ describe('keyTo and keyFrom with resolveHasManyMetadata', () => {
});
});

it('throws if both keyFrom and keyTo are not provided', async () => {
it('throws if keyFrom, keyTo, and default foreign key name are not provided', async () => {
let error;

try {
Expand All @@ -81,6 +81,24 @@ describe('keyTo and keyFrom with resolveHasManyMetadata', () => {
expect(error.code).to.eql('INVALID_RELATION_DEFINITION');
});

it('resolves metadata if keyTo and keyFrom are not provided, but default foreign key is', async () => {
Category.definition.addProperty('categoryId', {type: 'number'});

const meta = resolveHasManyMetadata(Category.definition.relations[
'categories'
] as HasManyDefinition);

expect(meta).to.eql({
name: 'categories',
type: 'hasMany',
targetsMany: true,
source: Category,
keyFrom: 'id',
target: () => Category,
keyTo: 'categoryId',
});
});

/****** HELPERS *******/

class Category extends Entity {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('keyTo and keyFrom with resolveHasOneMetadata', () => {
});
});

it('infers keyTo if is it not provided', () => {
it('infers keyTo if it is not provided', () => {
const meta = resolveHasOneMetadata(Category.definition.relations[
'thing'
] as HasOneDefinition);
Expand All @@ -62,7 +62,7 @@ describe('keyTo and keyFrom with resolveHasOneMetadata', () => {
});
});

it('throws if both keyFrom and keyTo are not provided', async () => {
it('throws if keyFrom, keyTo, and default foreign key name are not provided', async () => {
let error;

try {
Expand All @@ -81,6 +81,24 @@ describe('keyTo and keyFrom with resolveHasOneMetadata', () => {
expect(error.code).to.eql('INVALID_RELATION_DEFINITION');
});

it('resolves metadata if keyTo and keyFrom are not provided, but default foreign key is', async () => {
Category.definition.addProperty('categoryId', {type: 'number'});

const meta = resolveHasOneMetadata(Category.definition.relations[
'category'
] as HasOneDefinition);

expect(meta).to.eql({
name: 'category',
type: 'hasOne',
targetsMany: false,
source: Category,
keyFrom: 'id',
target: () => Category,
keyTo: 'categoryId',
});
});

/****** HELPERS *******/

class Category extends Entity {}
Expand Down

0 comments on commit d1613b9

Please sign in to comment.