|
1 | 1 | import fetchMock from 'fetch-mock'; |
2 | | - |
3 | | -import { BigNumber } from 'bignumber.js'; |
4 | 2 | import { SupersetClientClass, ClientConfig } from '../src'; |
5 | 3 | import throwIfCalled from './utils/throwIfCalled'; |
6 | 4 | import { LOGIN_GLOB } from './fixtures/constants'; |
7 | 5 |
|
8 | | -/* NOTE: We're using fetchMock v6.5.2, but corresponding fetchMock type declaration files are only available for v6.0.2 |
9 | | - * and v7+. It looks like there are behavior changes between v6 and v7 that break our tests, so upgrading to v7 is |
10 | | - * probably some work. |
11 | | - * |
12 | | - * To avoid this, we're using the type declarations for v6.0.2, but there is at least one API inconsistency between that |
13 | | - * type declaration file and the actual library we're using. It looks like `sendAsJson` was added sometime after that |
14 | | - * release, or else the type declaration file isn't completely accurate. To get around this, it's necessary to add |
15 | | - * a `@ts-ignore` decorator before references to `sendAsJson` (there's one instance of that in this file). |
16 | | - * |
17 | | - * The **right** solution is probably to upgrade to fetchMock v7 (and the latest type declaration) and fix the tests |
18 | | - * that become broken as a result. |
19 | | - */ |
20 | 6 | describe('SupersetClientClass', () => { |
21 | 7 | beforeAll(() => { |
22 | 8 | fetchMock.get(LOGIN_GLOB, { csrf_token: '' }); |
@@ -138,8 +124,6 @@ describe('SupersetClientClass', () => { |
138 | 124 | it('does not set csrfToken if response is not json', () => { |
139 | 125 | fetchMock.get(LOGIN_GLOB, '123', { |
140 | 126 | overwriteRoutes: true, |
141 | | - // @TODO remove once fetchMock is upgraded to 7+, see note at top of this file |
142 | | - // @ts-ignore |
143 | 127 | sendAsJson: false, |
144 | 128 | }); |
145 | 129 |
|
@@ -267,8 +251,7 @@ describe('SupersetClientClass', () => { |
267 | 251 | const mockTextUrl = `${protocol}//${host}${mockTextEndpoint}`; |
268 | 252 | const mockPutUrl = `${protocol}//${host}${mockPutEndpoint}`; |
269 | 253 | const mockDeleteUrl = `${protocol}//${host}${mockDeleteEndpoint}`; |
270 | | - const mockBigNumber = '9223372036854775807'; |
271 | | - const mockTextJsonResponse = `{ "value": ${mockBigNumber} }`; |
| 254 | + const mockTextJsonResponse = '{ "value": 9223372036854775807 }'; |
272 | 255 |
|
273 | 256 | fetchMock.get(mockGetUrl, { json: 'payload' }); |
274 | 257 | fetchMock.post(mockPostUrl, { json: 'payload' }); |
@@ -347,21 +330,6 @@ describe('SupersetClientClass', () => { |
347 | 330 | ); |
348 | 331 | }); |
349 | 332 |
|
350 | | - it('supports parsing a response as JSON while preserving precision of large numbers', () => { |
351 | | - expect.assertions(2); |
352 | | - const client = new SupersetClientClass({ protocol, host }); |
353 | | - |
354 | | - return client.init().then(() => |
355 | | - client.get({ url: mockTextUrl }).then(({ json }) => { |
356 | | - expect(fetchMock.calls(mockTextUrl)).toHaveLength(1); |
357 | | - // @ts-ignore |
358 | | - expect(json.value.toString()).toBe(new BigNumber(mockBigNumber).toString()); |
359 | | - |
360 | | - return Promise.resolve(); |
361 | | - }), |
362 | | - ); |
363 | | - }); |
364 | | - |
365 | 333 | it('supports parsing a response as text', () => { |
366 | 334 | expect.assertions(2); |
367 | 335 | const client = new SupersetClientClass({ protocol, host }); |
@@ -471,21 +439,6 @@ describe('SupersetClientClass', () => { |
471 | 439 | ); |
472 | 440 | }); |
473 | 441 |
|
474 | | - it('supports parsing a response as JSON while preserving precision of large numbers', () => { |
475 | | - expect.assertions(2); |
476 | | - const client = new SupersetClientClass({ protocol, host }); |
477 | | - |
478 | | - return client.init().then(() => |
479 | | - client.post({ url: mockTextUrl }).then(({ json }) => { |
480 | | - expect(fetchMock.calls(mockTextUrl)).toHaveLength(1); |
481 | | - // @ts-ignore |
482 | | - expect(json.value.toString()).toBe(new BigNumber(mockBigNumber).toString()); |
483 | | - |
484 | | - return Promise.resolve(); |
485 | | - }), |
486 | | - ); |
487 | | - }); |
488 | | - |
489 | 442 | it('supports parsing a response as text', () => { |
490 | 443 | expect.assertions(2); |
491 | 444 | const client = new SupersetClientClass({ protocol, host }); |
|
0 commit comments