Skip to content

Commit

Permalink
fix: superset-ui/core code coverage (#20676)
Browse files Browse the repository at this point in the history
  • Loading branch information
zhaoyongjie authored Jul 12, 2022
1 parent d4b59ff commit 8d4994a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ export default function processFilters(
const { adhoc_filters, extras = {}, filters = [], where } = formData;
const simpleWhere: QueryObjectFilterClause[] = filters;

const simpleHaving: QueryObjectFilterClause[] = [];
const freeformWhere: string[] = [];
if (where) freeformWhere.push(where);
const freeformHaving: string[] = [];
Expand All @@ -54,8 +53,6 @@ export default function processFilters(
const filterClause = convertFilter(filter);
if (clause === 'WHERE') {
simpleWhere.push(filterClause);
} else {
simpleHaving.push(filterClause);
}
} else {
const { sqlExpression } = filter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ describe('SupersetClient', () => {
expect(typeof SupersetClient.postForm).toBe('function');
expect(typeof SupersetClient.isAuthenticated).toBe('function');
expect(typeof SupersetClient.reAuthenticate).toBe('function');
expect(typeof SupersetClient.getGuestToken).toBe('function');
expect(typeof SupersetClient.request).toBe('function');
expect(typeof SupersetClient.reset).toBe('function');
});
Expand All @@ -55,7 +56,7 @@ describe('SupersetClient', () => {

// this also tests that the ^above doesn't throw if configure is called appropriately
it('calls appropriate SupersetClient methods when configured', async () => {
expect.assertions(15);
expect.assertions(16);
const mockGetUrl = '/mock/get/url';
const mockPostUrl = '/mock/post/url';
const mockRequestUrl = '/mock/request/url';
Expand All @@ -82,6 +83,10 @@ describe('SupersetClient', () => {
);
const csrfSpy = jest.spyOn(SupersetClientClass.prototype, 'getCSRFToken');
const requestSpy = jest.spyOn(SupersetClientClass.prototype, 'request');
const getGuestTokenSpy = jest.spyOn(
SupersetClientClass.prototype,
'getGuestToken',
);

SupersetClient.configure({});
await SupersetClient.init();
Expand Down Expand Up @@ -114,6 +119,9 @@ describe('SupersetClient', () => {
SupersetClient.isAuthenticated();
await SupersetClient.reAuthenticate();

SupersetClient.getGuestToken();
expect(getGuestTokenSpy).toHaveBeenCalledTimes(1);

expect(initSpy).toHaveBeenCalledTimes(2);
expect(deleteSpy).toHaveBeenCalledTimes(1);
expect(putSpy).toHaveBeenCalledTimes(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,14 +329,15 @@ describe('SupersetClientClass', () => {
});

it('uses a guest token when provided', async () => {
expect.assertions(1);
expect.assertions(2);

const client = new SupersetClientClass({
protocol,
host,
guestToken: 'abc123',
guestTokenHeaderName: 'guestTokenHeader',
});
expect(client.getGuestToken()).toBe('abc123');

await client.init();
await client.get({ url: mockGetUrl });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,14 @@ describe('processFilters', () => {
subject: 'gender',
operator: 'IS NOT NULL',
},
// ignore simple having filter
{
expressionType: 'SIMPLE',
clause: 'HAVING',
subject: 'sum(sales)',
operator: '>',
comparator: '100',
},
],
}),
).toEqual({
Expand Down

0 comments on commit 8d4994a

Please sign in to comment.