Skip to content

Commit 553c15f

Browse files
committed
test: Add smoke tests for SQL API ad-hoc measures
1 parent 957990c commit 553c15f

File tree

2 files changed

+96
-0
lines changed

2 files changed

+96
-0
lines changed

packages/cubejs-testing/test/__snapshots__/smoke-cubesql.test.ts.snap

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -546,6 +546,40 @@ Array [
546546
]
547547
`;
548548

549+
exports[`SQL API Postgres (Data) measure with ad-hoc filter and original measure: measure-with-ad-hoc-filters-and-original-measure 1`] = `
550+
Array [
551+
Object {
552+
"new_amount": 300,
553+
"total_amount": 1700,
554+
},
555+
]
556+
`;
557+
558+
exports[`SQL API Postgres (Data) measure with ad-hoc filter: measure-with-ad-hoc-filters 1`] = `
559+
Array [
560+
Object {
561+
"new_amount": 300,
562+
},
563+
]
564+
`;
565+
566+
exports[`SQL API Postgres (Data) measure with replaced aggregation and original measure: measure-with-replaced-aggregation-and-original-measure 1`] = `
567+
Array [
568+
Object {
569+
"min_amount": 100,
570+
"sum_amount": 1700,
571+
},
572+
]
573+
`;
574+
575+
exports[`SQL API Postgres (Data) measure with replaced aggregation: measure-with-replaced-aggregation 1`] = `
576+
Array [
577+
Object {
578+
"min_amount": 100,
579+
},
580+
]
581+
`;
582+
549583
exports[`SQL API Postgres (Data) metabase max number: metabase max number 1`] = `
550584
Array [
551585
Object {

packages/cubejs-testing/test/smoke-cubesql.test.ts

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -796,5 +796,67 @@ filter_subq AS (
796796
const res = await connection.query(query);
797797
expect(res.rows).toMatchSnapshot('wrapper-duplicated-members');
798798
});
799+
800+
test('measure with replaced aggregation', async () => {
801+
const query = `
802+
SELECT
803+
MIN(totalAmount) AS min_amount
804+
FROM
805+
Orders
806+
`;
807+
808+
const res = await connection.query(query);
809+
expect(res.rows).toMatchSnapshot('measure-with-replaced-aggregation');
810+
});
811+
812+
test('measure with replaced aggregation and original measure', async () => {
813+
const query = `
814+
SELECT
815+
SUM(totalAmount) AS sum_amount,
816+
MIN(totalAmount) AS min_amount
817+
FROM
818+
Orders
819+
`;
820+
821+
const res = await connection.query(query);
822+
expect(res.rows).toMatchSnapshot('measure-with-replaced-aggregation-and-original-measure');
823+
});
824+
825+
test('measure with ad-hoc filter', async () => {
826+
const query = `
827+
SELECT
828+
SUM(
829+
CASE status = 'new'
830+
WHEN TRUE
831+
THEN totalAmount
832+
ELSE NULL
833+
END
834+
) AS new_amount
835+
FROM
836+
Orders
837+
`;
838+
839+
const res = await connection.query(query);
840+
expect(res.rows).toMatchSnapshot('measure-with-ad-hoc-filters');
841+
});
842+
843+
test('measure with ad-hoc filter and original measure', async () => {
844+
const query = `
845+
SELECT
846+
SUM(totalAmount) AS total_amount,
847+
SUM(
848+
CASE status = 'new'
849+
WHEN TRUE
850+
THEN totalAmount
851+
ELSE NULL
852+
END
853+
) AS new_amount
854+
FROM
855+
Orders
856+
`;
857+
858+
const res = await connection.query(query);
859+
expect(res.rows).toMatchSnapshot('measure-with-ad-hoc-filters-and-original-measure');
860+
});
799861
});
800862
});

0 commit comments

Comments
 (0)