Skip to content

Commit

Permalink
Feat: Adds asset collection models (#126)
Browse files Browse the repository at this point in the history
* fix asset collection models

* add assets collections tests
  • Loading branch information
IvanKiral authored Oct 24, 2023
1 parent d4714c7 commit fd2a7c0
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 4 deletions.
5 changes: 5 additions & 0 deletions lib/contracts/asset-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export namespace AssetContracts {
last_modified: string;
url: string;
codename: string;
collection?: IAssetCollectionReferenceContract;
folder?: IAssetFolderReferenceContract;
}

Expand All @@ -33,6 +34,10 @@ export namespace AssetContracts {
description: string;
}

export interface IAssetCollectionReferenceContract {
reference: SharedContracts.IReferenceObjectContract | null;
}

export interface IAssetsListingResponseContract {
assets: IAssetModelContract[];
pagination: SharedContracts.IPaginationModelContract;
Expand Down
1 change: 1 addition & 0 deletions lib/mappers/assets-mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export class AssetsMapper extends BaseMapper {
type: rawAsset.type,
folder: rawAsset.folder,
codename: rawAsset.codename,
collection: rawAsset.collection,
_raw: rawAsset
});
}
Expand Down
11 changes: 9 additions & 2 deletions lib/models/assets/asset.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -33,6 +34,7 @@ export namespace AssetModels {
lastModified: Date;
url: string;
codename: string;
collection?: IAssetCollectionReferenceObject;
folder?: IAssetFolderReference;
_raw: AssetContracts.IAssetModelContract;
}) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -99,7 +105,7 @@ export namespace AssetModels {
descriptions?: IAssetFileDescription[];
folder?: IAssetFolderReference;
elements?: IAssetElementValueType[];
collection?: SharedContracts.IReferenceObjectContract;
collection?: IAssetCollectionReferenceObject;
codename?: string;
}

Expand All @@ -108,6 +114,7 @@ export namespace AssetModels {
title?: string;
file_reference?: IAssetFileReference;
folder?: IAssetFolderReference;
collection?: IAssetCollectionReferenceObject;
elements?: IAssetElementValueType[];
}

Expand All @@ -118,7 +125,7 @@ export namespace AssetModels {
descriptions?: IAssetFileDescription[];
folder?: IAssetFolderReference;
elements?: IAssetElementValueType[];
collection?: SharedContracts.IReferenceObjectContract;
collection?: IAssetCollectionReferenceObject;
codename?: string;
};
binaryFile: {
Expand Down
8 changes: 6 additions & 2 deletions test/browser/assets/add-assets.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ describe('Add asset', () => {
descriptions: [],
codename: 'x',
collection: {
codename: 'y'
reference: {
codename: 'y'
}
},
external_id: 'x',
folder: {
Expand Down Expand Up @@ -53,7 +55,8 @@ describe('Add asset', () => {
file_reference: {
id: 'x',
type: 'internal'
}
},
collection: { reference: null }
};
})
.getUrl();
Expand Down Expand Up @@ -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();
Expand Down
6 changes: 6 additions & 0 deletions test/browser/assets/upsert-assets.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ describe('Upsert asset', () => {
file_reference: {
id: 'xId',
type: 'internal'
},
collection: {
reference: {
codename: "y"
}
}
};
})
Expand Down Expand Up @@ -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();
Expand Down
5 changes: 5 additions & 0 deletions test/browser/fake-responses/assets/fake-add-asset.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions test/browser/fake-responses/assets/fake-upsert-asset.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit fd2a7c0

Please sign in to comment.