Skip to content

Commit

Permalink
feat: Adds codename & collection support for assets (fixes #122)
Browse files Browse the repository at this point in the history
  • Loading branch information
Enngage committed Sep 7, 2023
1 parent adb0e6b commit f08684f
Show file tree
Hide file tree
Showing 12 changed files with 196 additions and 99 deletions.
1 change: 1 addition & 0 deletions lib/contracts/asset-contracts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export namespace AssetContracts {
external_id: string;
last_modified: string;
url: string;
codename: string;
folder?: IAssetFolderReferenceContract;
}

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 @@ -98,6 +98,7 @@ export class AssetsMapper extends BaseMapper {
title: rawAsset.title,
type: rawAsset.type,
folder: rawAsset.folder,
codename: rawAsset.codename,
_raw: rawAsset
});
}
Expand Down
7 changes: 7 additions & 0 deletions lib/models/assets/asset.models.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export namespace AssetModels {
public externalId?: string;
public lastModified!: Date;
public url!: string;
public codename!: string;
public folder?: IAssetFolderReference;
public _raw!: AssetContracts.IAssetModelContract;

Expand All @@ -31,6 +32,7 @@ export namespace AssetModels {
externalId?: string;
lastModified: Date;
url: string;
codename: string;
folder?: IAssetFolderReference;
_raw: AssetContracts.IAssetModelContract;
}) {
Expand Down Expand Up @@ -97,6 +99,8 @@ export namespace AssetModels {
descriptions?: IAssetFileDescription[];
folder?: IAssetFolderReference;
elements?: IAssetElementValueType[];
collection?: SharedContracts.IReferenceObjectContract;
codename?: String;
}

export interface IUpsertAssetRequestData {
Expand All @@ -113,6 +117,9 @@ export namespace AssetModels {
external_id?: string;
descriptions?: IAssetFileDescription[];
folder?: IAssetFolderReference;
elements?: IAssetElementValueType[];
collection?: SharedContracts.IReferenceObjectContract;
codename?: String;
};
binaryFile: {
filename: string;
Expand Down
5 changes: 4 additions & 1 deletion lib/services/management-query-service.class.ts
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,10 @@ export class ManagementQueryService extends BaseManagementQueryService<any> {
descriptions: data.asset.descriptions,
external_id: data.asset.external_id,
folder: data.asset.folder,
title: data.asset.title
title: data.asset.title,
codename: data.asset.codename,
collection: data.asset.collection,
elements: data.asset.elements,
},
config
);
Expand Down
10 changes: 10 additions & 0 deletions test/browser/assets/add-assets.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ describe('Add asset', () => {
.withData((builder) => {
return {
descriptions: [],
codename: 'x',
collection: {
codename: 'y'
},
external_id: 'x',
folder: {
id: 'x'
},
title: 'Title',
elements: [
builder.taxonomyElement({
element: {
Expand Down Expand Up @@ -74,6 +83,7 @@ describe('Add asset', () => {
expect(asset.lastModified).toEqual(new Date(originalItem.last_modified));
expect(asset.imageHeight).toEqual(originalItem.image_height);
expect(asset.title).toEqual(originalItem.title);
expect(asset.codename).toEqual(originalItem.codename);
expect(asset.externalId).toEqual(originalItem.external_id);
expect(asset.imageWidth).toEqual(originalItem.image_width);
expect(asset.size).toEqual(originalItem.size);
Expand Down
1 change: 1 addition & 0 deletions test/browser/assets/list-assets-items.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ describe('List assets', () => {
expect(m.imageWidth).toEqual(originalItem.image_width);
expect(m.size).toEqual(originalItem.size);
expect(m.url).toEqual(originalItem.url);
expect(m.codename).toEqual(originalItem.codename);
expect(m.fileReference).toEqual(jasmine.any(AssetModels.AssetFileReference));
expect(m.fileReference.id).toEqual(originalItem.file_reference.id);
expect(m.fileReference.type).toEqual(originalItem.file_reference.type);
Expand Down
1 change: 1 addition & 0 deletions test/browser/assets/upsert-assets.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ describe('Upsert asset', () => {
expect(asset.imageHeight).toEqual(originalItem.image_height);
expect(asset.title).toEqual(originalItem.title);
expect(asset.externalId).toEqual(originalItem.external_id);
expect(asset.codename).toEqual(originalItem.codename);
expect(asset.imageWidth).toEqual(originalItem.image_width);
expect(asset.folder).toEqual(originalItem.folder);
expect(asset.size).toEqual(originalItem.size);
Expand Down
3 changes: 2 additions & 1 deletion test/browser/assets/view-asset.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ describe('View assets', () => {
expect(asset.lastModified).toEqual(new Date(originalItem.last_modified));
expect(asset.imageHeight).toEqual(originalItem.image_height);
expect(asset.title).toEqual(originalItem.title);
expect(asset.externalId).toEqual(undefined);
expect(asset.codename).toEqual(originalItem.codename);
expect(asset.externalId).toEqual(originalItem.external_id);
expect(asset.imageWidth).toEqual(originalItem.image_width);
expect(asset.size).toEqual(originalItem.size);
expect(asset.fileReference).toEqual(jasmine.any(AssetModels.AssetFileReference));
Expand Down
56 changes: 35 additions & 21 deletions test/browser/fake-responses/assets/fake-add-asset.json
Original file line number Diff line number Diff line change
@@ -1,29 +1,43 @@
{
"id": "fcbb12e6-66a3-4672-85d9-d502d16b8d9c",
"file_name": "which-brewing-fits-you-1080px.jpg",
"title": "Coffee Brewing Techniques",
"size": 125770,
"file_name": "file_name.jpeg",
"title": "Description of what the file contains",
"size": 148636,
"type": "image/jpeg",
"image_width": 1000,
"image_height": 666,
"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,
"file_reference": {
"id": "fcbb12e6-66a3-4672-85d9-d502d16b8d9c",
"type": "internal"
"id": "fcbb12e6-66a3-4672-85d9-d502d16b8d9c",
"type": "internal"
},
"folder": {
"id": "8fe4ff47-0ca8-449d-bc63-c280efee44ea"
},
"descriptions": [
{
"language": {
"id": "00000000-0000-0000-0000-000000000000"
},
"description": "Coffee Brewing Techniques"
},
{
"language": {
"id": "d1f95fde-af02-b3b5-bd9e-f232311ccab8"
},
"description": "Técnicas para hacer café"
}
{
"language": {
"id": "00000000-0000-0000-0000-000000000000"
},
"description": "The asset's alt text in the default language describing what the file or image shows."
}
],
"elements": [
{
"element": {
"id": "c7c3b834-2222-5677-89c4-b46f04489109"
},
"value": [
{
"id": "53a5eecb-f295-59b4-a07d-19655b6ad860"
},
{
"id": "3f367e4f-75b7-4b48-be3b-1136bbaf1f53"
}
]
}
],
"external_id": "which-brewing-fits-you",
"codename": "xcodename",
"external_id": "custom-asset-identifier",
"last_modified": "2017-09-12T08:29:36.1645977Z"
}
}
79 changes: 50 additions & 29 deletions test/browser/fake-responses/assets/fake-list-assets.json
Original file line number Diff line number Diff line change
@@ -1,35 +1,56 @@
{
"assets": [
{
"descriptions": [
{
"language": {
"id": "00000000-0000-0000-0000-000000000000"
{
"descriptions": [
{
"language": {
"id": "00000000-0000-0000-0000-000000000000"
},
"description": "The asset's alt text for the default language."
}
],
"elements": [
{
"element": {
"id": "c7c3b834-2222-5677-89c4-b46f04489109"
},
"value": [
{
"id": "53a5eecb-f295-59b4-a07d-19655b6ad860"
},
{
"id": "3f367e4f-75b7-4b48-be3b-1136bbaf1f53"
}
]
}
],
"external_id": "custom-asset-identifier",
"file_name": "file_name.png",
"file_reference": {
"id": "806ec84e-7c71-4856-9519-ee3dd3558583",
"type": "internal"
},
"description": "Alt text in default language for the asset."
}
],
"external_id": "which-brewing-fits-you",
"file_name": "which-brewing-fits-you-1080px.jpg",
"file_reference": {
"id": "806ec84e-7c71-4856-9519-ee3dd3558583",
"type": "internal"
},
"folder": {
"id": "8fe4ff47-0ca8-449d-bc63-c280efee44ea"
},
"id": "fcbb12e6-66a3-4672-85d9-d502d16b8d9c",
"image_height": 666,
"image_width": 1000,
"last_modified": "2019-09-12T08:29:36.1645977Z",
"size": 125770,
"title": "Coffee brewing techniques",
"type": "image/jpeg",
"url": "https://assets-us-01.kc-usercontent.com/975bf280-fd91-488c-994c-2f04416e5ee3/fcbb12e6-66a3-4672-85d9-d502d16b8d9c/which-brewing-fits-you-1080px.jpg"
}
"folder": {
"id": "8fe4ff47-0ca8-449d-bc63-c280efee44ea"
},
"collection": {
"reference": {
"codename": "first_collection"
}
},
"id": "fcbb12e6-66a3-4672-85d9-d502d16b8d9c",
"codename": "my_asset",
"image_height": 548,
"image_width": 1280,
"last_modified": "2019-09-12T08:29:36.1645977Z",
"size": 148636,
"title": "Makes the asset easier to find when you need it",
"type": "image/png",
"url": "https://assets-us-01.kc-usercontent.com/8d20758c-d74c-4f59-ae04-ee928c0816b7/806ec84e-7c71-4856-9519-ee3dd3558583/file_name.png"
}
],
"pagination": {
"continuation_token": "+RID:~...",
"next_page": "https://manage.kontent.ai/v2/projects/<project_id>/<resource>?continuationToken=%2bRID%3a~..."
"continuation_token": "W3sidG9rZW4iOiIrUklEOn...",
"next_page": "https://manage.kontent.ai/v2/your/chosen/list/endpoint"
}
}
}
75 changes: 46 additions & 29 deletions test/browser/fake-responses/assets/fake-upsert-asset.json
Original file line number Diff line number Diff line change
@@ -1,32 +1,49 @@
{
"id": "fcbb12e6-66a3-4672-85d9-d502d16b8d9c",
"file_name": "which-brewing-fits-you-1080px.jpg",
"title": "Coffee Brewing Techniques",
"size": 125770,
"type": "image/jpeg",
"folder": {
"external_id": "another-folder"
},
"image_width": 1000,
"image_height": 666,
"file_reference": {
"id": "fcbb12e6-66a3-4672-85d9-d502d16b8d9c",
"type": "internal"
},
"descriptions": [
{
"language": {
"id": "00000000-0000-0000-0000-000000000000"
},
"description": "Coffee Brewing Techniques"
"folder": {
"id": "4033071a-5bc1-48da-8342-d129bb967d1d"
},
{
"language": {
"id": "d1f95fde-af02-b3b5-bd9e-f232311ccab8"
},
"description": "Técnicas para hacer café"
}
],
"external_id": "which-brewing-fits-you",
"last_modified": "2017-09-12T08:29:36.1645977Z"
}
"file_name": "which-brewing-fits-you-1080px.jpg",
"title": "Coffee Brewing Techniques",
"size": 125770,
"type": "image/jpeg",
"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,
"file_reference": {
"id": "fcbb12e6-66a3-4672-85d9-d502d16b8d9c",
"type": "internal"
},
"codename": "xcodename",
"external_id": "xid",
"descriptions": [
{
"language": {
"id": "00000000-0000-0000-0000-000000000000"
},
"description": "Coffee Brewing Techniques"
},
{
"language": {
"id": "d1f95fde-af02-b3b5-bd9e-f232311ccab8"
},
"description": "Técnicas para hacer café"
}
],
"elements": [
{
"element": {
"id": "c7c3b834-2222-5677-89c4-b46f04489109"
},
"value": [
{
"id": "53a5eecb-f295-59b4-a07d-19655b6ad860"
},
{
"id": "3f367e4f-75b7-4b48-be3b-1136bbaf1f53"
}
]
}
],
"last_modified": "2017-09-12T08:29:36.1645977Z"
}
Loading

0 comments on commit f08684f

Please sign in to comment.