Skip to content

Commit 4935989

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

File tree

2 files changed

+37
-1
lines changed

2 files changed

+37
-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: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,42 @@ describe('transformMetaExtended helpers', () => {
162162
expect(handledCube).toHaveProperty('dimensions');
163163
});
164164

165+
test('transformCube - extends field preservation', () => {
166+
// Test cases from the reported bug: extends field missing first letter
167+
const mockCubeDefinitions = {
168+
AncillaryReview: { extends: () => 'AncillaryReview' },
169+
Agreement: { extends: () => 'Agreement' },
170+
ApiProjectRisk: { extends: () => 'ApiProjectRisk' },
171+
Disclosure: { extends: () => 'Disclosure' },
172+
Certification: { extends: () => 'Certification' }
173+
};
174+
175+
const mockCubes = [
176+
{ name: 'AncillaryReview' },
177+
{ name: 'Agreement' },
178+
{ name: 'ApiProjectRisk' },
179+
{ name: 'Disclosure' },
180+
{ name: 'Certification' }
181+
];
182+
183+
mockCubes.forEach(cube => {
184+
const transformedCube = transformCube(cube, mockCubeDefinitions);
185+
expect(transformedCube).toBeDefined();
186+
expect(transformedCube.extends).toBe(`"${cube.name}"`);
187+
// Verify the first letter is not truncated
188+
expect(transformedCube.extends).not.toBe(`"${cube.name.substring(1)}"`);
189+
});
190+
191+
// Specific test for the reported examples
192+
const ancillaryReviewCube = transformCube({ name: 'AncillaryReview' }, mockCubeDefinitions);
193+
expect(ancillaryReviewCube.extends).toBe('"AncillaryReview"');
194+
expect(ancillaryReviewCube.extends).not.toBe('"ncillaryReview"'); // Should not be truncated
195+
196+
const agreementCube = transformCube({ name: 'Agreement' }, mockCubeDefinitions);
197+
expect(agreementCube.extends).toBe('"Agreement"');
198+
expect(agreementCube.extends).not.toBe('"greement"'); // Should not be truncated
199+
});
200+
165201
test('transformDimension', () => {
166202
const handledDimension = transformDimension(MOCK_USERS_CUBE.dimensions.id, MOCK_USERS_CUBE);
167203
expect(handledDimension).toBeDefined();

0 commit comments

Comments
 (0)