mirror of
https://github.com/apache/superset.git
synced 2024-09-19 20:19:37 -04:00
fix: broken build due to failing unit tests (#141)
* fix: callapi unit test * test: fix async calls * fix: remaining test * refactor: do not declare unused var
This commit is contained in:
parent
6421d4b514
commit
d6f39335d8
@ -314,27 +314,24 @@ describe('callApi()', () => {
|
||||
);
|
||||
}));
|
||||
|
||||
it('works when the Cache API is disabled', () => {
|
||||
it('works when the Cache API is disabled', async () => {
|
||||
Object.defineProperty(constants, 'CACHE_AVAILABLE', { value: false });
|
||||
|
||||
return callApi({ url: mockCacheUrl, method: 'GET' }).then(firstResponse => {
|
||||
const firstResponse = await callApi({ url: mockCacheUrl, method: 'GET' });
|
||||
const calls = fetchMock.calls(mockCacheUrl);
|
||||
expect(calls).toHaveLength(1);
|
||||
expect(firstResponse.body).toEqual('BODY');
|
||||
const firstBody = await firstResponse.text();
|
||||
expect(firstBody).toEqual('BODY');
|
||||
|
||||
return callApi({ url: mockCacheUrl, method: 'GET' }).then(secondResponse => {
|
||||
const secondResponse = await callApi({ url: mockCacheUrl, method: 'GET' });
|
||||
const fetchParams = calls[1][1];
|
||||
expect(calls).toHaveLength(2);
|
||||
|
||||
// second call should not have If-None-Match header
|
||||
expect(fetchParams.headers).toBeUndefined();
|
||||
expect(secondResponse.body).toEqual('BODY');
|
||||
const secondBody = await secondResponse.text();
|
||||
expect(secondBody).toEqual('BODY');
|
||||
|
||||
Object.defineProperty(constants, 'CACHE_AVAILABLE', { value: true });
|
||||
|
||||
return Promise.resolve();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('sends known ETags in the If-None-Match header', () =>
|
||||
@ -354,23 +351,20 @@ describe('callApi()', () => {
|
||||
});
|
||||
}));
|
||||
|
||||
it('reuses cached responses on 304 status', () =>
|
||||
it('reuses cached responses on 304 status', async () => {
|
||||
// first call sets the cache
|
||||
callApi({ url: mockCacheUrl, method: 'GET' }).then(() => {
|
||||
await callApi({ url: mockCacheUrl, method: 'GET' });
|
||||
const calls = fetchMock.calls(mockCacheUrl);
|
||||
expect(calls).toHaveLength(1);
|
||||
|
||||
// second call reuses the cached payload on a 304
|
||||
const mockCachedPayload = { status: 304 };
|
||||
fetchMock.get(mockCacheUrl, mockCachedPayload, { overwriteRoutes: true });
|
||||
|
||||
return callApi({ url: mockCacheUrl, method: 'GET' }).then(response => {
|
||||
const secondResponse = await callApi({ url: mockCacheUrl, method: 'GET' });
|
||||
expect(calls).toHaveLength(2);
|
||||
expect(response.body).toEqual('BODY');
|
||||
|
||||
return Promise.resolve();
|
||||
const secondBody = await secondResponse.text();
|
||||
expect(secondBody).toEqual('BODY');
|
||||
});
|
||||
}));
|
||||
|
||||
it('throws error when cache fails on 304', () => {
|
||||
// this should never happen, since a 304 is only returned if we have
|
||||
|
Loading…
Reference in New Issue
Block a user