// @ts-ignore import { getPreviewUrlForAsset } from './asset-api-helpers'; describe('Asset API helpers', () => { it('should return correct preview url for an existing image', () => { const asset = { $type: 'Q42.Cms.Core.Domain.CmsAsset, Q42.Cms.Core.Domain', alt: 'cccdddd', alts: {}, blobstoreUrl: 'https://nederlandseloterij.blob.core.windows.net/assets/146F6931-B2E8-4D2A-9E15-3988E1BDBA99', centerPoint: { $type: 'Q42.Cms.Core.Domain.CenterPoint, Q42.Cms.Core.Domain', x: 318, y: 428, }, contentType: 'image/png', created: '2019-10-22T08:18:18.185013+02:00', createdOn: '2019-10-22T06:18:18.185019+00:00', createdBy: null, height: 2100, id: '146f6931-b2e8-4d2a-9e15-3988e1bdba99', imageUrl: 'https://localhost:44342/assets/146f6931-b2e8-4d2a-9e15-3988e1bdba99?w=200&c=c4a8d16a677479be1adc6b6b9b1b8771ee951a6b048cb5d65b61f5611836cd4d', isDeleted: false, modified: '2019-10-22T08:18:18.185013+02:00', modifiedBy: null, previewData: 'BCAAbACADQf/aAAwDAQACEQMRAD8AWrStKKsiFRUYDP1ObLd0lrMCNpx9qC1oTJobQ0Ih6WdowAU4xjTmOpUUmfkazxcb9B0jgxNCVbrtSnp6Y1NNjamuWmn3cFQXBA9lvv3BQMkcSLWlPCxrSQglp3lT6dSCKXBCZPcHTcfBqowSPbw4hb60nefKqs1ShoXf1Xeb80snO0IHc950tdQuhiwBhVZ1pO8+VhkeeXEoA0DiMvcfRK//2Q==', size: 3246515, sourceId: '146F6931-B2E8-4D2A-9E15-3988E1BDBA99', title: 'ddtitelddddffdsdd', variants: [ { $type: 'Q42.Cms.Core.Domain.AssetVariant, Q42.Cms.Core.Domain', id: '56de568d-4ce3-46d6-a22b-c71c315ab25f', name: 'Variant', fixedAspectRatio: 1.7777777777777777, isUntouched: true, isDefaultVariant: true, crop: { $type: 'Q42.Cms.Core.Domain.AssetVariantCrop, Q42.Cms.Core.Domain', centerPoint: { $type: 'Q42.Cms.Core.Domain.CenterPoint, Q42.Cms.Core.Domain', x: 318, y: 428 }, width: 626, height: 352 } }, ], tagIds: [], width: 2500, }; expect(getPreviewUrlForAsset(asset)).toEqual(asset.imageUrl); }); it('should handle previewurl for an asset which is not an image', () => { const asset = { $type: 'Q42.Cms.Core.Domain.CmsAsset, Q42.Cms.Core.Domain', alt: '', alts: {}, blobstoreUrl: '', contentType: 'text/javascript', // wrong contentType created: '', createdOn: '', createdBy: null, height: 1, id: '', imageUrl: '', isDeleted: false, modified: '', modifiedBy: null, previewData: '', size: 1, sourceId: '', title: '', variants: [], tagIds: [], width: 1, }; expect(getPreviewUrlForAsset(asset)).toEqual(''); }); it('should handle previewurl for a svg image', () => { const asset = { $type: 'Q42.Cms.Core.Domain.CmsAsset, Q42.Cms.Core.Domain', alt: '', alts: {}, blobstoreUrl: 'https://foo.bar/baz.svg', contentType: 'image/svg', created: '', createdOn: '', createdBy: null, height: 1, id: '', imageUrl: '', isDeleted: false, modified: '', modifiedBy: null, previewData: '', size: 1, sourceId: '', title: '', variants: [], tagIds: [], width: 1, }; expect(getPreviewUrlForAsset(asset)).toEqual(asset.blobstoreUrl); }); it('should handle previewurl for an asset which is not resized yet (case: directly after upload)', () => { const asset = { $type: 'Q42.Cms.Core.Domain.CmsAsset, Q42.Cms.Core.Domain', alt: null, alts: {}, blobstoreUrl: 'https://nederlandseloterij.blob.core.windows.net/assets/5F37C8B6-6FD0-4919-AD9A-06CA214398F3', centerPoint: { $type: 'Q42.Cms.Core.Domain.CenterPoint, Q42.Cms.Core.Domain', x: 318, y: 428, }, contentType: 'image/jpeg', created: '2019-10-24T13:46:26.421624+02:00', createdOn: '2019-10-24T11:46:26.421629+00:00', createdBy: null, height: 204, id: '5f37c8b6-6fd0-4919-ad9a-06ca214398f3', imageUrl: '/image/5F37C8B6-6FD0-4919-AD9A-06CA214398F3', isDeleted: false, modified: '2019-10-24T13:46:26.421624+02:00', modifiedBy: null, previewData: 'BCAASACADEkH/2gAMAwEAAhEDEQA/AL+11M7dQcE4yomWUojwScq71tNJLKTxSx27IfPFPcpWOpQgl1quZWl2ijms52n5FOVFjNLOAXH2p5tuTOPhpTFbQSwTBxb9qD5wiLmnV+SrNjtXAdBAA6CEKkuiE3Zrxb0PxZa0Z9BCEIZ+H//Z', size: 13739, sourceId: '5F37C8B6-6FD0-4919-AD9A-06CA214398F3', title: 'hhllo', variants: [ { $type: 'Q42.Cms.Core.Domain.AssetVariant, Q42.Cms.Core.Domain', id: '56de568d-4ce3-46d6-a22b-c71c315ab25f', name: 'Variant', fixedAspectRatio: 1.7777777777777777, isUntouched: true, isDefaultVariant: true, crop: { $type: 'Q42.Cms.Core.Domain.AssetVariantCrop, Q42.Cms.Core.Domain', centerPoint: { $type: 'Q42.Cms.Core.Domain.CenterPoint, Q42.Cms.Core.Domain', x: 318, y: 428 }, width: 626, height: 352 } }, ], tagIds: [], width: 360, }; expect(getPreviewUrlForAsset(asset)).toEqual(asset.blobstoreUrl); }); });