Skip to content

Commit

Permalink
#1324: add templating test for assets: templatebased-emails
Browse files Browse the repository at this point in the history
  • Loading branch information
JoernBerkefeld committed May 16, 2024
1 parent 40a77a4 commit 976758a
Show file tree
Hide file tree
Showing 5 changed files with 380 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<a href="%%ftaf_url%%"
><img
src="https://www.exacttarget.com/members/newsletters/gfx/forwardafriendicon.gif"
border="0" /></a
><a href="%%profile_center_url%%" alias="Update Profile">Update Profile</a>
<table cellpadding="2" cellspacing="0" width="600" id="Table5" border="0">
<tr>
<td>
<font face="verdana" size="1" color="#444444"
>This email was sent by: <b>%%Member_Busname%%</b><br />%%Member_Addr%%
%%Member_City%%, %%Member_State%%, %%Member_PostalCode%%, %%Member_Country%%<br /><br
/></font>
</td>
</tr>
</table>
<a href="%%subscription_center_url%%" alias="Manage Subscriptions">Manage Subscriptions</a
><img src="https://www.exacttarget.com/images/Powered_By_1206.jpg" border="0" /><custom
name="opencounter"
type="tracking"
/>
Original file line number Diff line number Diff line change
@@ -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"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<a href="%%ftaf_url%%"
><img
src="https://www.exacttarget.com/members/newsletters/gfx/forwardafriendicon.gif"
border="0" /></a
><a href="%%profile_center_url%%" alias="Update Profile">Update Profile</a>
<table cellpadding="2" cellspacing="0" width="600" id="Table5" border="0">
<tr>
<td>
<font face="verdana" size="1" color="#444444"
>This email was sent by: <b>%%Member_Busname%%</b><br />%%Member_Addr%%
%%Member_City%%, %%Member_State%%, %%Member_PostalCode%%, %%Member_Country%%<br /><br
/></font>
</td>
</tr>
</table>
<a href="%%subscription_center_url%%" alias="Manage Subscriptions">Manage Subscriptions</a
><img src="https://www.exacttarget.com/images/Powered_By_1206.jpg" border="0" /><custom
name="opencounter"
type="tracking"
/>
Original file line number Diff line number Diff line change
@@ -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"
}
176 changes: 176 additions & 0 deletions test/type.asset.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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.<string>} 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.<string>} 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(() => {
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 976758a

Please sign in to comment.