From 8d4994a89900c2cf636444e4febad61ce3b69d68 Mon Sep 17 00:00:00 2001 From: Yongjie Zhao Date: Tue, 12 Jul 2022 13:34:27 +0800 Subject: [PATCH] fix: superset-ui/core code coverage (#20676) --- .../superset-ui-core/src/query/processFilters.ts | 3 --- .../test/connection/SupersetClient.test.ts | 10 +++++++++- .../test/connection/SupersetClientClass.test.ts | 3 ++- .../superset-ui-core/test/query/processFilters.test.ts | 8 ++++++++ 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/superset-frontend/packages/superset-ui-core/src/query/processFilters.ts b/superset-frontend/packages/superset-ui-core/src/query/processFilters.ts index ba7131b0e12b0..8ad1f8b620db4 100644 --- a/superset-frontend/packages/superset-ui-core/src/query/processFilters.ts +++ b/superset-frontend/packages/superset-ui-core/src/query/processFilters.ts @@ -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[] = []; @@ -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; diff --git a/superset-frontend/packages/superset-ui-core/test/connection/SupersetClient.test.ts b/superset-frontend/packages/superset-ui-core/test/connection/SupersetClient.test.ts index 17a07f3c727e6..caba59f563722 100644 --- a/superset-frontend/packages/superset-ui-core/test/connection/SupersetClient.test.ts +++ b/superset-frontend/packages/superset-ui-core/test/connection/SupersetClient.test.ts @@ -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'); }); @@ -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'; @@ -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(); @@ -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); diff --git a/superset-frontend/packages/superset-ui-core/test/connection/SupersetClientClass.test.ts b/superset-frontend/packages/superset-ui-core/test/connection/SupersetClientClass.test.ts index 4db26b05b4151..56ab3f1baea07 100644 --- a/superset-frontend/packages/superset-ui-core/test/connection/SupersetClientClass.test.ts +++ b/superset-frontend/packages/superset-ui-core/test/connection/SupersetClientClass.test.ts @@ -329,7 +329,7 @@ describe('SupersetClientClass', () => { }); it('uses a guest token when provided', async () => { - expect.assertions(1); + expect.assertions(2); const client = new SupersetClientClass({ protocol, @@ -337,6 +337,7 @@ describe('SupersetClientClass', () => { guestToken: 'abc123', guestTokenHeaderName: 'guestTokenHeader', }); + expect(client.getGuestToken()).toBe('abc123'); await client.init(); await client.get({ url: mockGetUrl }); diff --git a/superset-frontend/packages/superset-ui-core/test/query/processFilters.test.ts b/superset-frontend/packages/superset-ui-core/test/query/processFilters.test.ts index 81c8fca2cb939..0d4fc4cd9f7c7 100644 --- a/superset-frontend/packages/superset-ui-core/test/query/processFilters.test.ts +++ b/superset-frontend/packages/superset-ui-core/test/query/processFilters.test.ts @@ -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({