From fd2a7c00fce30b9957638de04a0c803c25300377 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Kir=C3=A1=C4=BE?= <54802833+IvanKiral@users.noreply.github.com> Date: Tue, 24 Oct 2023 15:08:43 +0200 Subject: [PATCH] Feat: Adds asset collection models (#126) * fix asset collection models * add assets collections tests --- lib/contracts/asset-contracts.ts | 5 +++++ lib/mappers/assets-mapper.ts | 1 + lib/models/assets/asset.models.ts | 11 +++++++++-- test/browser/assets/add-assets.spec.ts | 8 ++++++-- test/browser/assets/upsert-assets.spec.ts | 6 ++++++ .../browser/fake-responses/assets/fake-add-asset.json | 5 +++++ .../fake-responses/assets/fake-upsert-asset.json | 3 +++ 7 files changed, 35 insertions(+), 4 deletions(-) diff --git a/lib/contracts/asset-contracts.ts b/lib/contracts/asset-contracts.ts index 44bb376..2ae90ec 100644 --- a/lib/contracts/asset-contracts.ts +++ b/lib/contracts/asset-contracts.ts @@ -15,6 +15,7 @@ export namespace AssetContracts { last_modified: string; url: string; codename: string; + collection?: IAssetCollectionReferenceContract; folder?: IAssetFolderReferenceContract; } @@ -33,6 +34,10 @@ export namespace AssetContracts { description: string; } + export interface IAssetCollectionReferenceContract { + reference: SharedContracts.IReferenceObjectContract | null; + } + export interface IAssetsListingResponseContract { assets: IAssetModelContract[]; pagination: SharedContracts.IPaginationModelContract; diff --git a/lib/mappers/assets-mapper.ts b/lib/mappers/assets-mapper.ts index 904e3d9..acab80e 100644 --- a/lib/mappers/assets-mapper.ts +++ b/lib/mappers/assets-mapper.ts @@ -99,6 +99,7 @@ export class AssetsMapper extends BaseMapper { type: rawAsset.type, folder: rawAsset.folder, codename: rawAsset.codename, + collection: rawAsset.collection, _raw: rawAsset }); } diff --git a/lib/models/assets/asset.models.ts b/lib/models/assets/asset.models.ts index 070affb..20a4962 100644 --- a/lib/models/assets/asset.models.ts +++ b/lib/models/assets/asset.models.ts @@ -16,6 +16,7 @@ export namespace AssetModels { public lastModified!: Date; public url!: string; public codename!: string; + public collection?: IAssetCollectionReferenceObject; public folder?: IAssetFolderReference; public _raw!: AssetContracts.IAssetModelContract; @@ -33,6 +34,7 @@ export namespace AssetModels { lastModified: Date; url: string; codename: string; + collection?: IAssetCollectionReferenceObject; folder?: IAssetFolderReference; _raw: AssetContracts.IAssetModelContract; }) { @@ -65,6 +67,10 @@ export namespace AssetModels { description: string; } + export interface IAssetCollectionReferenceObject { + reference: SharedModels.IReferenceObject | null + } + export class AssetFileDescription { public language: SharedModels.ReferenceObject; public description: string | null; @@ -99,7 +105,7 @@ export namespace AssetModels { descriptions?: IAssetFileDescription[]; folder?: IAssetFolderReference; elements?: IAssetElementValueType[]; - collection?: SharedContracts.IReferenceObjectContract; + collection?: IAssetCollectionReferenceObject; codename?: string; } @@ -108,6 +114,7 @@ export namespace AssetModels { title?: string; file_reference?: IAssetFileReference; folder?: IAssetFolderReference; + collection?: IAssetCollectionReferenceObject; elements?: IAssetElementValueType[]; } @@ -118,7 +125,7 @@ export namespace AssetModels { descriptions?: IAssetFileDescription[]; folder?: IAssetFolderReference; elements?: IAssetElementValueType[]; - collection?: SharedContracts.IReferenceObjectContract; + collection?: IAssetCollectionReferenceObject; codename?: string; }; binaryFile: { diff --git a/test/browser/assets/add-assets.spec.ts b/test/browser/assets/add-assets.spec.ts index 5c1bdc3..e88774c 100644 --- a/test/browser/assets/add-assets.spec.ts +++ b/test/browser/assets/add-assets.spec.ts @@ -13,7 +13,9 @@ describe('Add asset', () => { descriptions: [], codename: 'x', collection: { - codename: 'y' + reference: { + codename: 'y' + } }, external_id: 'x', folder: { @@ -53,7 +55,8 @@ describe('Add asset', () => { file_reference: { id: 'x', type: 'internal' - } + }, + collection: { reference: null } }; }) .getUrl(); @@ -90,6 +93,7 @@ describe('Add asset', () => { expect(asset.fileReference).toEqual(jasmine.any(AssetModels.AssetFileReference)); expect(asset.fileReference.id).toEqual(originalItem.file_reference.id); expect(asset.fileReference.type).toEqual(originalItem.file_reference.type); + expect(asset.collection).toEqual(originalItem.collection); asset.descriptions.forEach((s) => { expect(s.description).toBeDefined(); diff --git a/test/browser/assets/upsert-assets.spec.ts b/test/browser/assets/upsert-assets.spec.ts index b2614e1..5e2a29e 100644 --- a/test/browser/assets/upsert-assets.spec.ts +++ b/test/browser/assets/upsert-assets.spec.ts @@ -30,6 +30,11 @@ describe('Upsert asset', () => { file_reference: { id: 'xId', type: 'internal' + }, + collection: { + reference: { + codename: "y" + } } }; }) @@ -83,6 +88,7 @@ describe('Upsert asset', () => { expect(asset.fileReference).toEqual(jasmine.any(AssetModels.AssetFileReference)); expect(asset.fileReference.id).toEqual(originalItem.file_reference.id); expect(asset.fileReference.type).toEqual(originalItem.file_reference.type); + expect(asset.collection).toEqual(originalItem.collection); asset.descriptions.forEach((s) => { expect(s.description).toBeDefined(); diff --git a/test/browser/fake-responses/assets/fake-add-asset.json b/test/browser/fake-responses/assets/fake-add-asset.json index 7326cdb..a265f25 100644 --- a/test/browser/fake-responses/assets/fake-add-asset.json +++ b/test/browser/fake-responses/assets/fake-add-asset.json @@ -7,6 +7,11 @@ "url": "https://assets-us-01.kc-usercontent.com/8d20758c-d74c-4f59-ae04-ee928c0816b7/adf26cd2-1acb-403f-9d1e-6d04e46c39f1/file_name.png", "image_width": 1280, "image_height": 548, + "collection": { + "reference": { + "id": "y" + } + }, "file_reference": { "id": "fcbb12e6-66a3-4672-85d9-d502d16b8d9c", "type": "internal" diff --git a/test/browser/fake-responses/assets/fake-upsert-asset.json b/test/browser/fake-responses/assets/fake-upsert-asset.json index bbf2c43..9fb5881 100644 --- a/test/browser/fake-responses/assets/fake-upsert-asset.json +++ b/test/browser/fake-responses/assets/fake-upsert-asset.json @@ -10,6 +10,9 @@ "url": "https://assets-us-01.kc-usercontent.com/975bf280-fd91-488c-994c-2f04416e5ee3/fcbb12e6-66a3-4672-85d9-d502d16b8d9c/which-brewing-fits-you-1080px.jpg", "image_width": 1000, "image_height": 666, + "collection": { + "reference": null + }, "file_reference": { "id": "fcbb12e6-66a3-4672-85d9-d502d16b8d9c", "type": "internal"