Skip to content

Commit 0af4349

Browse files
committed
some fixes in tests
1 parent 6e803e7 commit 0af4349

File tree

2 files changed

+100
-4
lines changed

2 files changed

+100
-4
lines changed

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

Lines changed: 99 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { PostgresQuery } from '../../../src/adapter/PostgresQuery';
2-
import { prepareYamlCompiler } from '../../unit/PrepareCompiler';
2+
import { prepareCompiler, prepareYamlCompiler } from '../../unit/PrepareCompiler';
33
import { dbRunner } from './PostgresDBRunner';
44

55
describe('YAMLCompiler', () => {
@@ -642,7 +642,7 @@ views:
642642
);
643643
});
644644

645-
it('calling cube\'s sql()', async () => {
645+
it('calling cube\'s sql() (yaml-yaml)', async () => {
646646
const { compiler, joinGraph, cubeEvaluator } = prepareYamlCompiler(
647647
`cubes:
648648
- name: simple_orders
@@ -672,7 +672,7 @@ views:
672672
- name: simple_orders_sql_ext
673673
674674
sql: >
675-
SELECT * FROM ({simple_orders.sql()}) as parent
675+
SELECT * FROM {simple_orders.sql()} as parent
676676
WHERE status = 'new'
677677
678678
measures:
@@ -723,4 +723,100 @@ views:
723723
]
724724
);
725725
});
726+
727+
it('calling cube\'s sql() (yaml-js)', async () => {
728+
const { compiler, joinGraph, cubeEvaluator } = prepareCompiler([
729+
{
730+
content: `
731+
cube('simple_orders', {
732+
sql: \`
733+
SELECT 1 AS id, 100 AS amount, 'new' status, '2025-04-15'::TIMESTAMP AS created_at
734+
UNION ALL
735+
SELECT 2 AS id, 200 AS amount, 'new' status, '2025-04-16'::TIMESTAMP AS created_at
736+
UNION ALL
737+
SELECT 3 AS id, 300 AS amount, 'processed' status, '2025-04-17'::TIMESTAMP AS created_at
738+
UNION ALL
739+
SELECT 4 AS id, 500 AS amount, 'processed' status, '2025-04-18'::TIMESTAMP AS created_at
740+
UNION ALL
741+
SELECT 5 AS id, 600 AS amount, 'shipped' status, '2025-04-19'::TIMESTAMP AS created_at
742+
\`,
743+
744+
dimensions: {
745+
status: {
746+
sql: 'status',
747+
type: 'string',
748+
},
749+
},
750+
751+
measures: {
752+
count: {
753+
type: 'count',
754+
},
755+
total_amount: {
756+
type: 'sum',
757+
sql: 'total_amount',
758+
},
759+
},
760+
});
761+
`,
762+
fileName: 'cube.js',
763+
},
764+
{
765+
content: `cubes:
766+
- name: simple_orders_sql_ext
767+
768+
sql: >
769+
SELECT * FROM {simple_orders.sql()} as parent
770+
WHERE status = 'new'
771+
772+
measures:
773+
- name: count
774+
type: count
775+
776+
- name: total_amount
777+
sql: amount
778+
type: sum
779+
780+
dimensions:
781+
- name: id
782+
sql: id
783+
type: number
784+
primary_key: true
785+
786+
- name: created_at
787+
sql: created_at
788+
type: time
789+
`,
790+
fileName: 'cube.yml',
791+
},
792+
]);
793+
794+
await compiler.compile();
795+
796+
const query = new PostgresQuery({ joinGraph, cubeEvaluator, compiler }, {
797+
measures: ['simple_orders_sql_ext.count'],
798+
timeDimensions: [{
799+
dimension: 'simple_orders_sql_ext.created_at',
800+
granularity: 'day',
801+
dateRange: ['2025-04-01', '2025-05-01']
802+
}],
803+
timezone: 'UTC',
804+
preAggregationsSchema: ''
805+
});
806+
807+
const res = await dbRunner.evaluateQueryWithPreAggregations(query);
808+
809+
expect(res).toEqual(
810+
[
811+
{
812+
simple_orders_sql_ext__count: '1',
813+
simple_orders_sql_ext__created_at_day: '2025-04-15T00:00:00.000Z',
814+
},
815+
{
816+
simple_orders_sql_ext__count: '1',
817+
simple_orders_sql_ext__created_at_day: '2025-04-16T00:00:00.000Z',
818+
}
819+
]
820+
);
821+
});
726822
});

packages/cubejs-schema-compiler/test/unit/yaml-schema.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ describe('Yaml Schema Testing', () => {
497497
- name: simple_orders_sql_ext
498498
499499
sql: >
500-
SELECT * FROM {simple_orders.sql()}
500+
SELECT * FROM {simple_orders.sql()} as q
501501
WHERE status = 'processed'
502502
503503
measures:

0 commit comments

Comments
 (0)