1+ import { Builder } from '../../src/builder' ;
2+ import { Generators } from '../../src/generation/generators/generators' ;
13import { CustomSchema } from '../../src/schema/custom-schema.class' ;
2- import { Schema , Table , Column } from '../../src/schema/schema.class' ;
34import { CustomizedSchema } from '../../src/schema/customized-schema.class' ;
4- import { Generators } from '../../src/generation/generators/generators' ;
5- import { Builder } from '../../src/builder' ;
5+ import { Column , Schema , Table } from '../../src/schema/schema.class' ;
66
77describe ( 'CustomizedSchema' , ( ) => {
88 it ( 'handle missing custom table' , async ( ) => {
@@ -94,6 +94,69 @@ describe('CustomizedSchema', () => {
9494 schema . tables = [ table ] ;
9595
9696 const customSchema = new CustomSchema ( ) ;
97+ customSchema . tables = [ {
98+ name : 'table1' ,
99+ maxLines : 100 ,
100+ columns : [
101+ {
102+ name : 'column1' ,
103+ max : 10 ,
104+ values : [ ] ,
105+ } ,
106+ ] ,
107+ } ] ;
108+ const result = CustomizedSchema . create ( schema , customSchema ) ;
109+ expect ( result . tables [ 0 ] . columns [ 0 ] . max ) . toBe ( 10 ) ;
110+ } ) ;
111+ it ( 'Column options takes in account default maxLengthValue' , async ( ) => {
112+ const column = new Builder ( Column )
113+ . set ( 'name' , 'column1' )
114+ . set ( 'generator' , Generators . string )
115+ . build ( ) ;
116+
117+ const table = new Builder ( Table )
118+ . set ( 'name' , 'table1' )
119+ . set ( 'columns' , [
120+ column ,
121+ ] )
122+ . build ( ) ;
123+
124+ const schema = new Schema ( ) ;
125+ schema . tables = [ table ] ;
126+
127+ const customSchema = new CustomSchema ( ) ;
128+ customSchema . tables = [ {
129+ name : 'table1' ,
130+ maxLines : 100 ,
131+ columns : [
132+ {
133+ name : 'column1' ,
134+ max : 100 ,
135+ values : [ ] ,
136+ } ,
137+ ] ,
138+ } ] ;
139+ const result = CustomizedSchema . create ( schema , customSchema ) ;
140+ expect ( result . tables [ 0 ] . columns [ 0 ] . max ) . toBe ( 36 ) ;
141+ } ) ;
142+ it ( 'Column options do not override maxLengthValue' , async ( ) => {
143+ const column = new Builder ( Column )
144+ . set ( 'name' , 'column1' )
145+ . set ( 'generator' , Generators . string )
146+ . build ( ) ;
147+
148+ const table = new Builder ( Table )
149+ . set ( 'name' , 'table1' )
150+ . set ( 'columns' , [
151+ column ,
152+ ] )
153+ . build ( ) ;
154+
155+ const schema = new Schema ( ) ;
156+ schema . tables = [ table ] ;
157+
158+ const customSchema = new CustomSchema ( ) ;
159+ customSchema . settings . maxLengthValue = 42 ;
97160 customSchema . tables = [ {
98161 name : 'table1' ,
99162 maxLines : 100 ,
@@ -106,7 +169,7 @@ describe('CustomizedSchema', () => {
106169 ] ,
107170 } ] ;
108171 const result = CustomizedSchema . create ( schema , customSchema ) ;
109- expect ( result . tables [ 0 ] . columns [ 0 ] . max ) . toBe ( 100 ) ;
172+ expect ( result . tables [ 0 ] . columns [ 0 ] . max ) . toBe ( 42 ) ;
110173 } ) ;
111174 it ( 'reorder columns' , async ( ) => {
112175 const columns = [
0 commit comments