// @ts-ignore import { fetchMock } from 'fetch-mock'; import AssetApi from './asset-api'; describe('Asset API', () => { afterEach(() => { fetchMock.restore(); }); const assetId4 = { $type: '', alt: 'new', blobstoreUrl: '', centerPoint: { $type: '', x: 1, y: 1 }, contentType: '', created: '', createdOn: '', height: 4, id: '4', imageUrl: '', isDeleted: false, modified: '', previewData: '', size: 10, sourceId: '', title: '', variants: [ { $type: '', id: '1', name: 'variant', fixedAspectRatio: 1, isUntouched: false, isDefaultVariant: false, crop: { $type: '', centerPoint: { $type: '', x: 1, y: 1 }, width: 2, height: 2 } } ], width: 2, }; const assetId5 = { $type: '', alt: 'new', blobstoreUrl: '', centerPoint: { x: 1, y: 1 }, contentType: '', created: '', createdOn: '', height: 4, id: '5', imageUrl: '', isDeleted: false, modified: '', previewData: '', size: 10, sourceId: '', title: '', variants: [ { $type: '', id: '1', name: 'variant', fixedAspectRatio: 1, isUntouched: false, isDefaultVariant: false, crop: { $type: '', centerPoint: { $type: '', x: 1, y: 1 }, width: 2, height: 2 } } ], width: 2, }; it('should return asset by ID', async () => { fetchMock.get(/api\/assets\/4/, { status: 200, body: assetId4, }); fetchMock.get(/api\/assets\/5/, { status: 200, body: assetId5, }); const response = await AssetApi.getAssetById('4'); expect(response).toEqual(assetId4); }); it('should handle empty guid as ID', async () => { fetchMock.get(/api\/assets\/0/, { status: 204, }); const response = await AssetApi.getAssetById('0'); expect(response).toEqual(null); }); });