Skip to content

Commit

Permalink
add tests for custom granularity in query annotation
Browse files Browse the repository at this point in the history
  • Loading branch information
KSDaemon committed Sep 24, 2024
1 parent f2357bd commit a3349ac
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
22 changes: 22 additions & 0 deletions packages/cubejs-api-gateway/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,28 @@ describe('API Gateway', () => {
expect(res.body && res.body.data).toStrictEqual([{ 'Foo.bar': 42 }]);
});

test('custom granularities in annotation', async () => {
const { app } = await createApiGateway();

const res = await request(app)
.get(
'/cubejs-api/v1/load?query={"measures":["Foo.bar"],"timeDimensions":[{"dimension":"Foo.timeGranularities","granularity":"half_year_by_1st_april"}]}'
)
.set('Authorization', 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.t-IDcSemACt8x4iTMCda8Yhe3iZaWbvV5XKSTbuAn0M')

Check failure

Code scanning / CodeQL

Hard-coded credentials Critical test

The hard-coded value "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.e30.t-IDcSemACt8x4iTMCda8Yhe3iZaWbvV5XKSTbuAn0M" is used as
authorization header
.
.expect(200);
console.log(res.body);
expect(res.body && res.body.data).toStrictEqual([{ 'Foo.bar': 42 }]);
expect(res.body.annotation.timeDimensions['Foo.timeGranularities.half_year_by_1st_april'])
.toStrictEqual({
granularities: [{
name: 'half_year_by_1st_april',
title: 'Half Year By1 St April',
interval: '6 months',
offset: '3 months',
}]
});
});

test('dry-run', async () => {
const { app } = await createApiGateway();

Expand Down
12 changes: 12 additions & 0 deletions packages/cubejs-api-gateway/test/mocks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,18 @@ export const compilerApi = jest.fn().mockImplementation(async () => ({
name: 'Foo.time',
isVisible: true,
},
{
name: 'Foo.timeGranularities',
isVisible: true,
granularities: [
{
name: 'half_year_by_1st_april',
title: 'Half Year By1 St April',
interval: '6 months',
offset: '3 months'
}
]
},
],
segments: [
{
Expand Down

0 comments on commit a3349ac

Please sign in to comment.