Skip to content

Commit fff648e

Browse files
committed
some fixes in tests
1 parent 76e3e66 commit fff648e

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', () => {
@@ -676,7 +676,7 @@ views:
676676
);
677677
});
678678

679-
it('calling cube\'s sql()', async () => {
679+
it('calling cube\'s sql() (yaml-yaml)', async () => {
680680
const { compiler, joinGraph, cubeEvaluator } = prepareYamlCompiler(
681681
`cubes:
682682
- name: simple_orders
@@ -706,7 +706,7 @@ views:
706706
- name: simple_orders_sql_ext
707707
708708
sql: >
709-
SELECT * FROM ({simple_orders.sql()}) as parent
709+
SELECT * FROM {simple_orders.sql()} as parent
710710
WHERE status = 'new'
711711
712712
measures:
@@ -757,4 +757,100 @@ views:
757757
]
758758
);
759759
});
760+
761+
it('calling cube\'s sql() (yaml-js)', async () => {
762+
const { compiler, joinGraph, cubeEvaluator } = prepareCompiler([
763+
{
764+
content: `
765+
cube('simple_orders', {
766+
sql: \`
767+
SELECT 1 AS id, 100 AS amount, 'new' status, '2025-04-15'::TIMESTAMP AS created_at
768+
UNION ALL
769+
SELECT 2 AS id, 200 AS amount, 'new' status, '2025-04-16'::TIMESTAMP AS created_at
770+
UNION ALL
771+
SELECT 3 AS id, 300 AS amount, 'processed' status, '2025-04-17'::TIMESTAMP AS created_at
772+
UNION ALL
773+
SELECT 4 AS id, 500 AS amount, 'processed' status, '2025-04-18'::TIMESTAMP AS created_at
774+
UNION ALL
775+
SELECT 5 AS id, 600 AS amount, 'shipped' status, '2025-04-19'::TIMESTAMP AS created_at
776+
\`,
777+
778+
dimensions: {
779+
status: {
780+
sql: 'status',
781+
type: 'string',
782+
},
783+
},
784+
785+
measures: {
786+
count: {
787+
type: 'count',
788+
},
789+
total_amount: {
790+
type: 'sum',
791+
sql: 'total_amount',
792+
},
793+
},
794+
});
795+
`,
796+
fileName: 'cube.js',
797+
},
798+
{
799+
content: `cubes:
800+
- name: simple_orders_sql_ext
801+
802+
sql: >
803+
SELECT * FROM {simple_orders.sql()} as parent
804+
WHERE status = 'new'
805+
806+
measures:
807+
- name: count
808+
type: count
809+
810+
- name: total_amount
811+
sql: amount
812+
type: sum
813+
814+
dimensions:
815+
- name: id
816+
sql: id
817+
type: number
818+
primary_key: true
819+
820+
- name: created_at
821+
sql: created_at
822+
type: time
823+
`,
824+
fileName: 'cube.yml',
825+
},
826+
]);
827+
828+
await compiler.compile();
829+
830+
const query = new PostgresQuery({ joinGraph, cubeEvaluator, compiler }, {
831+
measures: ['simple_orders_sql_ext.count'],
832+
timeDimensions: [{
833+
dimension: 'simple_orders_sql_ext.created_at',
834+
granularity: 'day',
835+
dateRange: ['2025-04-01', '2025-05-01']
836+
}],
837+
timezone: 'UTC',
838+
preAggregationsSchema: ''
839+
});
840+
841+
const res = await dbRunner.evaluateQueryWithPreAggregations(query);
842+
843+
expect(res).toEqual(
844+
[
845+
{
846+
simple_orders_sql_ext__count: '1',
847+
simple_orders_sql_ext__created_at_day: '2025-04-15T00:00:00.000Z',
848+
},
849+
{
850+
simple_orders_sql_ext__count: '1',
851+
simple_orders_sql_ext__created_at_day: '2025-04-16T00:00:00.000Z',
852+
}
853+
]
854+
);
855+
});
760856
});

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ describe('Yaml Schema Testing', () => {
604604
- name: simple_orders_sql_ext
605605
606606
sql: >
607-
SELECT * FROM {simple_orders.sql()}
607+
SELECT * FROM {simple_orders.sql()} as q
608608
WHERE status = 'processed'
609609
610610
measures:

0 commit comments

Comments
 (0)