@@ -251,27 +251,136 @@ describe('Cube Validation', () => {
251251 expect ( validationResult . error ) . toBeTruthy ( ) ;
252252 } ) ;
253253
254- it ( 'measures alternatives' , async ( ) => {
255- const cubeValidator = new CubeValidator ( new CubeSymbols ( ) ) ;
256- const cube = {
257- name : 'name' ,
258- sql : ( ) => '' ,
259- fileName : 'fileName' ,
260- measures : {
261- number : {
262- type : 'suma'
254+ describe ( 'Measures' , ( ) => {
255+ it ( 'measures alternatives' , async ( ) => {
256+ const cubeValidator = new CubeValidator ( new CubeSymbols ( ) ) ;
257+ const cube = {
258+ name : 'name' ,
259+ sql : ( ) => '' ,
260+ fileName : 'fileName' ,
261+ measures : {
262+ number : {
263+ type : 'suma'
264+ }
263265 }
264- }
265- } ;
266+ } ;
266267
267- const validationResult = cubeValidator . validate ( cube , {
268- error : ( message : any , _e : any ) => {
269- console . log ( message ) ;
270- expect ( message ) . toContain ( 'must be one of [count, number,' ) ;
271- }
272- } as any ) ;
268+ const validationResult = cubeValidator . validate ( cube , {
269+ error : ( message : any , _e : any ) => {
270+ console . log ( message ) ;
271+ expect ( message ) . toContain ( 'must be one of [count, number,' ) ;
272+ }
273+ } as any ) ;
273274
274- expect ( validationResult . error ) . toBeTruthy ( ) ;
275+ expect ( validationResult . error ) . toBeTruthy ( ) ;
276+ } ) ;
277+
278+ it ( '2 timeShifts, 1 without timeDimension' , async ( ) => {
279+ const cubeValidator = new CubeValidator ( new CubeSymbols ( ) ) ;
280+ const cube = {
281+ name : 'name' ,
282+ sql : ( ) => '' ,
283+ fileName : 'fileName' ,
284+ measures : {
285+ measure_with_time_shift : {
286+ multiStage : true ,
287+ type : 'sum' ,
288+ sql : ( ) => '' ,
289+ timeShift : [
290+ {
291+ timeDimension : ( ) => '' ,
292+ interval : '1 day' ,
293+ type : 'prior' ,
294+ } ,
295+ {
296+ interval : '1 day' ,
297+ type : 'prior' ,
298+ }
299+ ]
300+ }
301+ }
302+ } ;
303+
304+ const validationResult = cubeValidator . validate ( cube , {
305+ error : ( message : any , _e : any ) => {
306+ console . log ( message ) ;
307+ expect ( message ) . toContain ( '(measures.measure_with_time_shift.timeShift[1].timeDimension) is required' ) ;
308+ }
309+ } as any ) ;
310+
311+ expect ( validationResult . error ) . toBeTruthy ( ) ;
312+ } ) ;
313+
314+ it ( '3 timeShifts' , async ( ) => {
315+ const cubeValidator = new CubeValidator ( new CubeSymbols ( ) ) ;
316+ const cube = {
317+ name : 'name' ,
318+ sql : ( ) => '' ,
319+ fileName : 'fileName' ,
320+ measures : {
321+ measure_with_time_shift : {
322+ multiStage : true ,
323+ type : 'sum' ,
324+ sql : ( ) => '' ,
325+ timeShift : [
326+ {
327+ timeDimension : ( ) => '' ,
328+ interval : '1 day' ,
329+ type : 'prior' ,
330+ } ,
331+ {
332+ timeDimension : ( ) => '' ,
333+ interval : '1 year' ,
334+ type : 'next' ,
335+ } ,
336+ {
337+ timeDimension : ( ) => '' ,
338+ interval : '1 week' ,
339+ type : 'prior' ,
340+ }
341+ ]
342+ }
343+ }
344+ } ;
345+
346+ const validationResult = cubeValidator . validate ( cube , {
347+ error : ( message : any , _e : any ) => {
348+ console . log ( message ) ;
349+ }
350+ } as any ) ;
351+
352+ expect ( validationResult . error ) . toBeFalsy ( ) ;
353+ } ) ;
354+
355+ it ( '1 timeShift without timeDimension' , async ( ) => {
356+ const cubeValidator = new CubeValidator ( new CubeSymbols ( ) ) ;
357+ const cube = {
358+ name : 'name' ,
359+ sql : ( ) => '' ,
360+ fileName : 'fileName' ,
361+ measures : {
362+ measure_with_time_shift : {
363+ multiStage : true ,
364+ type : 'sum' ,
365+ sql : ( ) => '' ,
366+ timeShift : [
367+ {
368+ interval : '1 day' ,
369+ type : 'prior' ,
370+ }
371+ ]
372+ }
373+ }
374+ } ;
375+
376+ const validationResult = cubeValidator . validate ( cube , {
377+ error : ( message : any , _e : any ) => {
378+ console . log ( message ) ;
379+ }
380+ } as any ) ;
381+
382+ expect ( validationResult . error ) . toBeFalsy ( ) ;
383+ } ) ;
275384 } ) ;
276385
277386 it ( 'OriginalSqlSchema' , async ( ) => {
0 commit comments