Skip to content

Commit 24abdea

Browse files
authored
chore(schema-compiler): Add more inheritance tests (#9642)
1 parent 8f486ba commit 24abdea

File tree

5 files changed

+169
-1
lines changed

5 files changed

+169
-1
lines changed

packages/cubejs-schema-compiler/test/unit/__snapshots__/schema.test.ts.snap

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,28 @@ Array [
329329
]
330330
`;
331331

332+
exports[`Schema Testing Inheritance CubeB.js correctly extends cubeA.js (with additions) 13`] = `
333+
Object {
334+
"order_users": Object {
335+
"relationship": "belongsTo",
336+
"sql": [Function],
337+
},
338+
}
339+
`;
340+
341+
exports[`Schema Testing Inheritance CubeB.js correctly extends cubeA.js (with additions) 14`] = `
342+
Object {
343+
"line_items": Object {
344+
"relationship": "hasMany",
345+
"sql": [Function],
346+
},
347+
"order_users": Object {
348+
"relationship": "belongsTo",
349+
"sql": [Function],
350+
},
351+
}
352+
`;
353+
332354
exports[`Schema Testing Inheritance CubeB.js correctly extends cubeA.yml (with additions) 1`] = `
333355
Object {
334356
"completed_at": Object {
@@ -702,6 +724,28 @@ Array [
702724
]
703725
`;
704726

727+
exports[`Schema Testing Inheritance CubeB.js correctly extends cubeA.yml (with additions) 13`] = `
728+
Object {
729+
"order_users": Object {
730+
"relationship": "belongsTo",
731+
"sql": [Function],
732+
},
733+
}
734+
`;
735+
736+
exports[`Schema Testing Inheritance CubeB.js correctly extends cubeA.yml (with additions) 14`] = `
737+
Object {
738+
"line_items": Object {
739+
"relationship": "hasMany",
740+
"sql": [Function],
741+
},
742+
"order_users": Object {
743+
"relationship": "belongsTo",
744+
"sql": [Function],
745+
},
746+
}
747+
`;
748+
705749
exports[`Schema Testing Inheritance CubeB.yml correctly extends cubeA.js (with additions) 1`] = `
706750
Object {
707751
"completed_at": Object {
@@ -1003,6 +1047,28 @@ Array [
10031047
]
10041048
`;
10051049

1050+
exports[`Schema Testing Inheritance CubeB.yml correctly extends cubeA.js (with additions) 13`] = `
1051+
Object {
1052+
"order_users": Object {
1053+
"relationship": "belongsTo",
1054+
"sql": [Function],
1055+
},
1056+
}
1057+
`;
1058+
1059+
exports[`Schema Testing Inheritance CubeB.yml correctly extends cubeA.js (with additions) 14`] = `
1060+
Object {
1061+
"line_items": Object {
1062+
"relationship": "hasMany",
1063+
"sql": [Function],
1064+
},
1065+
"order_users": Object {
1066+
"relationship": "belongsTo",
1067+
"sql": [Function],
1068+
},
1069+
}
1070+
`;
1071+
10061072
exports[`Schema Testing Inheritance CubeB.yml correctly extends cubeA.yml (with additions) 1`] = `
10071073
Object {
10081074
"completed_at": Object {
@@ -1348,6 +1414,28 @@ Array [
13481414
]
13491415
`;
13501416

1417+
exports[`Schema Testing Inheritance CubeB.yml correctly extends cubeA.yml (with additions) 13`] = `
1418+
Object {
1419+
"order_users": Object {
1420+
"relationship": "belongsTo",
1421+
"sql": [Function],
1422+
},
1423+
}
1424+
`;
1425+
1426+
exports[`Schema Testing Inheritance CubeB.yml correctly extends cubeA.yml (with additions) 14`] = `
1427+
Object {
1428+
"line_items": Object {
1429+
"relationship": "hasMany",
1430+
"sql": [Function],
1431+
},
1432+
"order_users": Object {
1433+
"relationship": "belongsTo",
1434+
"sql": [Function],
1435+
},
1436+
}
1437+
`;
1438+
13511439
exports[`Schema Testing Views allows to override \`title\`, \`description\`, \`meta\`, and \`format\` on includes members 1`] = `
13521440
Object {
13531441
"accessPolicy": undefined,
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
cubes:
2+
- name: line_items
3+
sql_table: public.line_items
4+
public: false
5+
6+
dimensions:
7+
- name: id
8+
sql: id
9+
type: number
10+
primary_key: true
11+
public: true
12+
13+
- name: product_id
14+
sql: product_id
15+
type: number
16+
17+
- name: order_id
18+
sql: order_id
19+
type: number
20+
21+
# - name: quantity
22+
# sql: quantity
23+
# type: number
24+
25+
- name: price
26+
sql: price
27+
type: number
28+
29+
measures:
30+
- name: count
31+
type: count
32+
33+
- name: sum_price
34+
sql: "{price}"
35+
type: sum
36+
public: false

packages/cubejs-schema-compiler/test/unit/fixtures/orders_ext.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,13 @@ cube('ordersExt', {
1515
},
1616
},
1717

18+
joins: {
19+
line_items: {
20+
relationship: 'one_to_many',
21+
sql: `${CUBE}.id = ${line_items}.order_id`,
22+
}
23+
},
24+
1825
segments: {
1926
anotherStatus: {
2027
description: 'Just another one',

packages/cubejs-schema-compiler/test/unit/fixtures/orders_ext.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,11 @@ cubes:
1212
sql: status
1313
type: count_distinct
1414

15+
joins:
16+
- name: line_items
17+
sql: '{CUBE.id} = {line_items.order_id}'
18+
relationship: one_to_many
19+
1520
segments:
1621
- name: anotherStatus
1722
description: Just another one

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

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import path from 'path';
33
import { prepareCompiler, prepareJsCompiler, prepareYamlCompiler } from './PrepareCompiler';
44
import { createCubeSchema, createCubeSchemaWithCustomGranularitiesAndTimeShift, createCubeSchemaWithAccessPolicy } from './utils';
55

6-
const CUBE_COMPONENTS = ['dimensions', 'measures', 'segments', 'hierarchies', 'preAggregations', 'accessPolicy'];
6+
const CUBE_COMPONENTS = ['dimensions', 'measures', 'segments', 'hierarchies', 'preAggregations', 'accessPolicy', 'joins'];
77

88
describe('Schema Testing', () => {
99
const schemaCompile = async () => {
@@ -807,6 +807,10 @@ describe('Schema Testing', () => {
807807
path.join(process.cwd(), '/test/unit/fixtures/order_users.yml'),
808808
'utf8'
809809
);
810+
const orderLineItems = fs.readFileSync(
811+
path.join(process.cwd(), '/test/unit/fixtures/line_items.yml'),
812+
'utf8'
813+
);
810814
const ordersExt = fs.readFileSync(
811815
path.join(process.cwd(), '/test/unit/fixtures/orders_ext.js'),
812816
'utf8'
@@ -825,6 +829,10 @@ describe('Schema Testing', () => {
825829
content: orderUsers,
826830
fileName: 'order_users.yml',
827831
},
832+
{
833+
content: orderLineItems,
834+
fileName: 'line_items.yml',
835+
},
828836
]);
829837
await compiler.compile();
830838
compiler.throwIfAnyErrors();
@@ -887,6 +895,10 @@ describe('Schema Testing', () => {
887895
path.join(process.cwd(), '/test/unit/fixtures/order_users.yml'),
888896
'utf8'
889897
);
898+
const orderLineItems = fs.readFileSync(
899+
path.join(process.cwd(), '/test/unit/fixtures/line_items.yml'),
900+
'utf8'
901+
);
890902
const ordersExt = fs.readFileSync(
891903
path.join(process.cwd(), '/test/unit/fixtures/orders_ext.yml'),
892904
'utf8'
@@ -905,6 +917,10 @@ describe('Schema Testing', () => {
905917
content: orderUsers,
906918
fileName: 'order_users.yml',
907919
},
920+
{
921+
content: orderLineItems,
922+
fileName: 'line_items.yml',
923+
},
908924
]);
909925
await compiler.compile();
910926
compiler.throwIfAnyErrors();
@@ -967,6 +983,10 @@ describe('Schema Testing', () => {
967983
path.join(process.cwd(), '/test/unit/fixtures/order_users.yml'),
968984
'utf8'
969985
);
986+
const orderLineItems = fs.readFileSync(
987+
path.join(process.cwd(), '/test/unit/fixtures/line_items.yml'),
988+
'utf8'
989+
);
970990
const ordersExt = fs.readFileSync(
971991
path.join(process.cwd(), '/test/unit/fixtures/orders_ext.yml'),
972992
'utf8'
@@ -985,6 +1005,10 @@ describe('Schema Testing', () => {
9851005
content: orderUsers,
9861006
fileName: 'order_users.yml',
9871007
},
1008+
{
1009+
content: orderLineItems,
1010+
fileName: 'line_items.yml',
1011+
},
9881012
]);
9891013
await compiler.compile();
9901014
compiler.throwIfAnyErrors();
@@ -1043,6 +1067,10 @@ describe('Schema Testing', () => {
10431067
path.join(process.cwd(), '/test/unit/fixtures/order_users.yml'),
10441068
'utf8'
10451069
);
1070+
const orderLineItems = fs.readFileSync(
1071+
path.join(process.cwd(), '/test/unit/fixtures/line_items.yml'),
1072+
'utf8'
1073+
);
10461074
const ordersExt = fs.readFileSync(
10471075
path.join(process.cwd(), '/test/unit/fixtures/orders_ext.js'),
10481076
'utf8'
@@ -1061,6 +1089,10 @@ describe('Schema Testing', () => {
10611089
content: orderUsers,
10621090
fileName: 'order_users.yml',
10631091
},
1092+
{
1093+
content: orderLineItems,
1094+
fileName: 'line_items.yml',
1095+
},
10641096
]);
10651097
await compiler.compile();
10661098
compiler.throwIfAnyErrors();

0 commit comments

Comments
 (0)