Skip to content

Commit

Permalink
#789: improve resolving campaigns + fix mobileMessage RETRIEVE test
Browse files Browse the repository at this point in the history
  • Loading branch information
JoernBerkefeld committed Mar 27, 2023
1 parent 4bafdf2 commit e0034b5
Show file tree
Hide file tree
Showing 7 changed files with 126 additions and 29 deletions.
21 changes: 11 additions & 10 deletions lib/metadataTypes/MobileMessage.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,16 +277,17 @@ class MobileMessage extends MetadataType {
metadata.c__campaignNames = [];

for (const campaign of metadata.campaigns) {
const campaignName = cache.searchForField(
'campaign',
campaign.id,
'id',
'name'
);
if (campaignName === campaign.name) {
metadata.c__campaignNames.push(campaignName);
} else {
throw new Error(`Campaign Name / ID mismatch for ${campaign.name}.`);
try {
// test if exists
cache.getByKey('campaign', campaign.name);
metadata.c__campaignNames.push(campaign.name);
// TODO figure out what campaign.id stands for - it cant be found on campaigns.
} catch (ex) {
Util.logger.warn(
` - ${this.definition.type} ${metadata[this.definition.nameField]}: ${
ex.message
}`
);
}
}
delete metadata.campaigns;
Expand Down
7 changes: 7 additions & 0 deletions lib/metadataTypes/definitions/MobileMessage.definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -712,5 +712,12 @@ module.exports = {
retrieving: true,
template: true,
},
c__campaignNames: {
isCreateable: false,
isUpdateable: false,
retrieving: true,
template: true,
},
'c__campaignNames[]': { skipValidation: true },
},
};
41 changes: 23 additions & 18 deletions test/mobileMessage.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
const chai = require('chai');
const chaiFiles = require('chai-files');
// const assert = chai.assert;
const assert = chai.assert;
chai.use(chaiFiles);
// const cache = require('../lib/util/cache');
const expect = chai.expect;
const file = chaiFiles.file;
const cache = require('../lib/util/cache');
const testUtils = require('./utils');
const handler = require('../lib/index');

Expand All @@ -20,22 +22,25 @@ describe('mobileMessage', () => {
await handler.retrieve('testInstance/testBU', ['mobileMessage']);
// THEN
// get results from cache
// const result = cache.getCache();
// assert.equal(
// result.mobileMessage ? Object.keys(result.mobileMessage).length : 0,
// 2,
// 'only 2 mobileMessages expected'
// );
// assert.deepEqual(
// await testUtils.getActualJson('testExisting_mobileMessage', 'mobileMessage'),
// await testUtils.getExpectedJson('9999999', 'mobileMessage', 'get'),
// 'returned JSON was not equal expected'
// );
// assert.equal(
// testUtils.getAPIHistoryLength(),
// 9,
// 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
// );
const result = cache.getCache();
assert.equal(
result.mobileMessage ? Object.keys(result.mobileMessage).length : 0,
1,
'only 1 mobileMessages expected'
);
assert.deepEqual(
await testUtils.getActualJson('NTIzOjc4OjA', 'mobileMessage'),
await testUtils.getExpectedJson('9999999', 'mobileMessage', 'get'),
'saved JSON was not equal expected'
);
expect(file(testUtils.getActualFile('NTIzOjc4OjA', 'mobileMessage', 'amp'))).to.equal(
file(testUtils.getExpectedFile('9999999', 'mobileMessage', 'get', 'amp'))
);
assert.equal(
testUtils.getAPIHistoryLength(),
4,
'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
);
return;
});
});
Expand Down
22 changes: 22 additions & 0 deletions test/resources/9999999/hub/v1/campaigns/get-response.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"count": 1,
"page": 1,
"pageSize": 100,
"links": {
"self": {
"href": "/v1/campaigns?$page=1&$pagesize=100"
}
},
"items": [
{
"createdDate": "2021-05-17T05:52:40",
"modifiedDate": "2021-05-17T05:52:52",
"id": "231",
"name": "testExisting_campaign",
"description": "Test Campaign",
"campaignCode": "TEST CAMPAIGN",
"color": "f6efb6",
"favorite": false
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"id": "NTIzOjc4OjA",
"lastUpdated": "2023-03-08T16:30:00Z",
"type": "ExactTarget.Mobile.Sms.Core.Entities.SmsMessageEntity",
"name": "testExisting_SMS",
"name": "testExisting_mobileMessage",
"text": "test message jb new",
"origin": "SMS Send",
"code": {
Expand Down
1 change: 1 addition & 0 deletions test/resources/9999999/mobileMessage/get-expected.amp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test message jb new
61 changes: 61 additions & 0 deletions test/resources/9999999/mobileMessage/get-expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
"id": "NTIzOjc4OjA",
"lastUpdated": "2023-03-08T16:30:00Z",
"type": "ExactTarget.Mobile.Sms.Core.Entities.SmsMessageEntity",
"name": "testExisting_mobileMessage",
"origin": "SMS Send",
"code": {
"code": "4912312345678"
},
"c__campaignNames": ["testExisting_campaign"],

"mtSendDate": "2020-07-16T22:46:00Z",
"template": {
"id": "Mzo4MDow",
"name": "Outbound"
},
"status": "Active/Scheduled",
"invalidMessage": "",
"responseMessage": "",
"publishedMessage": "Text '<keyword>' to 4912312345678.",
"isTest": false,
"moTimezone": {
"offset": 1,
"name": "(GMT+01:00) Amsterdam, Berlin, Bern, Rome, Stockholm, Vienna *"
},
"optinType": "NO_OPTIN",
"doubleOptinInitialMessage": "",
"doubleOptinConfirmMessage": "",
"optinMinimumAge": 0,
"optinInvalidAgeMessage": "",
"numberMessagesPerPeriod": 0,
"periodType": "NO_PERIOD",
"optinErrorMessage": "",
"isDuplicationAllowed": true,
"triggeredSendName": "DEV_InformUserAboutProposal - 267",
"isTimeZoneBased": false,
"surveyType": "NO_SURVEY",
"surveyCorrectResponseMessage": "",
"surveyTooManyEntriesMessage": "",
"isExpireSet": false,
"expireHours": 0,
"surveyIncorrectResponseMessage": "",
"statusId": 2,
"doubleOptinValidResponses": "y|yes",
"messagesPerPeriod": 0,
"minutesPerPeriod": 0,
"subscriberResponseMessage": "",
"isSubscriberResponseToAnySubscriptionForShortCode": false,
"sendMethod": "API",
"messageObjectId": "MzN3MUV5YVpmRVMtV1R1UXJUR3NzUTo2MjU6MA",
"allowSingleOptin": false,
"isSentImmediately": true,
"isSuppressMt": false,
"smsTriggeredSendDefinitionId": "39d0e022-b6c7-ea11-a2e9-1402ec938719",
"fromName": "4912312345678",
"concatenateMessage": true,
"isFromNameCertificationAccepted": false,
"isCertified": false,
"outboundSendTypeFlag": "Audience",
"outboundSendBehaviorFlag": "AutoAddSubscribers"
}

0 comments on commit e0034b5

Please sign in to comment.