mirror of
https://github.com/SomboChea/ui
synced 2024-06-16 00:19:42 +07:00
35 lines
1.0 KiB
TypeScript
35 lines
1.0 KiB
TypeScript
/* eslint-disable @typescript-eslint/no-object-literal-type-assertion */
|
|
|
|
import { handleResponseType } from '../../src/utils/api';
|
|
|
|
describe('api', () => {
|
|
describe('handleResponseType', () => {
|
|
test('should handle missing Content-Type', async () => {
|
|
const response: Response = {
|
|
url: 'http://localhost:8080/-/packages',
|
|
ok: false,
|
|
headers: new Headers(),
|
|
} as Response;
|
|
|
|
const handled = await handleResponseType(response);
|
|
|
|
// Should this actually return [false, null] ?
|
|
expect(handled).toBeUndefined();
|
|
});
|
|
|
|
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,
|
|
headers: new Headers(),
|
|
} as Response;
|
|
const handled = await handleResponseType(response);
|
|
|
|
expect(handled).toEqual([true, blob]);
|
|
});
|
|
});
|
|
});
|