11import { prepareCompiler } from './PrepareCompiler' ;
22
3- describe ( 'Schema Testing' , ( ) => {
4- const schemaCompile = async ( ) => {
5- const { compiler, cubeEvaluator } = prepareCompiler ( `
3+ export function makeCubeSchema ( { preAggregations } ) {
4+ return `
65 cube('CubeA', {
76 sql: \`select * from test\`,
87
@@ -35,29 +34,58 @@ describe('Schema Testing', () => {
3534 },
3635
3736 preAggregations: {
38- main: {
37+ ${ preAggregations }
38+ },
39+ })
40+ ` ;
41+ }
42+
43+ describe ( 'Schema Testing' , ( ) => {
44+ const schemaCompile = async ( ) => {
45+ const { compiler, cubeEvaluator } = prepareCompiler (
46+ makeCubeSchema ( {
47+ preAggregations : `
48+ main: {
3949 type: 'originalSql',
4050 timeDimension: createdAt,
4151 partitionGranularity: \`month\`,
52+ refreshRangeStart: {
53+ sql: 'SELECT NOW()',
54+ },
55+ refreshRangeEnd: {
56+ sql: 'SELECT NOW()',
57+ }
4258 },
4359 // Pre-aggregation without type, rollup is used by default
4460 countCreatedAt: {
4561 measureReferences: [count],
4662 timeDimensionReference: createdAt,
4763 granularity: \`day\`,
48- partitionGranularity: \`month\`
64+ partitionGranularity: \`month\`,
65+ buildRangeStart: {
66+ sql: 'SELECT NOW()',
67+ },
68+ buildRangeEnd: {
69+ sql: 'SELECT NOW()',
70+ }
4971 },
5072 countCreatedAtWithoutReferences: {
5173 dimensions: [type],
5274 measures: [count],
5375 timeDimension: [createdAt],
5476 segments: [sfUsers],
5577 granularity: \`day\`,
56- partitionGranularity: \`month\`
78+ partitionGranularity: \`month\`,
79+ buildRangeStart: {
80+ sql: 'SELECT NOW()',
81+ },
82+ buildRangeEnd: {
83+ sql: 'SELECT NOW()',
84+ }
5785 }
58- },
59- })
60- ` ) ;
86+ `
87+ } )
88+ ) ;
6189 await compiler . compile ( ) ;
6290
6391 return { compiler, cubeEvaluator } ;
@@ -73,6 +101,12 @@ describe('Schema Testing', () => {
73101 timeDimensionReference : expect . any ( Function ) ,
74102 partitionGranularity : 'month' ,
75103 type : 'originalSql' ,
104+ refreshRangeStart : {
105+ sql : expect . any ( Function ) ,
106+ } ,
107+ refreshRangeEnd : {
108+ sql : expect . any ( Function ) ,
109+ } ,
76110 } ,
77111 countCreatedAt : {
78112 external : false ,
@@ -82,6 +116,12 @@ describe('Schema Testing', () => {
82116 timeDimensionReference : expect . any ( Function ) ,
83117 partitionGranularity : 'month' ,
84118 type : 'rollup' ,
119+ refreshRangeStart : {
120+ sql : expect . any ( Function ) ,
121+ } ,
122+ refreshRangeEnd : {
123+ sql : expect . any ( Function ) ,
124+ } ,
85125 } ,
86126 countCreatedAtWithoutReferences : {
87127 // because preview
@@ -94,6 +134,12 @@ describe('Schema Testing', () => {
94134 dimensionReferences : expect . any ( Function ) ,
95135 partitionGranularity : 'month' ,
96136 type : 'rollup' ,
137+ refreshRangeStart : {
138+ sql : expect . any ( Function ) ,
139+ } ,
140+ refreshRangeEnd : {
141+ sql : expect . any ( Function ) ,
142+ } ,
97143 }
98144 } ) ;
99145 } ) ;
@@ -114,6 +160,12 @@ describe('Schema Testing', () => {
114160 timeDimensionReference : expect . any ( Function ) ,
115161 partitionGranularity : 'month' ,
116162 type : 'originalSql' ,
163+ refreshRangeStart : {
164+ sql : expect . any ( Function ) ,
165+ } ,
166+ refreshRangeEnd : {
167+ sql : expect . any ( Function ) ,
168+ } ,
117169 } ,
118170 countCreatedAt : {
119171 // because preview
@@ -124,6 +176,12 @@ describe('Schema Testing', () => {
124176 timeDimensionReference : expect . any ( Function ) ,
125177 partitionGranularity : 'month' ,
126178 type : 'rollup' ,
179+ refreshRangeStart : {
180+ sql : expect . any ( Function ) ,
181+ } ,
182+ refreshRangeEnd : {
183+ sql : expect . any ( Function ) ,
184+ } ,
127185 } ,
128186 countCreatedAtWithoutReferences : {
129187 // because preview
@@ -136,7 +194,58 @@ describe('Schema Testing', () => {
136194 timeDimensionReference : expect . any ( Function ) ,
137195 partitionGranularity : 'month' ,
138196 type : 'rollup' ,
197+ refreshRangeStart : {
198+ sql : expect . any ( Function ) ,
199+ } ,
200+ refreshRangeEnd : {
201+ sql : expect . any ( Function ) ,
202+ } ,
139203 }
140204 } ) ;
141205 } ) ;
206+
207+ it ( 'invalid schema' , async ( ) => {
208+ const logger = jest . fn ( ) ;
209+
210+ const { compiler } = prepareCompiler (
211+ makeCubeSchema ( {
212+ preAggregations : `
213+ main: {
214+ type: 'originalSql',
215+ timeDimension: createdAt,
216+ partitionGranularity: \`month\`,
217+ refreshRangeStart: {
218+ sql: 'SELECT NOW()',
219+ },
220+ buildRangeStart: {
221+ sql: 'SELECT NOW()',
222+ },
223+ refreshRangeEnd: {
224+ sql: 'SELECT NOW()',
225+ },
226+ buildRangeEnd: {
227+ sql: 'SELECT NOW()',
228+ }
229+ },
230+ `
231+ } ) ,
232+ {
233+ omitErrors : true ,
234+ errorReport : {
235+ logger,
236+ }
237+ }
238+ ) ;
239+
240+ await compiler . compile ( ) ;
241+ compiler . throwIfAnyErrors ( ) ;
242+
243+ expect ( logger . mock . calls . length ) . toEqual ( 2 ) ;
244+ expect ( logger . mock . calls [ 0 ] ) . toEqual ( [
245+ 'You specified both buildRangeStart and refreshRangeStart, buildRangeStart will be used.'
246+ ] ) ;
247+ expect ( logger . mock . calls [ 1 ] ) . toEqual ( [
248+ 'You specified both buildRangeEnd and refreshRangeEnd, buildRangeEnd will be used.'
249+ ] ) ;
250+ } ) ;
142251} ) ;
0 commit comments