Skip to content

Commit 35638b8

Browse files
committed
add tests
1 parent 4f1bed1 commit 35638b8

File tree

3 files changed

+270
-0
lines changed

3 files changed

+270
-0
lines changed

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

Lines changed: 168 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1347,3 +1347,171 @@ Array [
13471347
},
13481348
]
13491349
`;
1350+
1351+
exports[`Schema Testing Views allows to override \`title\`, \`description\`, \`meta\`, and \`format\` on includes members 1`] = `
1352+
Object {
1353+
"accessPolicy": undefined,
1354+
"allDefinitions": [Function],
1355+
"cubes": Array [
1356+
Object {
1357+
"includes": Array [
1358+
Object {
1359+
"alias": "my_beloved_status",
1360+
"description": "Don't you believe this?",
1361+
"meta": Array [
1362+
Object {
1363+
"whose": "mine",
1364+
},
1365+
Object {
1366+
"what": "status",
1367+
},
1368+
],
1369+
"name": "status",
1370+
"title": "My Favorite and not Beloved Status!",
1371+
},
1372+
Object {
1373+
"alias": "my_beloved_created_at",
1374+
"description": "Created at this point in time",
1375+
"meta": Array [
1376+
Object {
1377+
"f1": "idk",
1378+
},
1379+
Object {
1380+
"f2": "rofl",
1381+
},
1382+
],
1383+
"name": "created_at",
1384+
"title": "My Favorite and not Beloved created_at!",
1385+
},
1386+
Object {
1387+
"description": "It's not possible!",
1388+
"format": "percent",
1389+
"meta": Array [
1390+
Object {
1391+
"whose": "bread",
1392+
},
1393+
Object {
1394+
"what": "butter",
1395+
},
1396+
Object {
1397+
"why": "cheese",
1398+
},
1399+
],
1400+
"name": "count",
1401+
"title": "My Overridden Count!",
1402+
},
1403+
Object {
1404+
"meta": Array [
1405+
Object {
1406+
"c1": "iddqd",
1407+
},
1408+
Object {
1409+
"c2": "idkfa",
1410+
},
1411+
],
1412+
"name": "hello",
1413+
"title": "My Overridden hierarchy!",
1414+
},
1415+
],
1416+
"joinPath": [Function],
1417+
},
1418+
],
1419+
"dimensions": Object {
1420+
"my_beloved_created_at": Object {
1421+
"aliasMember": "orders.created_at",
1422+
"description": "Created at this point in time",
1423+
"format": undefined,
1424+
"meta": Array [
1425+
Object {
1426+
"f1": "idk",
1427+
},
1428+
Object {
1429+
"f2": "rofl",
1430+
},
1431+
],
1432+
"ownedByCube": false,
1433+
"sql": [Function],
1434+
"title": "My Favorite and not Beloved created_at!",
1435+
"type": "time",
1436+
},
1437+
"my_beloved_status": Object {
1438+
"aliasMember": "orders.status",
1439+
"description": "Don't you believe this?",
1440+
"format": undefined,
1441+
"meta": Array [
1442+
Object {
1443+
"whose": "mine",
1444+
},
1445+
Object {
1446+
"what": "status",
1447+
},
1448+
],
1449+
"ownedByCube": false,
1450+
"sql": [Function],
1451+
"title": "My Favorite and not Beloved Status!",
1452+
"type": "string",
1453+
},
1454+
},
1455+
"evaluatedHierarchies": Array [
1456+
Object {
1457+
"levels": Array [
1458+
"orders_view.my_beloved_status",
1459+
],
1460+
"name": "hello",
1461+
"title": "World",
1462+
},
1463+
],
1464+
"fileName": "order_view.yml",
1465+
"hierarchies": Object {},
1466+
"includedMembers": Array [
1467+
Object {
1468+
"memberPath": "orders.hello",
1469+
"name": "hello",
1470+
"type": "hierarchies",
1471+
},
1472+
Object {
1473+
"memberPath": "orders.count",
1474+
"name": "count",
1475+
"type": "measures",
1476+
},
1477+
Object {
1478+
"memberPath": "orders.status",
1479+
"name": "my_beloved_status",
1480+
"type": "dimensions",
1481+
},
1482+
Object {
1483+
"memberPath": "orders.created_at",
1484+
"name": "my_beloved_created_at",
1485+
"type": "dimensions",
1486+
},
1487+
],
1488+
"isView": true,
1489+
"joins": Object {},
1490+
"measures": Object {
1491+
"count": Object {
1492+
"aggType": "count",
1493+
"aliasMember": "orders.count",
1494+
"description": "It's not possible!",
1495+
"format": "percent",
1496+
"meta": Array [
1497+
Object {
1498+
"whose": "bread",
1499+
},
1500+
Object {
1501+
"what": "butter",
1502+
},
1503+
Object {
1504+
"why": "cheese",
1505+
},
1506+
],
1507+
"ownedByCube": false,
1508+
"sql": [Function],
1509+
"title": "My Overridden Count!",
1510+
"type": "number",
1511+
},
1512+
},
1513+
"name": "orders_view",
1514+
"preAggregations": Object {},
1515+
"segments": Object {},
1516+
}
1517+
`;

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

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,47 @@ describe('Cube Validation', () => {
165165
expect(validationResult.error).toBeTruthy();
166166
});
167167

