Skip to content

Commit

Permalink
#557: add transactionalEmail test for DEPLOY
Browse files Browse the repository at this point in the history
  • Loading branch information
JoernBerkefeld committed Dec 6, 2022
1 parent 2d50478 commit 26aa915
Show file tree
Hide file tree
Showing 11 changed files with 202 additions and 11 deletions.
13 changes: 13 additions & 0 deletions docs/dist/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -4367,9 +4367,22 @@ TransactionalEmail MetadataType
**Extends**: [<code>TransactionalMessage</code>](#TransactionalMessage)

* [TransactionalEmail](#TransactionalEmail)[<code>TransactionalMessage</code>](#TransactionalMessage)
* [.update(metadata)](#TransactionalEmail.update) ⇒ <code>Promise</code>
* [.preDeployTasks(metadata)](#TransactionalEmail.preDeployTasks) ⇒ <code>TYPE.MetadataTypeItem</code>
* [.postRetrieveTasks(metadata)](#TransactionalEmail.postRetrieveTasks) ⇒ <code>TYPE.MetadataTypeItem</code>

<a name="TransactionalEmail.update"></a>

### TransactionalEmail.update(metadata) ⇒ <code>Promise</code>
Updates a single item

**Kind**: static method of [<code>TransactionalEmail</code>](#TransactionalEmail)
**Returns**: <code>Promise</code> - Promise

| Param | Type | Description |
| --- | --- | --- |
| metadata | <code>TYPE.MetadataTypeItem</code> | a single item |

<a name="TransactionalEmail.preDeployTasks"></a>

### TransactionalEmail.preDeployTasks(metadata) ⇒ <code>TYPE.MetadataTypeItem</code>
Expand Down
27 changes: 23 additions & 4 deletions lib/metadataTypes/TransactionalEmail.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,20 @@ const cache = require('../util/cache');
class TransactionalEmail extends TransactionalMessage {
static subType = 'email';

/**
* Updates a single item
*
* @param {TYPE.MetadataTypeItem} metadata a single item
* @returns {Promise} Promise
*/
static update(metadata) {
if (metadata.options?.createJourney) {
// only send this during create or else we might end up with an unexpected outcome
delete metadata.options.createJourney;
}
return super.update(metadata);
}

/**
* prepares for deployment
*
Expand Down Expand Up @@ -42,15 +56,20 @@ class TransactionalEmail extends TransactionalMessage {
}
// subscriptions: list
if (metadata.subscriptions?.r__list_PathName) {
metadata.subscriptions.list = {
ID: cache.getListObjectId(metadata.subscriptions.r__list_PathName, 'CustomerKey'),
};
metadata.subscriptions.list = cache.getListObjectId(
metadata.subscriptions.r__list_PathName,
'CustomerKey'
);
delete metadata.subscriptions.r__list_PathName;
}

// journey
if (metadata.journey?.interactionKey) {
cache.searchForField('interaction', metadata.journey.interactionKey, 'key', 'key');
// ! update & create enpoints dont accept journey.interactionKey. They only allow to create a new journey
// cache.searchForField('interaction', metadata.journey.interactionKey, 'key', 'key');
metadata.options = metadata.options || {};
metadata.options.createJourney = true; // only send this during create or else we might end up with an unexpected outcome
delete metadata.journey.interactionKey;
}

return metadata;
Expand Down
12 changes: 9 additions & 3 deletions lib/metadataTypes/definitions/TransactionalEmail.definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,15 +123,21 @@ module.exports = {
retrieving: true,
template: true,
},
journey: {
'options.createJourney': {
isCreateable: true,
isUpdateable: true,
retrieving: false,
template: false,
},
journey: {
isCreateable: false,
isUpdateable: false,
retrieving: true,
template: true,
},
'journey.interactionKey': {
isCreateable: true,
isUpdateable: true,
isCreateable: false,
isUpdateable: false,
retrieving: true,
template: true,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "testExisting_temail",
"definitionKey": "testExisting_temail",
"description": "bla bla",
"description": "updated via deploy",
"classification": "Default Transactional",
"status": "Active",
"createdDate": "2020-09-10T03:29:00",
Expand All @@ -19,6 +19,6 @@
"trackLinks": true
},
"journey": {
"interactionKey": "testExisting_journey"
"interactionKey": "testExisting_interaction"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "testNew_temail",
"definitionKey": "testNew_temail",
"description": "created on deploy",
"classification": "Default Transactional",
"status": "Active",
"createdDate": "2020-09-10T03:29:00",
"modifiedDate": "2020-09-10T03:29:00",
"content": {
"customerKey": "testExisting_asset_message"
},
"subscriptions": {
"dataExtension": "childBU_dataextension_test",
"autoAddSubscriber": true,
"updateSubscriber": true,
"r__list_PathName": "my subscribers/All Subscribers"
},
"options": {
"trackLinks": true
},
"journey": {
"interactionKey": "testExisting_interaction"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"requestId": "51f09ca1-1e5e-444a-8ddc-8e4ff80a9fa1",
"name": "testNew_temail",
"definitionKey": "testNew_temail",
"description": "created on deploy",
"classification": "Default Transactional",
"status": "Active",
"createdDate": "2022-12-06T06:08:00",
"modifiedDate": "2022-12-06T06:08:00",
"content": { "customerKey": "testExisting_asset_message" },
"subscriptions": {
"dataExtension": "childBU_dataextension_test",
"list": "All Subscribers - 277",
"autoAddSubscriber": true,
"updateSubscriber": true
},
"options": { "trackLinks": true },
"journey": { "interactionKey": "1f936b41-cf1b-4207-aa33-715b3bf9eab7" }
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@
"customerKey": "testExisting_asset_message"
},
"subscriptions": {
"list": "All Subscribers - 277",
"dataExtension": "childBU_dataextension_test",
"autoAddSubscriber": true,
"updateSubscriber": true,
"r__list_PathName": "my subscribers/All Subscribers"
"updateSubscriber": true
},
"options": {
"trackLinks": true
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"requestId": "ae8511d0-9bf0-42d0-af4f-bd9c1218c812",
"name": "testExisting_temail",
"definitionKey": "testExisting_temail",
"definitionId": "0a650d90-755e-ed11-b852-48df37d1df5b",
"description": "updated via deploy",
"classification": "Default Transactional",
"status": "Active",
"createdDate": "2020-09-10T03:29:00",
"modifiedDate": "2020-09-10T03:29:00",
"content": {
"customerKey": "testExisting_asset_message"
},
"subscriptions": {
"list": "All Subscribers - 277",
"dataExtension": "childBU_dataextension_test",
"autoAddSubscriber": true,
"updateSubscriber": true
},
"options": {
"trackLinks": true
},
"journey": {
"interactionKey": "testExisting_interaction"
}
}
24 changes: 24 additions & 0 deletions test/resources/9999999/transactionalEmail/patch-expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "testExisting_temail",
"definitionKey": "testExisting_temail",
"description": "updated via deploy",
"classification": "Default Transactional",
"status": "Active",
"createdDate": "2020-09-10T03:29:00",
"modifiedDate": "2020-09-10T03:29:00",
"content": {
"customerKey": "testExisting_asset_message"
},
"subscriptions": {
"dataExtension": "childBU_dataextension_test",
"autoAddSubscriber": true,
"updateSubscriber": true,
"r__list_PathName": "my subscribers/All Subscribers"
},
"options": {
"trackLinks": true
},
"journey": {
"interactionKey": "testExisting_interaction"
}
}
24 changes: 24 additions & 0 deletions test/resources/9999999/transactionalEmail/post-expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "testNew_temail",
"definitionKey": "testNew_temail",
"description": "created on deploy",
"classification": "Default Transactional",
"status": "Active",
"createdDate": "2022-12-06T06:08:00",
"modifiedDate": "2022-12-06T06:08:00",
"content": {
"customerKey": "testExisting_asset_message"
},
"subscriptions": {
"dataExtension": "childBU_dataextension_test",
"autoAddSubscriber": true,
"updateSubscriber": true,
"r__list_PathName": "my subscribers/All Subscribers"
},
"options": {
"trackLinks": true
},
"journey": {
"interactionKey": "1f936b41-cf1b-4207-aa33-715b3bf9eab7"
}
}
36 changes: 36 additions & 0 deletions test/transactionalEmail.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,40 @@ describe('transactionalEmail', () => {
return;
});
});
describe('Deploy ================', () => {
beforeEach(() => {
testUtils.mockSetup(true);
});
it('Should create & upsert a transactionalEmail', async () => {
// WHEN
await handler.deploy('testInstance/testBU', ['transactionalEmail']);
// THEN
// get results from cache
const result = cache.getCache();
assert.equal(
result.transactionalEmail ? Object.keys(result.transactionalEmail).length : 0,
2,
'two transactionalEmails expected'
);
// confirm created item
assert.deepEqual(
await testUtils.getActualJson('testNew_temail', 'transactionalEmail'),
await testUtils.getExpectedJson('9999999', 'transactionalEmail', 'post'),
'returned JSON was not equal expected for insert transactionalEmail'
);
// confirm updated item
assert.deepEqual(
await testUtils.getActualJson('testExisting_temail', 'transactionalEmail'),
await testUtils.getExpectedJson('9999999', 'transactionalEmail', 'patch'),
'returned JSON was not equal expected for update transactionalEmail'
);
// check number of API calls
assert.equal(
Object.values(testUtils.getAPIHistory()).flat().length,
13,
'Unexpected number of requests made'
);
return;
});
});
});

0 comments on commit 26aa915

Please sign in to comment.