From 976758a41199084ad0d37a8b75526ac77b5c1b04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Berkefeld?= Date: Thu, 16 May 2024 14:02:03 +0200 Subject: [PATCH] #1324: add templating test for assets: templatebased-emails --- .../build-templatebasedemail-expected.html | 20 ++ .../build-templatebasedemail-expected.json | 82 ++++++++ .../template-templatebasedemail-expected.html | 20 ++ .../template-templatebasedemail-expected.json | 82 ++++++++ test/type.asset.test.js | 176 ++++++++++++++++++ 5 files changed, 380 insertions(+) create mode 100644 test/resources/9999999/asset/build-templatebasedemail-expected.html create mode 100644 test/resources/9999999/asset/build-templatebasedemail-expected.json create mode 100644 test/resources/9999999/asset/template-templatebasedemail-expected.html create mode 100644 test/resources/9999999/asset/template-templatebasedemail-expected.json diff --git a/test/resources/9999999/asset/build-templatebasedemail-expected.html b/test/resources/9999999/asset/build-templatebasedemail-expected.html new file mode 100644 index 000000000..5ae3b84c4 --- /dev/null +++ b/test/resources/9999999/asset/build-templatebasedemail-expected.html @@ -0,0 +1,20 @@ +Update Profile + + + + +
+ This email was sent by: %%Member_Busname%%
%%Member_Addr%% + %%Member_City%%, %%Member_State%%, %%Member_PostalCode%%, %%Member_Country%%

+
+Manage Subscriptions diff --git a/test/resources/9999999/asset/build-templatebasedemail-expected.json b/test/resources/9999999/asset/build-templatebasedemail-expected.json new file mode 100644 index 000000000..6e32c69e0 --- /dev/null +++ b/test/resources/9999999/asset/build-templatebasedemail-expected.json @@ -0,0 +1,82 @@ +{ + "customerKey": "testTemplated_asset_templatebasedemail", + "contentType": "application/vnd.etmc.email.Message; kind=template", + "assetType": { "name": "templatebasedemail", "displayName": "Template-Based Email" }, + "name": " testTemplated_asset_templatebasedemail", + "createdBy": {}, + "modifiedBy": {}, + "memberId": "1111111", + "status": { "name": "Draft" }, + "views": { + "subjectline": { + "contentType": "application/vnd.etmc.email.View; kind=subjectline", + "thumbnail": {}, + "content": "my subject line", + "availableViews": [], + "data": { "email": { "options": { "generateFrom": null } } }, + "modelVersion": 2 + }, + "preheader": { + "contentType": "application/vnd.etmc.email.View; kind=preheader", + "thumbnail": {}, + "content": "my custom preheader text", + "availableViews": [], + "data": { "email": { "options": { "generateFrom": null } } }, + "modelVersion": 2 + }, + "text": { + "thumbnail": {}, + "availableViews": [], + "data": { "email": { "options": { "generateFrom": "html" } } }, + "generateFrom": "html", + "modelVersion": 2 + }, + "viewAsAWebPage": { + "thumbnail": {}, + "availableViews": [], + "data": { "email": { "options": { "generateFrom": null } } }, + "modelVersion": 2 + }, + "subscriptioncenter": { + "thumbnail": {}, + "availableViews": [], + "data": { "email": { "options": { "generateFrom": null } } }, + "modelVersion": 2 + }, + "forwardHTML": { + "thumbnail": {}, + "availableViews": [], + "data": { "email": { "options": { "generateFrom": null } } }, + "modelVersion": 2 + }, + "forwardText": { + "thumbnail": {}, + "availableViews": [], + "data": { "email": { "options": { "generateFrom": null } } }, + "modelVersion": 2 + }, + "html": { + "thumbnail": {}, + "availableViews": [], + "template": { + "meta": { "contentHash": -166410261 }, + "r__assetTemplate_Key": "testTemplated_asset_template" + }, + "data": { "email": { "options": { "generateFrom": null } } }, + "modelVersion": 2 + } + }, + "availableViews": [ + "subjectline", + "preheader", + "text", + "viewAsAWebPage", + "subscriptioncenter", + "forwardHTML", + "forwardText", + "html" + ], + "data": { "email": { "options": { "characterEncoding": "utf-8" } } }, + "modelVersion": 2, + "r__folder_Path": "Content Builder" +} diff --git a/test/resources/9999999/asset/template-templatebasedemail-expected.html b/test/resources/9999999/asset/template-templatebasedemail-expected.html new file mode 100644 index 000000000..5ae3b84c4 --- /dev/null +++ b/test/resources/9999999/asset/template-templatebasedemail-expected.html @@ -0,0 +1,20 @@ +Update Profile + + + + +
+ This email was sent by: %%Member_Busname%%
%%Member_Addr%% + %%Member_City%%, %%Member_State%%, %%Member_PostalCode%%, %%Member_Country%%

