diff --git a/lib/metadataTypes/MobileMessage.js b/lib/metadataTypes/MobileMessage.js index ea7a07df2..7d5c9025e 100644 --- a/lib/metadataTypes/MobileMessage.js +++ b/lib/metadataTypes/MobileMessage.js @@ -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; diff --git a/lib/metadataTypes/definitions/MobileMessage.definition.js b/lib/metadataTypes/definitions/MobileMessage.definition.js index 4fbb3788a..85d368e8c 100644 --- a/lib/metadataTypes/definitions/MobileMessage.definition.js +++ b/lib/metadataTypes/definitions/MobileMessage.definition.js @@ -712,5 +712,12 @@ module.exports = { retrieving: true, template: true, }, + c__campaignNames: { + isCreateable: false, + isUpdateable: false, + retrieving: true, + template: true, + }, + 'c__campaignNames[]': { skipValidation: true }, }, }; diff --git a/test/mobileMessage.test.js b/test/mobileMessage.test.js index 0aad2a3ca..f701d863b 100644 --- a/test/mobileMessage.test.js +++ b/test/mobileMessage.test.js @@ -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'); @@ -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; }); }); diff --git a/test/resources/9999999/hub/v1/campaigns/get-response.json b/test/resources/9999999/hub/v1/campaigns/get-response.json new file mode 100644 index 000000000..294a69326 --- /dev/null +++ b/test/resources/9999999/hub/v1/campaigns/get-response.json @@ -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 + } + ] +} diff --git a/test/resources/9999999/legacy/v1/beta/mobile/message/get-response.json b/test/resources/9999999/legacy/v1/beta/mobile/message/get-response.json index d6b436fcf..ae6a6da20 100644 --- a/test/resources/9999999/legacy/v1/beta/mobile/message/get-response.json +++ b/test/resources/9999999/legacy/v1/beta/mobile/message/get-response.json @@ -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": { diff --git a/test/resources/9999999/mobileMessage/get-expected.amp b/test/resources/9999999/mobileMessage/get-expected.amp new file mode 100644 index 000000000..0639ff611 --- /dev/null +++ b/test/resources/9999999/mobileMessage/get-expected.amp @@ -0,0 +1 @@ +test message jb new \ No newline at end of file diff --git a/test/resources/9999999/mobileMessage/get-expected.json b/test/resources/9999999/mobileMessage/get-expected.json new file mode 100644 index 000000000..50cbe9cae --- /dev/null +++ b/test/resources/9999999/mobileMessage/get-expected.json @@ -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 '' 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" +}