1
+ import { TableSchema } from '../../types/cube-types/table' ;
2
+ import { getDimensionProjection , getFilterMeasureProjection } from '../get-aliased-columns-from-filters' ;
3
+
4
+ const TABLE_SCHEMA : TableSchema = {
5
+ dimensions : [
6
+ { name : 'a' , sql : 'others' , type : 'number' } ,
7
+ { name : 'c' , sql : 'any' , type : 'string' } ,
8
+ ] ,
9
+ measures : [
10
+ { name : 'x' , sql : 'x' , type : 'number' } ,
11
+ { name : 'y' , sql : 'y' , type : 'number' } ,
12
+ { name : 'z' , sql : 'z' , type : 'number' } ,
13
+ { name : 'total_rows' , sql : 'count(test.id)' , type : 'number' } ,
14
+ ] ,
15
+ name : 'test' ,
16
+ sql : 'SELECT * from test' ,
17
+ // Define your table schema here
18
+ } ;
19
+
20
+ describe ( 'get-aliased-columns-from-filters' , ( ) => {
21
+ describe ( 'getFilterMeasureProjection' , ( ) => {
22
+ it ( 'should return the member projection when the key exists in the table schema' , ( ) => {
23
+ const key = 'test.x' ;
24
+ const result = getFilterMeasureProjection ( {
25
+ key,
26
+ tableSchema : TABLE_SCHEMA ,
27
+ measures : [ 'test.a' ] ,
28
+ } ) ;
29
+ expect ( result ) . toEqual ( {
30
+ aliasKey : 'test__x' ,
31
+ foundMember : { name : 'x' , sql : 'x' , type : 'number' } ,
32
+ sql : 'test.x AS test__x' ,
33
+ } ) ;
34
+ } ) ;
35
+
36
+ it ( 'should not create alias when item in measure list' , ( ) => {
37
+ const key = 'test.x' ;
38
+ const result = getFilterMeasureProjection ( {
39
+ key,
40
+ tableSchema : TABLE_SCHEMA ,
41
+ measures : [ 'test.x' ] ,
42
+ } ) ;
43
+ expect ( result ) . toEqual ( {
44
+ aliasKey : undefined ,
45
+ foundMember : undefined ,
46
+ sql : undefined ,
47
+ } ) ;
48
+ } ) ;
49
+
50
+ it ( "should return the object with undefined values when the key doesn't exist in the table schema" , ( ) => {
51
+ const key = 'test.a' ;
52
+ const tableSchema : TableSchema = {
53
+ ...TABLE_SCHEMA ,
54
+ measures : [ { name : 'b' , sql : 'others' , type : 'number' } ] ,
55
+ } ;
56
+
57
+ const result = getFilterMeasureProjection ( {
58
+ key,
59
+ tableSchema,
60
+ measures : [ 'test.b' ] ,
61
+ } ) ;
62
+ expect ( result ) . toEqual ( {
63
+ aliasKey : undefined ,
64
+ foundMember : undefined ,
65
+ sql : undefined ,
66
+ } ) ;
67
+ } ) ;
68
+ } ) ;
69
+
70
+ describe ( 'getDimensionProjection' , ( ) => {
71
+ it ( 'should return the member projection when the key exists in the table schema' , ( ) => {
72
+ const key = 'test.a' ;
73
+
74
+ const result = getDimensionProjection ( { key, tableSchema : TABLE_SCHEMA , modifiers : [ ] } ) ;
75
+ expect ( result ) . toEqual ( {
76
+ aliasKey : 'test__a' ,
77
+ foundMember : { name : 'a' , sql : 'others' , type : 'number' } ,
78
+ sql : 'others AS test__a' ,
79
+ } ) ;
80
+ } ) ;
81
+
82
+ it ( "should return the object with undefined values when the key doesn't exist in the table schema" , ( ) => {
83
+ const key = 'test.a' ;
84
+ const tableSchema : TableSchema = {
85
+ ...TABLE_SCHEMA ,
86
+ dimensions : [ { name : 'b' , sql : 'others' , type : 'number' } ] ,
87
+ } ;
88
+
89
+ const result = getDimensionProjection ( { key, tableSchema, modifiers : [ ] } ) ;
90
+ expect ( result ) . toEqual ( {
91
+ aliasKey : undefined ,
92
+ foundMember : undefined ,
93
+ sql : undefined ,
94
+ } ) ;
95
+ } ) ;
96
+ } ) ;
97
+ } )
0 commit comments