Skip to content

Commit 2bcedd1

Browse files
committed
add tests
1 parent 5cc936f commit 2bcedd1

File tree

3 files changed

+264
-0
lines changed

3 files changed

+264
-0
lines changed

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

Lines changed: 165 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,3 +1408,168 @@ Object {
14081408
"type": "number",
14091409
}
14101410
`;
1411+
1412+
exports[`Schema Testing Views allows to override \`title\`, \`description\`, \`meta\`, and \`format\` on includes members 1`] = `
1413+
Object {
1414+
"accessPolicy": undefined,
1415+
"allDefinitions": [Function],
1416+
"cubes": Array [
1417+
Object {
1418+
"includes": Array [
1419+
Object {
1420+
"alias": "my_beloved_status",
1421+
"description": "Don't you believe this?",
1422+
"meta": Array [
1423+
Object {
1424+
"whose": "mine",
1425+
},
1426+
Object {
1427+
"what": "status",
1428+
},
1429+
],
1430+
"name": "status",
1431+
"title": "My Favorite and not Beloved Status!",
1432+
},
1433+
Object {
1434+
"alias": "my_beloved_created_at",
1435+
"description": "Created at this point in time",
1436+
"meta": Array [
1437+
Object {
1438+
"c1": "iddqd",
1439+
},
1440+
Object {
1441+
"c2": "idkfa",
1442+
},
1443+
],
1444+
"name": "created_at",
1445+
"title": "My Favorite and not Beloved created_at!",
1446+
},
1447+
Object {
1448+
"description": "It's not possible!",
1449+
"format": "percent",
1450+
"meta": Array [
1451+
Object {
1452+
"whose": "bread",
1453+
},
1454+
Object {
1455+
"what": "butter",
1456+
},
1457+
Object {
1458+
"why": "cheese",
1459+
},
1460+
],
1461+
"name": "count",
1462+
"title": "My Overridden Count!",
1463+
},
1464+
Object {
1465+
"name": "hello",
1466+
"title": "My Overridden hierarchy!",
1467+
},
1468+
],
1469+
"joinPath": [Function],
1470+
},
1471+
],
1472+
"dimensions": Object {
1473+
"my_beloved_created_at": Object {
1474+
"aliasMember": "orders.created_at",
1475+
"description": "Created at this point in time",
1476+
"format": undefined,
1477+
"meta": Array [
1478+
Object {
1479+
"c1": "iddqd",
1480+
},
1481+
Object {
1482+
"c2": "idkfa",
1483+
},
1484+
],
1485+
"ownedByCube": false,
1486+
"sql": [Function],
1487+
"title": "My Favorite and not Beloved created_at!",
1488+
"type": "time",
1489+
},
1490+
"my_beloved_status": Object {
1491+
"aliasMember": "orders.status",
1492+
"description": "Don't you believe this?",
1493+
"format": undefined,
1494+
"meta": Array [
1495+
Object {
1496+
"whose": "mine",
1497+
},
1498+
Object {
1499+
"what": "status",
1500+
},
1501+
],
1502+
"ownedByCube": false,
1503+
"sql": [Function],
1504+
"title": "My Favorite and not Beloved Status!",
1505+
"type": "string",
1506+
},
1507+
},
1508+
"evaluatedHierarchies": Array [
1509+
Object {
1510+
"levels": Array [
1511+
"orders_view.my_beloved_status",
1512+
],
1513+
"name": "hello",
1514+
"title": "World",
1515+
},
1516+
],
1517+
"fileName": "order_view.yml",
1518+
"hierarchies": Object {
1519+
"hello": Object {
1520+
"levels": [Function],
1521+
"title": "My Overridden hierarchy!",
1522+
},
1523+
},
1524+
"includedMembers": Array [
1525+
Object {
1526+
"memberPath": "orders.hello",
1527+
"name": "hello",
1528+
"type": "hierarchies",
1529+
},
1530+
Object {
1531+
"memberPath": "orders.count",
1532+
"name": "count",
1533+
"type": "measures",
1534+
},
1535+
Object {
1536+
"memberPath": "orders.status",
1537+
"name": "my_beloved_status",
1538+
"type": "dimensions",
1539+
},
1540+
Object {
1541+
"memberPath": "orders.created_at",
1542+
"name": "my_beloved_created_at",
1543+
"type": "dimensions",
1544+
},
1545+
],
1546+
"isView": true,
1547+
"joins": Object {},
1548+
"measures": Object {
1549+
"count": Object {
1550+
"aggType": "count",
1551+
"aliasMember": "orders.count",
1552+
"description": "It's not possible!",
1553+
"format": "percent",
1554+
"meta": Array [
1555+
Object {
1556+
"whose": "bread",
1557+
},
1558+
Object {
1559+
"what": "butter",
1560+
},
1561+
Object {
1562+
"why": "cheese",
1563+
},
1564+
],
1565+
"ownedByCube": false,
1566+
"sql": [Function],
1567+
"title": "My Overridden Count!",
1568+
"type": "number",
1569+
},
1570+
},
1571+
"name": "orders_view",
1572+
"preAggregations": Object {},
1573+
"segments": Object {},
1574+
}
1575+
`;

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

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

0 commit comments

Comments
 (0)