1
- import { expect } from 'chai' ;
1
+ import { expect , use } from 'chai' ;
2
+ import * as chaiAsPromised from 'chai-as-promised' ;
2
3
import { DefineAttributes } from 'sequelize' ;
3
4
import { Model , Table , Column , DataType } from "../../index" ;
4
5
import { createSequelize } from "../utils/sequelize" ;
5
6
import { User } from "../models/User" ;
6
7
import { getOptions , getAttributes } from "../../lib/services/models" ;
7
8
import { Shoe , SHOE_TABLE_NAME } from "../models/Shoe" ;
9
+ import * as _ from 'lodash' ;
10
+
11
+ use ( chaiAsPromised ) ;
8
12
9
13
/* tslint:disable:max-classes-per-file */
10
14
@@ -29,6 +33,9 @@ describe('table_column', () => {
29
33
username : {
30
34
type : DataType . STRING
31
35
} ,
36
+ username2 : {
37
+ type : DataType . STRING ( 5 )
38
+ } ,
32
39
aNumber : {
33
40
type : DataType . INTEGER
34
41
} ,
@@ -147,7 +154,7 @@ describe('table_column', () => {
147
154
148
155
try {
149
156
150
- expect ( attributes [ key ] ) . to . have . property ( attrOptionKey , expectedUserAttributes [ key ] [ attrOptionKey ] ) ;
157
+ expect ( attributes [ key ] ) . to . have . property ( attrOptionKey ) . that . eql ( expectedUserAttributes [ key ] [ attrOptionKey ] ) ;
151
158
} catch ( e ) {
152
159
153
160
e . message += ` for property "${ key } "` ;
@@ -197,6 +204,38 @@ describe('table_column', () => {
197
204
198
205
} ) ;
199
206
207
+ describe ( 'column' , ( ) => {
208
+
209
+ it ( 'should create appropriate sql query' , ( ) => {
210
+
211
+ const seq = createSequelize ( false ) ;
212
+
213
+ @Table
214
+ class Bottle extends Model < Bottle > {
215
+
216
+ @Column ( DataType . STRING ( 5 ) )
217
+ brand : string ;
218
+
219
+ @Column ( DataType . CHAR ( 2 ) )
220
+ key : string ;
221
+
222
+ @Column ( DataType . INTEGER ( 100 ) )
223
+ num : number ;
224
+ }
225
+
226
+ seq . addModels ( [ Bottle ] ) ;
227
+
228
+ return Bottle . sync ( {
229
+ force : true , logging : _ . after ( 2 , _ . once ( ( sql ) => {
230
+
231
+ // tslint:disable:max-line-length
232
+ expect ( sql ) . to . match ( / C R E A T E T A B L E I F N O T E X I S T S ` B o t t l e ` \( ` i d ` I N T E G E R P R I M A R Y K E Y A U T O I N C R E M E N T , ` b r a n d ` V A R C H A R \( 5 \) , ` k e y ` C H A R \( 2 \) , ` n u m ` I N T E G E R \( 1 0 0 \) \) / ) ;
233
+ } ) )
234
+ } ) ;
235
+ } ) ;
236
+
237
+ } ) ;
238
+
200
239
describe ( 'accessors' , ( ) => {
201
240
202
241
describe ( 'get' , ( ) => {
0 commit comments