Skip to content

Commit f262fc5

Browse files
committed
fix(api-gateway): Fix member sql extraction in meta?extended
1 parent fa35c0a commit f262fc5

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

packages/cubejs-api-gateway/src/helpers/transformMetaExtended.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ function stringifyMemberSql(sql?: () => string) {
44
}
55

66
const sqlStr = sql.toString();
7-
return sqlStr.substring(sqlStr.indexOf('=>') + 3);
7+
return sqlStr.substring(sqlStr.indexOf('=>') + 2).trim();
88
}
99

1010
type MemberPath = {

packages/cubejs-api-gateway/test/helpers/transformMetaExtended.test.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,41 @@ describe('transformMetaExtended helpers', () => {
162162
expect(handledCube).toHaveProperty('dimensions');
163163
});
164164

165+
test('transformCube - extends field preservation', () => {
166+
const mockCubeDefinitions = {
167+
BaseCube: { extends: () => 'BaseCube' },
168+
ExtendedCube: { extends: () => 'ExtendedCube' },
169+
AnotherCube: { extends: () => 'AnotherCube' },
170+
TestCube: { extends: () => 'TestCube' },
171+
SampleCube: { extends: () => 'SampleCube' }
172+
};
173+
174+
const mockCubes = [
175+
{ name: 'BaseCube' },
176+
{ name: 'ExtendedCube' },
177+
{ name: 'AnotherCube' },
178+
{ name: 'TestCube' },
179+
{ name: 'SampleCube' }
180+
];
181+
182+
mockCubes.forEach(cube => {
183+
const transformedCube = transformCube(cube, mockCubeDefinitions);
184+
expect(transformedCube).toBeDefined();
185+
expect(transformedCube.extends).toBe(`'${cube.name}'`);
186+
// Verify the first letter is not truncated
187+
expect(transformedCube.extends).not.toBe(`'${cube.name.substring(1)}'`);
188+
});
189+
190+
// Specific test cases to verify first letter preservation
191+
const baseCube = transformCube({ name: 'BaseCube' }, mockCubeDefinitions);
192+
expect(baseCube.extends).toBe('\'BaseCube\'');
193+
expect(baseCube.extends).not.toBe('\'aseCube\''); // Should not be truncated
194+
195+
const extendedCube = transformCube({ name: 'ExtendedCube' }, mockCubeDefinitions);
196+
expect(extendedCube.extends).toBe('\'ExtendedCube\'');
197+
expect(extendedCube.extends).not.toBe('\'xtendedCube\''); // Should not be truncated
198+
});
199+
165200
test('transformDimension', () => {
166201
const handledDimension = transformDimension(MOCK_USERS_CUBE.dimensions.id, MOCK_USERS_CUBE);
167202
expect(handledDimension).toBeDefined();

0 commit comments

Comments
 (0)