1
- import { get } from "http" ;
2
1
import { TableSchema } from "../types/cube-types" ;
3
- import { getMemberProjection , getProjectionClause } from './get-projection-clause' ;
2
+ import { getDimensionProjection , getFilterMeasureProjection , getProjectionClause } from './get-projection-clause' ;
4
3
5
4
6
5
const TABLE_SCHEMA : TableSchema = {
7
6
dimensions : [ { name : 'a' , sql : 'others' , type : 'number' } , { name : 'c' , sql : 'any' , type : 'string' } ] ,
8
- measures : [ ] ,
7
+ measures : [ { name : 'x' , sql : 'x' , type : 'number' } , { name : 'y' , sql : 'y' , type : 'number' } , { name : 'z' , sql : 'z' , type : 'number' } ] ,
9
8
name : 'test' ,
10
9
sql : 'SELECT * from test'
11
10
// Define your table schema here
12
11
} ;
13
12
describe ( "get-projection-clause" , ( ) => {
14
- describe ( "getMemberProjection " , ( ) => {
13
+ describe ( "getDimensionProjection " , ( ) => {
15
14
it ( "should return the member projection when the key exists in the table schema" , ( ) => {
16
15
const key = "test.a" ;
17
-
18
16
19
- const result = getMemberProjection ( { key, tableSchema : TABLE_SCHEMA } ) ;
17
+ const result = getDimensionProjection ( { key, tableSchema : TABLE_SCHEMA } ) ;
20
18
expect ( result ) . toEqual ( { aliasKey : "test__a" , foundMember : { "name" : "a" , "sql" : "others" , "type" : "number" } , sql : "others AS test__a" } ) ;
21
19
} ) ;
22
20
@@ -27,25 +25,48 @@ describe("get-projection-clause", () => {
27
25
dimensions : [ { name : 'b' , sql : 'others' , type : 'number' } ] ,
28
26
} ;
29
27
30
- const result = getMemberProjection ( { key, tableSchema } ) ;
28
+ const result = getDimensionProjection ( { key, tableSchema } ) ;
29
+ expect ( result ) . toEqual ( { aliasKey : undefined , foundMember : undefined , sql : undefined } ) ;
30
+ } ) ;
31
+ } )
32
+
33
+ describe ( "getFilterMeasureProjection" , ( ) => {
34
+ it ( "should return the member projection when the key exists in the table schema" , ( ) => {
35
+ const key = "test.x" ;
36
+ const result = getFilterMeasureProjection ( { key, tableSchema : TABLE_SCHEMA , measures : [ 'test.a' ] } ) ;
37
+ expect ( result ) . toEqual ( { aliasKey : "test__x" , foundMember : { "name" : "x" , "sql" : "x" , "type" : "number" } , sql : "test.x AS test__x" } ) ;
38
+ } ) ;
39
+
40
+ it ( "should not create alias when item in measure list" , ( ) => {
41
+ const key = "test.x" ;
42
+ const result = getFilterMeasureProjection ( { key, tableSchema : TABLE_SCHEMA , measures : [ 'test.x' ] } ) ;
43
+ expect ( result ) . toEqual ( { aliasKey : undefined , foundMember : undefined , sql : undefined } ) ;
44
+ } ) ;
45
+
46
+ it ( "should return the object with undefined values when the key doesn't exist in the table schema" , ( ) => {
47
+ const key = "test.a" ;
48
+ const tableSchema : TableSchema = {
49
+ ...TABLE_SCHEMA ,
50
+ measures : [ { name : 'b' , sql : 'others' , type : 'number' } ] ,
51
+ } ;
52
+
53
+ const result = getFilterMeasureProjection ( { key, tableSchema, measures : [ 'test.b' ] } ) ;
31
54
expect ( result ) . toEqual ( { aliasKey : undefined , foundMember : undefined , sql : undefined } ) ;
32
55
} ) ;
33
56
} )
34
57
35
58
describe ( "getProjectionClause" , ( ) => {
36
59
it ( 'should return the projection clause when the members are present in the table schema' , ( ) => {
37
60
const members = [ 'test.a' , 'test.c' ] ;
38
- const tableSchema = TABLE_SCHEMA ;
39
61
const aliasedColumnSet = new Set < string > ( ) ;
40
- const result = getProjectionClause ( members , tableSchema , aliasedColumnSet ) ;
41
- expect ( result ) . toEqual ( ', others AS test__a, any AS test__c' ) ;
62
+ const result = getProjectionClause ( [ ] , members , TABLE_SCHEMA , aliasedColumnSet ) ;
63
+ expect ( result ) . toEqual ( 'others AS test__a, any AS test__c' ) ;
42
64
} )
43
65
it ( 'should skip aliased items present in already seen' , ( ) => {
44
66
const members = [ 'test.a' , 'test.c' ] ;
45
- const tableSchema = TABLE_SCHEMA ;
46
67
const aliasedColumnSet = new Set < string > ( [ 'test.c' ] ) ;
47
- const result = getProjectionClause ( members , tableSchema , aliasedColumnSet ) ;
48
- expect ( result ) . toEqual ( ', others AS test__a' ) ;
68
+ const result = getProjectionClause ( [ ] , members , TABLE_SCHEMA , aliasedColumnSet ) ;
69
+ expect ( result ) . toEqual ( 'others AS test__a, ' ) ;
49
70
} )
50
71
} )
51
72
0 commit comments