diff --git a/src/components/ActionBar/ActionBar.test.tsx b/src/components/ActionBar/ActionBar.test.tsx index 59cea7b..e227f45 100644 --- a/src/components/ActionBar/ActionBar.test.tsx +++ b/src/components/ActionBar/ActionBar.test.tsx @@ -44,7 +44,7 @@ describe(' component', () => { const ActionBar = require('./ActionBar').default; const wrapper = shallow(); // FIXME: this only renders the DetailContextConsumer, thus - // the wrapper will be + // the wrapper will be always empty expect(wrapper.html()).toEqual(''); }); diff --git a/src/utils/api.test.ts b/src/utils/api.test.ts new file mode 100644 index 0000000..bf5824b --- /dev/null +++ b/src/utils/api.test.ts @@ -0,0 +1,28 @@ +/* eslint-disable @typescript-eslint/no-object-literal-type-assertion */ + +import { handleResponseType } from '../../src/utils/api'; + +describe('api', () => { + // no the best mock, but I'd look for a mock library to work with fetch in the future + // @ts-ignore + const headers: Headers = { + // @ts-ignore + get: () => [], + }; + + describe('handleResponseType', () => { + test('should test tgz scenario', async () => { + const blob = new Blob(['foo']); + const blobPromise = Promise.resolve(blob); + const response: Response = { + url: 'http://localhost:8080/bootstrap/-/bootstrap-4.3.1.tgz', + blob: () => blobPromise, + ok: true, + headers, + } as Response; + const handled = await handleResponseType(response); + + expect(handled).toEqual([true, blob]); + }); + }); +}); diff --git a/src/utils/api.ts b/src/utils/api.ts index c869881..3d95a5e 100644 --- a/src/utils/api.ts +++ b/src/utils/api.ts @@ -6,7 +6,7 @@ import '../../types'; * @param {object} response * @returns {promise} */ -function handleResponseType(response: Response): Promise<[boolean, Blob | string]> | Promise { +export function handleResponseType(response: Response): Promise<[boolean, Blob | string]> | Promise { if (response.headers) { const contentType = response.headers.get('Content-Type') as string; if (contentType.includes('application/pdf')) { @@ -21,7 +21,7 @@ function handleResponseType(response: Response): Promise<[boolean, Blob | string } // unfortunatelly on download files there is no header available - if (response.url && response.url.match(/.tgz/) !== null) { + if (response.url && response.url.endsWith('.tgz') !== null) { return Promise.all([response.ok, response.blob()]); } }