Skip to content

Commit 9f8977a

Browse files
committed
add tests
1 parent 60384f6 commit 9f8977a

File tree

2 files changed

+230
-89
lines changed

2 files changed

+230
-89
lines changed

packages/cubejs-schema-compiler/test/integration/postgres/yaml-compiler.test.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,40 @@ cubes:
5757
);
5858
});
5959

60+
it('simple with json/curly in sql', async () => {
61+
const { compiler, joinGraph, cubeEvaluator } = prepareYamlCompiler(`
62+
cubes:
63+
- name: ActiveUsers
64+
sql: SELECT 1 as user_id, '2022-01-01'::TIMESTAMP as timestamp, CAST('\\{"key":"value"\\}'::JSON AS TEXT) AS json_col
65+
66+
dimensions:
67+
- name: time
68+
sql: "{CUBE}.timestamp"
69+
type: time
70+
- name: json_col
71+
sql: json_col
72+
type: string
73+
`);
74+
await compiler.compile();
75+
76+
const query = new PostgresQuery({ joinGraph, cubeEvaluator, compiler }, {
77+
dimensions: ['ActiveUsers.time', 'ActiveUsers.json_col'],
78+
timezone: 'UTC'
79+
});
80+
81+
console.log(query.buildSqlAndParams());
82+
83+
const res = await dbRunner.testQuery(query.buildSqlAndParams());
84+
console.log(JSON.stringify(res));
85+
86+
expect(res).toEqual(
87+
[{
88+
active_users__time: '2022-01-01T00:00:00.000Z',
89+
active_users__json_col: '{"key":"value"}',
90+
}]
91+
);
92+
});
93+
6094
it('missed sql', async () => {
6195
const { compiler } = prepareYamlCompiler(`
6296
cubes:

0 commit comments

Comments
 (0)