2019-07-29 13:42:37 +07:00
|
|
|
import { handleResponseType } from '../../src/utils/api';
|
|
|
|
|
|
|
|
describe('api', () => {
|
|
|
|
describe('handleResponseType', () => {
|
2019-08-08 19:26:30 +07:00
|
|
|
test('should handle missing Content-Type', async () => {
|
|
|
|
const response: Response = {
|
|
|
|
url: 'http://localhost:8080/-/packages',
|
|
|
|
ok: false,
|
2019-10-23 03:31:39 +07:00
|
|
|
headers: new Headers(),
|
2019-08-08 19:26:30 +07:00
|
|
|
} as Response;
|
|
|
|
|
|
|
|
const handled = await handleResponseType(response);
|
|
|
|
|
|
|
|
// Should this actually return [false, null] ?
|
|
|
|
expect(handled).toBeUndefined();
|
|
|
|
});
|
|
|
|
|
2019-07-29 13:42:37 +07:00
|
|
|
test('should test tgz scenario', async () => {
|
|
|
|
const blob = new Blob(['foo']);
|
|
|
|
const blobPromise = Promise.resolve<Blob>(blob);
|
|
|
|
const response: Response = {
|
|
|
|
url: 'http://localhost:8080/bootstrap/-/bootstrap-4.3.1.tgz',
|
|
|
|
blob: () => blobPromise,
|
|
|
|
ok: true,
|
2019-10-23 03:31:39 +07:00
|
|
|
headers: new Headers(),
|
2019-07-29 13:42:37 +07:00
|
|
|
} as Response;
|
|
|
|
const handled = await handleResponseType(response);
|
|
|
|
|
|
|
|
expect(handled).toEqual([true, blob]);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|