Skip to content

Commit 33b56bc

Browse files
committed
add schema tests for joins as array/object
1 parent 47e353b commit 33b56bc

File tree

2 files changed

+111
-31
lines changed

2 files changed

+111
-31
lines changed

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

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2091,6 +2091,46 @@ Array [
20912091
]
20922092
`;
20932093

2094+
exports[`Schema Testing join types (joins as array) 1`] = `
2095+
Array [
2096+
Object {
2097+
"name": "CubeB",
2098+
"relationship": "hasOne",
2099+
"sql": [Function],
2100+
},
2101+
Object {
2102+
"name": "CubeC",
2103+
"relationship": "hasMany",
2104+
"sql": [Function],
2105+
},
2106+
Object {
2107+
"name": "CubeD",
2108+
"relationship": "belongsTo",
2109+
"sql": [Function],
2110+
},
2111+
]
2112+
`;
2113+
2114+
exports[`Schema Testing join types (joins as object) 1`] = `
2115+
Array [
2116+
Object {
2117+
"name": "CubeB",
2118+
"relationship": "hasOne",
2119+
"sql": [Function],
2120+
},
2121+
Object {
2122+
"name": "CubeC",
2123+
"relationship": "hasMany",
2124+
"sql": [Function],
2125+
},
2126+
Object {
2127+
"name": "CubeD",
2128+
"relationship": "belongsTo",
2129+
"sql": [Function],
2130+
},
2131+
]
2132+
`;
2133+
20942134
exports[`Schema Testing join types 1`] = `
20952135
Array [
20962136
Object {

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

Lines changed: 71 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -416,38 +416,78 @@ describe('Schema Testing', () => {
416416
expect(gr.origin).toBe('2020-06-01 10:00:00');
417417
});
418418

419-
it('join types', async () => {
420-
const { compiler, cubeEvaluator } = prepareJsCompiler([
421-
createCubeSchema({
422-
name: 'CubeA',
423-
joins: `{
424-
CubeB: {
425-
sql: \`SQL ON clause\`,
426-
relationship: 'one_to_one'
427-
},
428-
CubeC: {
429-
sql: \`SQL ON clause\`,
430-
relationship: 'one_to_many'
431-
},
432-
CubeD: {
433-
sql: \`SQL ON clause\`,
434-
relationship: 'many_to_one'
435-
},
436-
}`
437-
}),
438-
createCubeSchema({
439-
name: 'CubeB',
440-
}),
441-
createCubeSchema({
442-
name: 'CubeC',
443-
}),
444-
createCubeSchema({
445-
name: 'CubeD',
446-
}),
447-
]);
448-
await compiler.compile();
419+
describe('Joins', () => {
420+
it('join types (joins as object)', async () => {
421+
const { compiler, cubeEvaluator } = prepareJsCompiler([
422+
createCubeSchema({
423+
name: 'CubeA',
424+
joins: `{
425+
CubeB: {
426+
sql: \`SQL ON clause\`,
427+
relationship: 'one_to_one'
428+
},
429+
CubeC: {
430+
sql: \`SQL ON clause\`,
431+
relationship: 'one_to_many'
432+
},
433+
CubeD: {
434+
sql: \`SQL ON clause\`,
435+
relationship: 'many_to_one'
436+
},
437+
}`
438+
}),
439+
createCubeSchema({
440+
name: 'CubeB',
441+
}),
442+
createCubeSchema({
443+
name: 'CubeC',
444+
}),
445+
createCubeSchema({
446+
name: 'CubeD',
447+
}),
448+
]);
449+
await compiler.compile();
450+
451+
expect(cubeEvaluator.cubeFromPath('CubeA').joins).toMatchSnapshot();
452+
});
453+
454+
it('join types (joins as array)', async () => {
455+
const { compiler, cubeEvaluator } = prepareJsCompiler([
456+
createCubeSchema({
457+
name: 'CubeA',
458+
joins: `[
459+
{
460+
name: 'CubeB',
461+
sql: \`SQL ON clause\`,
462+
relationship: 'one_to_one'
463+
},
464+
{
465+
name: 'CubeC',
466+
sql: \`SQL ON clause\`,
467+
relationship: 'one_to_many'
468+
},
469+
{
470+
name: 'CubeD',
471+
sql: \`SQL ON clause\`,
472+
relationship: 'many_to_one'
473+
},
474+
]`
475+
}),
476+
createCubeSchema({
477+
name: 'CubeB',
478+
}),
479+
createCubeSchema({
480+
name: 'CubeC',
481+
}),
482+
createCubeSchema({
483+
name: 'CubeD',
484+
}),
485+
]);
486+
await compiler.compile();
487+
488+
expect(cubeEvaluator.cubeFromPath('CubeA').joins).toMatchSnapshot();
489+
});
449490

450-
expect(cubeEvaluator.cubeFromPath('CubeA').joins).toMatchSnapshot();
451491
});
452492

453493
describe('Access Policies', () => {

0 commit comments

Comments
 (0)