168+
it('view with overridden included members properties', async () => {
169+
const cubeValidator = new CubeValidator(new CubeSymbols());
170+
const cube = {
171+
name: 'name',
172+
// it's a hidden field which we use internally
173+
isView: true,
174+
fileName: 'fileName',
175+
cubes: [
176+
{
177+
joinPath: () => '',
178+
prefix: false,
179+
includes: [
180+
'member_by_name',
181+
{
182+
name: 'member_by_alias',
183+
alias: 'correct_alias'
184+
},
185+
{
186+
name: 'member_by_alias_with_overrides',
187+
title: 'Overridden title',
188+
description: 'Overridden description',
189+
format: 'percent',
190+
meta: {
191+
f1: 'Overridden 1',
192+
f2: 'Overridden 2',
193+
},
194+
}
195+
]
196+
}
197+
]
198+
};
199+
200+
const validationResult = cubeValidator.validate(cube, {
201+
error: (message: any, _e: any) => {
202+
console.log(message);
203+
}
204+
} as any);
205+
206+
expect(validationResult.error).toBeFalsy();
207+
});
208+
168209
it('refreshKey alternatives', async () => {
169210
const cubeValidator = new CubeValidator(new CubeSymbols());
170211
const cube = {

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

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -674,6 +674,67 @@ describe('Schema Testing', () => {
674674
expect(e.toString()).toMatch(/Included member 'id' conflicts with existing member of 'orders_view'\. Please consider excluding this member or assigning it an alias/);
675675
}
676676
});
677+
678+
it('allows to override `title`, `description`, `meta`, and `format` on includes members', async () => {
679+
const orders = fs.readFileSync(
680+
path.join(process.cwd(), '/test/unit/fixtures/orders.js'),
681+
'utf8'
682+
);
683+
const ordersView = `
684+
views:
685+
- name: orders_view
686+
cubes:
687+
- join_path: orders
688+
includes:
689+
- name: status
690+
alias: my_beloved_status
691+
title: My Favorite and not Beloved Status!
692+
description: Don't you believe this?
693+
meta:
694+
- whose: mine
695+
- what: status
696+
697+
- name: created_at
698+
alias: my_beloved_created_at
699+
title: My Favorite and not Beloved created_at!
700+
description: Created at this point in time
701+
meta:
702+
- f1: idk
703+
- f2: rofl
704+
705+
- name: count
706+
title: My Overridden Count!
707+
description: It's not possible!
708+
format: percent
709+
meta:
710+
- whose: bread
711+
- what: butter
712+
- why: cheese
713+
714+
- name: hello
715+
title: My Overridden hierarchy!
716+
meta:
717+
- c1: iddqd
718+
- c2: idkfa
719+
`;
720+
721+
const { compiler, cubeEvaluator } = prepareCompiler([
722+
{
723+
content: orders,
724+
fileName: 'orders.js',
725+
},
726+
{
727+
content: ordersView,
728+
fileName: 'order_view.yml',
729+
},
730+
]);
731+
732+
await compiler.compile();
733+
compiler.throwIfAnyErrors();
734+
735+
const cubeB = cubeEvaluator.cubeFromPath('orders_view');
736+
expect(cubeB).toMatchSnapshot();
737+
});
677738
});
678739

679740
describe('Inheritance', () => {

0 commit comments

Comments
 (0)