Skip to content

Commit 442d55c

Browse files
committed
add tests
1 parent ca314a0 commit 442d55c

File tree

1 file changed

+57
-0
lines changed

1 file changed

+57
-0
lines changed

packages/cubejs-schema-compiler/test/unit/base-query.test.ts

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {
55
createCubeSchema,
66
createCubeSchemaWithCustomGranularities,
77
createCubeSchemaYaml,
8+
createECommerceSchema,
89
createJoinedCubesSchema,
910
createSchemaYaml,
1011
createSchemaYamlForGroupFilterParamsTests
@@ -360,6 +361,62 @@ describe('SQL Generation', () => {
360361
const expectedParams = ['type_value', 'not_type_value', '3'];
361362
expect(queryAndParams[1]).toEqual(expectedParams);
362363
});
364+
365+
it('Simple query - order by for query with filtered timeDimension', async () => {
366+
const compilersLocal = prepareYamlCompiler(
367+
createSchemaYaml(createECommerceSchema())
368+
);
369+
370+
await compilersLocal.compiler.compile();
371+
372+
let query = new PostgresQuery(compilersLocal, {
373+
measures: [
374+
'orders.count'
375+
],
376+
timeDimensions: [
377+
{
378+
dimension: 'orders.updated_at',
379+
granularity: 'week'
380+
},
381+
{
382+
dimension: 'orders.created_at',
383+
dateRange: [
384+
'2016-01-01',
385+
'2018-01-01'
386+
]
387+
},
388+
],
389+
order: [{ id: 'orders.updated_at', desc: false }],
390+
});
391+
392+
let queryAndParams = query.buildSqlAndParams();
393+
expect(queryAndParams[0].includes('ORDER BY 1')).toBeTruthy();
394+
395+
// The order of time dimensions should have no effect on the `ORDER BY` clause
396+
397+
query = new PostgresQuery(compilersLocal, {
398+
measures: [
399+
'orders.count'
400+
],
401+
timeDimensions: [
402+
{
403+
dimension: 'orders.created_at',
404+
dateRange: [
405+
'2016-01-01',
406+
'2018-01-01'
407+
]
408+
},
409+
{
410+
dimension: 'orders.updated_at',
411+
granularity: 'week'
412+
}
413+
],
414+
order: [{ id: 'orders.updated_at', desc: false }],
415+
});
416+
417+
queryAndParams = query.buildSqlAndParams();
418+
expect(queryAndParams[0].includes('ORDER BY 1')).toBeTruthy();
419+
});
363420
});
364421

365422
describe('Custom granularities', () => {

0 commit comments

Comments
 (0)