Skip to content

Commit bedb8c5

Browse files
committed
more tests
1 parent e3e242c commit bedb8c5

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

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

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,44 @@ const cubeDefs: CubeDefinition[] = [
8383
CheckinCreatedAt: { type: 'time', sql: () => 'created_at' },
8484
},
8585
},
86+
87+
// Separate graph configuration with loops
88+
{
89+
name: 'view',
90+
isView: true,
91+
cubes: [
92+
{ join_path: () => 'A', includes: ['aid'] },
93+
]
94+
},
95+
{
96+
name: 'A',
97+
dimensions: { aid: { type: 'number', sql: () => 'aid' } },
98+
joins: {
99+
B: { relationship: 'hasMany', sql: (CUBE) => 'join' },
100+
D: { relationship: 'hasMany', sql: (CUBE) => 'join' }
101+
},
102+
},
103+
{
104+
name: 'B',
105+
dimensions: { bid: { type: 'number', sql: () => 'bid' } },
106+
joins: {
107+
A: { relationship: 'hasMany', sql: (CUBE) => 'join' },
108+
E: { relationship: 'hasMany', sql: (CUBE) => 'join' }
109+
},
110+
},
111+
{
112+
name: 'D',
113+
dimensions: { did: { type: 'number', sql: () => 'did' } },
114+
joins: {
115+
A: { relationship: 'hasMany', sql: (CUBE) => 'join' },
116+
B: { relationship: 'hasMany', sql: (CUBE) => 'join' },
117+
E: { relationship: 'hasMany', sql: (CUBE) => 'join' }
118+
},
119+
},
120+
{
121+
name: 'E',
122+
dimensions: { eid: { type: 'number', sql: () => 'eid' } },
123+
},
86124
];
87125

88126
describe('Cube Symbols Compiler', () => {
@@ -155,6 +193,26 @@ describe('Cube Symbols Compiler', () => {
155193
expect(() => reporter.throwIfAny()).toThrow(/sum defined more than once/);
156194
});
157195

196+
it('throws error if dependency loop involving view is detected', () => {
197+
process.env.CUBEJS_CASE_INSENSITIVE_DUPLICATES_CHECK = 'true';
198+
199+
const reporter = new ConsoleErrorReporter();
200+
const compiler = new CubeSymbols(true);
201+
202+
const cubeDefsTest: CubeDefinition[] = [...cubeDefs];
203+
// Change the A cube to be a view
204+
cubeDefsTest[7] = {
205+
name: 'A',
206+
isView: true,
207+
cubes: [
208+
{ join_path: () => 'B', includes: ['bid'] },
209+
{ join_path: () => 'D', includes: ['did'] },
210+
]
211+
};
212+
213+
expect(() => compiler.compile(cubeDefsTest, reporter)).toThrow(/A view cannot be part of a dependency loop/);
214+
});
215+
158216
it('compiles correct cubes and views (case sensitive)', () => {
159217
process.env.CUBEJS_CASE_INSENSITIVE_DUPLICATES_CHECK = 'false';
160218

0 commit comments

Comments
 (0)