diff --git a/lib/contracts/asset-contracts.ts b/lib/contracts/asset-contracts.ts index e681142..44bb376 100644 --- a/lib/contracts/asset-contracts.ts +++ b/lib/contracts/asset-contracts.ts @@ -14,6 +14,7 @@ export namespace AssetContracts { external_id: string; last_modified: string; url: string; + codename: string; folder?: IAssetFolderReferenceContract; } diff --git a/lib/mappers/assets-mapper.ts b/lib/mappers/assets-mapper.ts index 151bc97..904e3d9 100644 --- a/lib/mappers/assets-mapper.ts +++ b/lib/mappers/assets-mapper.ts @@ -98,6 +98,7 @@ export class AssetsMapper extends BaseMapper { title: rawAsset.title, type: rawAsset.type, folder: rawAsset.folder, + codename: rawAsset.codename, _raw: rawAsset }); } diff --git a/lib/models/assets/asset.models.ts b/lib/models/assets/asset.models.ts index 05262d1..87d224b 100644 --- a/lib/models/assets/asset.models.ts +++ b/lib/models/assets/asset.models.ts @@ -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; @@ -31,6 +32,7 @@ export namespace AssetModels { externalId?: string; lastModified: Date; url: string; + codename: string; folder?: IAssetFolderReference; _raw: AssetContracts.IAssetModelContract; }) { @@ -97,6 +99,8 @@ export namespace AssetModels { descriptions?: IAssetFileDescription[]; folder?: IAssetFolderReference; elements?: IAssetElementValueType[]; + collection?: SharedContracts.IReferenceObjectContract; + codename?: String; } export interface IUpsertAssetRequestData { @@ -113,6 +117,9 @@ export namespace AssetModels { external_id?: string; descriptions?: IAssetFileDescription[]; folder?: IAssetFolderReference; + elements?: IAssetElementValueType[]; + collection?: SharedContracts.IReferenceObjectContract; + codename?: String; }; binaryFile: { filename: string; diff --git a/lib/services/management-query-service.class.ts b/lib/services/management-query-service.class.ts index 2326fd0..4548c8b 100644 --- a/lib/services/management-query-service.class.ts +++ b/lib/services/management-query-service.class.ts @@ -650,7 +650,10 @@ export class ManagementQueryService extends BaseManagementQueryService { 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 ); diff --git a/test/browser/assets/add-assets.spec.ts b/test/browser/assets/add-assets.spec.ts index fd896b3..5c1bdc3 100644 --- a/test/browser/assets/add-assets.spec.ts +++ b/test/browser/assets/add-assets.spec.ts @@ -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: { @@ -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); diff --git a/test/browser/assets/list-assets-items.spec.ts b/test/browser/assets/list-assets-items.spec.ts index ff0802d..0e06d74 100644 --- a/test/browser/assets/list-assets-items.spec.ts +++ b/test/browser/assets/list-assets-items.spec.ts @@ -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); diff --git a/test/browser/assets/upsert-assets.spec.ts b/test/browser/assets/upsert-assets.spec.ts index 3268a12..b2614e1 100644 --- a/test/browser/assets/upsert-assets.spec.ts +++ b/test/browser/assets/upsert-assets.spec.ts @@ -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); diff --git a/test/browser/assets/view-asset.spec.ts b/test/browser/assets/view-asset.spec.ts index 404383d..2347274 100644 --- a/test/browser/assets/view-asset.spec.ts +++ b/test/browser/assets/view-asset.spec.ts @@ -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)); diff --git a/test/browser/fake-responses/assets/fake-add-asset.json b/test/browser/fake-responses/assets/fake-add-asset.json index 50b29fd..7326cdb 100644 --- a/test/browser/fake-responses/assets/fake-add-asset.json +++ b/test/browser/fake-responses/assets/fake-add-asset.json @@ -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" - } \ No newline at end of file +} diff --git a/test/browser/fake-responses/assets/fake-list-assets.json b/test/browser/fake-responses/assets/fake-list-assets.json index c75181b..fc2fd2e 100644 --- a/test/browser/fake-responses/assets/fake-list-assets.json +++ b/test/browser/fake-responses/assets/fake-list-assets.json @@ -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//?continuationToken=%2bRID%3a~..." + "continuation_token": "W3sidG9rZW4iOiIrUklEOn...", + "next_page": "https://manage.kontent.ai/v2/your/chosen/list/endpoint" } - } \ No newline at end of file +} diff --git a/test/browser/fake-responses/assets/fake-upsert-asset.json b/test/browser/fake-responses/assets/fake-upsert-asset.json index 98521a6..bbf2c43 100644 --- a/test/browser/fake-responses/assets/fake-upsert-asset.json +++ b/test/browser/fake-responses/assets/fake-upsert-asset.json @@ -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" -} \ No newline at end of file + "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" +} diff --git a/test/browser/fake-responses/assets/fake-view-asset.json b/test/browser/fake-responses/assets/fake-view-asset.json index 970d9bc..207db0e 100644 --- a/test/browser/fake-responses/assets/fake-view-asset.json +++ b/test/browser/fake-responses/assets/fake-view-asset.json @@ -1,28 +1,48 @@ { - "id": "fcbb12e6-66a3-4672-85d9-d502d16b8d9c", - "file_name": "which-brewing-fits-you-1080px.jpg", - "title": "Coffe Brewing Techniques", - "size": 125770, - "type": "image/jpeg", - "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" - }, + "description": "The asset's alt text for the default language." + } + ], + "elements": [ { - "language": { - "id": "d1f95fde-af02-b3b5-bd9e-f232311ccab8" + "element": { + "id": "c7c3b834-2222-5677-89c4-b46f04489109" }, - "description": "Técnicas para hacer café" + "value": [ + { + "id": "53a5eecb-f295-59b4-a07d-19655b6ad860" + }, + { + "id": "3f367e4f-75b7-4b48-be3b-1136bbaf1f53" + } + ] } ], - "last_modified": "2017-09-12T08:29:36.1645977Z" -} \ No newline at end of file + "external_id": "custom-asset-identifier", + "file_name": "file_name.png", + "file_reference": { + "id": "806ec84e-7c71-4856-9519-ee3dd3558583", + "type": "internal" + }, + "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" +}