File tree Expand file tree Collapse file tree 4 files changed +155
-0
lines changed Expand file tree Collapse file tree 4 files changed +155
-0
lines changed Original file line number Diff line number Diff line change
1
+ import { expect , use } from 'chai' ;
2
+ import * as chaiAsPromised from 'chai-as-promised' ;
3
+ import { Table } from '../../../lib/annotations/Table' ;
4
+ import { Model } from '../../../lib/models/Model' ;
5
+ import { createSequelize } from '../../utils/sequelize' ;
6
+ import { BelongsToMany } from '../../../lib/annotations/association/BelongsToMany' ;
7
+
8
+ use ( chaiAsPromised ) ;
9
+
10
+ // tslint:disable:max-classes-per-file
11
+ describe ( 'BelongsToMany' , ( ) => {
12
+
13
+ const as = 'manyTeams' ;
14
+ const sequelize = createSequelize ( false ) ;
15
+
16
+ @Table
17
+ class Team extends Model < Team > { }
18
+
19
+ @Table
20
+ class Player extends Model < Player > {
21
+
22
+ @BelongsToMany ( ( ) => Team , {
23
+ as,
24
+ through : 'TeamPlayer' ,
25
+ foreignKey : 'playerId' ,
26
+ otherKey : 'teamId' ,
27
+ } )
28
+ teams : Team [ ] ;
29
+ }
30
+
31
+ sequelize . addModels ( [ Team , Player ] ) ;
32
+
33
+ it ( 'should pass as options to sequelize association' , ( ) => {
34
+ expect ( Player [ 'associations' ] ) . to . have . property ( as ) ;
35
+ } ) ;
36
+
37
+ } ) ;
Original file line number Diff line number Diff line change
1
+ import { expect , use } from 'chai' ;
2
+ import * as chaiAsPromised from 'chai-as-promised' ;
3
+ import { Table } from '../../../lib/annotations/Table' ;
4
+ import { BelongsTo } from '../../../lib/annotations/association/BelongsTo' ;
5
+ import { Model } from '../../../lib/models/Model' ;
6
+ import { createSequelize } from '../../utils/sequelize' ;
7
+
8
+ use ( chaiAsPromised ) ;
9
+
10
+ // tslint:disable:max-classes-per-file
11
+ describe ( 'BelongsTo' , ( ) => {
12
+
13
+ const as = 'parent' ;
14
+ const sequelize = createSequelize ( false ) ;
15
+
16
+ @Table
17
+ class Team extends Model < Team > { }
18
+
19
+ @Table
20
+ class Player extends Model < Player > {
21
+
22
+ @BelongsTo ( ( ) => Team , { as, foreignKey : 'teamId' } )
23
+ team : Team ;
24
+ }
25
+
26
+ sequelize . addModels ( [ Team , Player ] ) ;
27
+
28
+ it ( 'should pass as options to sequelize association' , ( ) => {
29
+ expect ( Player [ 'associations' ] ) . to . have . property ( as ) ;
30
+ } ) ;
31
+
32
+ it ( 'should throw due to missing foreignKey' , ( ) => {
33
+ const _sequelize = createSequelize ( false ) ;
34
+
35
+ @Table
36
+ class Team extends Model < Team > { }
37
+
38
+ @Table
39
+ class Player extends Model < Player > {
40
+ @BelongsTo ( ( ) => Team )
41
+ team : Team ;
42
+ }
43
+
44
+ expect ( ( ) => _sequelize . addModels ( [ Team , Player ] ) ) . to . throw ( / F o r e i g n k e y f o r " \w + " i s m i s s i n g o n " \w + " ./ ) ;
45
+ } ) ;
46
+
47
+ } ) ;
Original file line number Diff line number Diff line change
1
+ import { expect , use } from 'chai' ;
2
+ import * as chaiAsPromised from 'chai-as-promised' ;
3
+ import { Table } from '../../../lib/annotations/Table' ;
4
+ import { Model } from '../../../lib/models/Model' ;
5
+ import { createSequelize } from '../../utils/sequelize' ;
6
+ import { HasMany } from '../../../lib/annotations/association/HasMany' ;
7
+
8
+ use ( chaiAsPromised ) ;
9
+
10
+ // tslint:disable:max-classes-per-file
11
+ describe ( 'HasMany' , ( ) => {
12
+
13
+ const as = 'babies' ;
14
+ const sequelize = createSequelize ( false ) ;
15
+
16
+ @Table
17
+ class Player extends Model < Player > { }
18
+
19
+ @Table
20
+ class Team extends Model < Team > {
21
+
22
+ @HasMany ( ( ) => Player , {
23
+ as,
24
+ foreignKey : 'teamId'
25
+ } )
26
+ players : Player [ ] ;
27
+ }
28
+
29
+ sequelize . addModels ( [ Team , Player ] ) ;
30
+
31
+ it ( 'should pass as options to sequelize association' , ( ) => {
32
+ expect ( Team [ 'associations' ] ) . to . have . property ( as ) ;
33
+ } ) ;
34
+
35
+ } ) ;
Original file line number Diff line number Diff line change
1
+ import { expect , use } from 'chai' ;
2
+ import * as chaiAsPromised from 'chai-as-promised' ;
3
+ import { Table } from '../../../lib/annotations/Table' ;
4
+ import { Model } from '../../../lib/models/Model' ;
5
+ import { createSequelize } from '../../utils/sequelize' ;
6
+ import { HasOne } from '../../../lib/annotations/association/HasOne' ;
7
+
8
+ use ( chaiAsPromised ) ;
9
+
10
+ // tslint:disable:max-classes-per-file
11
+ describe ( 'HasOne' , ( ) => {
12
+
13
+ const as = 'baby' ;
14
+ const sequelize = createSequelize ( false ) ;
15
+
16
+ @Table
17
+ class Player extends Model < Player > { }
18
+
19
+ @Table
20
+ class Team extends Model < Team > {
21
+
22
+ @HasOne ( ( ) => Player , {
23
+ as,
24
+ foreignKey : 'teamId'
25
+ } )
26
+ player : Player ;
27
+ }
28
+
29
+
30
+ sequelize . addModels ( [ Team , Player ] ) ;
31
+
32
+ it ( 'should pass as options to sequelize association' , ( ) => {
33
+ expect ( Team [ 'associations' ] ) . to . have . property ( as ) ;
34
+ } ) ;
35
+
36
+ } ) ;
You can’t perform that action at this time.
0 commit comments