-
Notifications
You must be signed in to change notification settings - Fork 281
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7a7d6f7
commit 3532589
Showing
4 changed files
with
155 additions
and
0 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 |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import {expect, use} from 'chai'; | ||
import * as chaiAsPromised from 'chai-as-promised'; | ||
import {Table} from '../../../lib/annotations/Table'; | ||
import {Model} from '../../../lib/models/Model'; | ||
import {createSequelize} from '../../utils/sequelize'; | ||
import {BelongsToMany} from '../../../lib/annotations/association/BelongsToMany'; | ||
|
||
use(chaiAsPromised); | ||
|
||
// tslint:disable:max-classes-per-file | ||
describe('BelongsToMany', () => { | ||
|
||
const as = 'manyTeams'; | ||
const sequelize = createSequelize(false); | ||
|
||
@Table | ||
class Team extends Model<Team> {} | ||
|
||
@Table | ||
class Player extends Model<Player> { | ||
|
||
@BelongsToMany(() => Team, { | ||
as, | ||
through: 'TeamPlayer', | ||
foreignKey: 'playerId', | ||
otherKey: 'teamId', | ||
}) | ||
teams: Team[]; | ||
} | ||
|
||
sequelize.addModels([Team, Player]); | ||
|
||
it('should pass as options to sequelize association', () => { | ||
expect(Player['associations']).to.have.property(as); | ||
}); | ||
|
||
}); |
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,47 @@ | ||
import {expect, use} from 'chai'; | ||
import * as chaiAsPromised from 'chai-as-promised'; | ||
import {Table} from '../../../lib/annotations/Table'; | ||
import {BelongsTo} from '../../../lib/annotations/association/BelongsTo'; | ||
import {Model} from '../../../lib/models/Model'; | ||
import {createSequelize} from '../../utils/sequelize'; | ||
|
||
use(chaiAsPromised); | ||
|
||
// tslint:disable:max-classes-per-file | ||
describe('BelongsTo', () => { | ||
|
||
const as = 'parent'; | ||
const sequelize = createSequelize(false); | ||
|
||
@Table | ||
class Team extends Model<Team> {} | ||
|
||
@Table | ||
class Player extends Model<Player> { | ||
|
||
@BelongsTo(() => Team, {as, foreignKey: 'teamId'}) | ||
team: Team; | ||
} | ||
|
||
sequelize.addModels([Team, Player]); | ||
|
||
it('should pass as options to sequelize association', () => { | ||
expect(Player['associations']).to.have.property(as); | ||
}); | ||
|
||
it('should throw due to missing foreignKey', () => { | ||
const _sequelize = createSequelize(false); | ||
|
||
@Table | ||
class Team extends Model<Team> {} | ||
|
||
@Table | ||
class Player extends Model<Player> { | ||
@BelongsTo(() => Team) | ||
team: Team; | ||
} | ||
|
||
expect(() => _sequelize.addModels([Team, Player])).to.throw(/Foreign key for "\w+" is missing on "\w+"./); | ||
}); | ||
|
||
}); |
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,35 @@ | ||
import {expect, use} from 'chai'; | ||
import * as chaiAsPromised from 'chai-as-promised'; | ||
import {Table} from '../../../lib/annotations/Table'; | ||
import {Model} from '../../../lib/models/Model'; | ||
import {createSequelize} from '../../utils/sequelize'; | ||
import {HasMany} from '../../../lib/annotations/association/HasMany'; | ||
|
||
use(chaiAsPromised); | ||
|
||
// tslint:disable:max-classes-per-file | ||
describe('HasMany', () => { | ||
|
||
const as = 'babies'; | ||
const sequelize = createSequelize(false); | ||
|
||
@Table | ||
class Player extends Model<Player> {} | ||
|
||
@Table | ||
class Team extends Model<Team> { | ||
|
||
@HasMany(() => Player, { | ||
as, | ||
foreignKey: 'teamId' | ||
}) | ||
players: Player[]; | ||
} | ||
|
||
sequelize.addModels([Team, Player]); | ||
|
||
it('should pass as options to sequelize association', () => { | ||
expect(Team['associations']).to.have.property(as); | ||
}); | ||
|
||
}); |
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,36 @@ | ||
import {expect, use} from 'chai'; | ||
import * as chaiAsPromised from 'chai-as-promised'; | ||
import {Table} from '../../../lib/annotations/Table'; | ||
import {Model} from '../../../lib/models/Model'; | ||
import {createSequelize} from '../../utils/sequelize'; | ||
import {HasOne} from '../../../lib/annotations/association/HasOne'; | ||
|
||
use(chaiAsPromised); | ||
|
||
// tslint:disable:max-classes-per-file | ||
describe('HasOne', () => { | ||
|
||
const as = 'baby'; | ||
const sequelize = createSequelize(false); | ||
|
||
@Table | ||
class Player extends Model<Player> {} | ||
|
||
@Table | ||
class Team extends Model<Team> { | ||
|
||
@HasOne(() => Player, { | ||
as, | ||
foreignKey: 'teamId' | ||
}) | ||
player: Player; | ||
} | ||
|
||
|
||
sequelize.addModels([Team, Player]); | ||
|
||
it('should pass as options to sequelize association', () => { | ||
expect(Team['associations']).to.have.property(as); | ||
}); | ||
|
||
}); |