+
+Manage Subscriptions diff --git a/test/resources/9999999/asset/template-templatebasedemail-expected.json b/test/resources/9999999/asset/template-templatebasedemail-expected.json new file mode 100644 index 000000000..8fc42da8a --- /dev/null +++ b/test/resources/9999999/asset/template-templatebasedemail-expected.json @@ -0,0 +1,82 @@ +{ + "customerKey": "{{{prefix}}}asset_templatebasedemail", + "contentType": "application/vnd.etmc.email.Message; kind=template", + "assetType": { "name": "templatebasedemail", "displayName": "Template-Based Email" }, + "name": " {{{prefix}}}asset_templatebasedemail", + "createdBy": {}, + "modifiedBy": {}, + "memberId": "{{{mid}}}", + "status": { "name": "Draft" }, + "views": { + "subjectline": { + "contentType": "application/vnd.etmc.email.View; kind=subjectline", + "thumbnail": {}, + "content": "my subject line", + "availableViews": [], + "data": { "email": { "options": { "generateFrom": null } } }, + "modelVersion": 2 + }, + "preheader": { + "contentType": "application/vnd.etmc.email.View; kind=preheader", + "thumbnail": {}, + "content": "my custom preheader text", + "availableViews": [], + "data": { "email": { "options": { "generateFrom": null } } }, + "modelVersion": 2 + }, + "text": { + "thumbnail": {}, + "availableViews": [], + "data": { "email": { "options": { "generateFrom": "html" } } }, + "generateFrom": "html", + "modelVersion": 2 + }, + "viewAsAWebPage": { + "thumbnail": {}, + "availableViews": [], + "data": { "email": { "options": { "generateFrom": null } } }, + "modelVersion": 2 + }, + "subscriptioncenter": { + "thumbnail": {}, + "availableViews": [], + "data": { "email": { "options": { "generateFrom": null } } }, + "modelVersion": 2 + }, + "forwardHTML": { + "thumbnail": {}, + "availableViews": [], + "data": { "email": { "options": { "generateFrom": null } } }, + "modelVersion": 2 + }, + "forwardText": { + "thumbnail": {}, + "availableViews": [], + "data": { "email": { "options": { "generateFrom": null } } }, + "modelVersion": 2 + }, + "html": { + "thumbnail": {}, + "availableViews": [], + "template": { + "meta": { "contentHash": -166410261 }, + "r__assetTemplate_Key": "{{{prefix}}}asset_template" + }, + "data": { "email": { "options": { "generateFrom": null } } }, + "modelVersion": 2 + } + }, + "availableViews": [ + "subjectline", + "preheader", + "text", + "viewAsAWebPage", + "subscriptioncenter", + "forwardHTML", + "forwardText", + "html" + ], + "data": { "email": { "options": { "characterEncoding": "utf-8" } } }, + "modelVersion": 2, + "r__folder_Path": "Content Builder" +} diff --git a/test/type.asset.test.js b/test/type.asset.test.js index 89ddce466..1ddad5030 100644 --- a/test/type.asset.test.js +++ b/test/type.asset.test.js @@ -44,6 +44,82 @@ async function getActualJson(customerKey, type, subtype, buName = 'testBU') { function getActualFile(customerKey, type, subtype, ext, buName = 'testBU') { return `./retrieve/testInstance/${buName}/${type}/${subtype}/${customerKey}.${type}-${subtype}-meta.${ext}`; } +/** + * gets file from Template folder + * + * @param {string} customerKey of metadata + * @param {string} type of metadata + * @param {string} subtype of metadata + * @returns {Promise.} file in string form + */ +async function getActualTemplateJson(customerKey, type, subtype) { + try { + return await File.readJSON( + `./template/${type}/${subtype}/${customerKey}.${type}-${subtype}-meta.json` + ); + } catch { + return await File.readJSON( + `./template/${type}/${subtype}/${customerKey}/${customerKey}.${type}-${subtype}-meta.json` + ); + } +} +/** + * gets file from Template folder + * + * @param {string} customerKey of metadata + * @param {string} type of metadata + * @param {string} subtype of metadata + * @param {string} ext file extension + * @param {string} [filename] optional fileprefix that differs from customerKey + * @returns {any} file + */ +function getActualTemplateFile(customerKey, type, subtype, ext, filename) { + return filename + ? file( + `./template/${type}/${subtype}/${customerKey}/${filename}.${type}-${subtype}-meta.${ext}` + ) + : file(`./template/${type}/${subtype}/${customerKey}.${type}-${subtype}-meta.${ext}`); +} +/** + * gets file from Deploy folder + * + * @param {string} customerKey of metadata + * @param {string} type of metadata + * @param {string} subtype of metadata + * @param {string} [buName] used when we need to test on ParentBU + * @returns {Promise.} file in string form + */ +async function getActualDeployJson(customerKey, type, subtype, buName = 'testBU') { + try { + return await File.readJSON( + `./deploy/testInstance/${buName}/${type}/${subtype}/${customerKey}.${type}-${subtype}-meta.json` + ); + } catch { + return await File.readJSON( + `./deploy/testInstance/${buName}/${type}/${subtype}/${customerKey}/${customerKey}.${type}-${subtype}-meta.json` + ); + } +} +/** + * gets file from Deploy folder + * + * @param {string} customerKey of metadata + * @param {string} type of metadata + * @param {string} subtype of metadata + * @param {string} ext file extension + * @param {string} [filename] optional fileprefix that differs from customerKey + * @param {string} [buName] used when we need to test on ParentBU + * @returns {any} file content + */ +function getActualDeployFile(customerKey, type, subtype, ext, filename, buName = 'testBU') { + return filename + ? file( + `./deploy/testInstance/${buName}/${type}/${subtype}/${customerKey}/${filename}.${type}-${subtype}-meta.${ext}` + ) + : file( + `./deploy/testInstance/${buName}/${type}/${subtype}/${customerKey}.${type}-${subtype}-meta.${ext}` + ); +} describe('type: asset', () => { beforeEach(() => { @@ -214,6 +290,106 @@ describe('type: asset', () => { }); }); + describe('Templating ================', () => { + it('Should create a asset template via buildTemplate and build it', async () => { + // download first before we test buildTemplate + await handler.retrieve('testInstance/testBU', ['asset']); + + const expectedApiCallsRetrieve = 15; + assert.equal( + testUtils.getAPIHistoryLength(), + expectedApiCallsRetrieve, + 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' + ); + + // GIVEN there is a template + const result = await handler.buildTemplate( + 'testInstance/testBU', + 'asset', + ['testExisting_asset_templatebasedemail'], + 'testSourceMarket' + ); + // WHEN + assert.equal(process.exitCode, 0, 'buildTemplate should not have thrown an error'); + assert.equal( + result.asset ? Object.keys(result.asset).length : 0, + 1, + 'only one asset expected' + ); + assert.deepEqual( + await getActualTemplateJson( + 'testExisting_asset_templatebasedemail', + 'asset', + 'message' + ), + await testUtils.getExpectedJson('9999999', 'asset', 'template-templatebasedemail'), + 'returned template JSON of buildTemplate was not equal expected' + ); + + expect( + getActualTemplateFile( + 'testExisting_asset_templatebasedemail', + 'asset', + 'message', + 'html', + 'views.html.content' + ) + ).to.equal( + file( + testUtils.getExpectedFile( + '9999999', + 'asset', + 'template-templatebasedemail', + 'html' + ) + ) + ); + // THEN + await handler.buildDefinition( + 'testInstance/testBU', + 'asset', + ['testExisting_asset_templatebasedemail'], + 'testTargetMarket' + ); + assert.equal(process.exitCode, 0, 'buildDefinition should not have thrown an error'); + + assert.deepEqual( + await getActualDeployJson( + 'testTemplated_asset_templatebasedemail', + 'asset', + 'message' + ), + await testUtils.getExpectedJson('9999999', 'asset', 'build-templatebasedemail'), + 'returned deployment JSON was not equal expected' + ); + expect( + getActualDeployFile( + 'testTemplated_asset_templatebasedemail', + 'asset', + 'message', + 'html', + 'views.html.content' + ) + ).to.equal( + file( + testUtils.getExpectedFile( + '9999999', + 'asset', + 'build-templatebasedemail', + 'html' + ) + ) + ); + + assert.equal( + testUtils.getAPIHistoryLength() - expectedApiCallsRetrieve, + 0, + 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' + ); + return; + }); + }); + describe('Delete ================', () => { it('Should delete the item', async () => { // WHEN