Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Task/1227 fix test for importfile activities for sms #1260

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 48 additions & 32 deletions lib/metadataTypes/ImportFile.js
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,9 @@ class ImportFile extends MetadataType {
*/
static async deploy(metadataMap, deployDir, retrieveDir) {
if (
Object.values(metadataMap).filter((item) => item.c__destinationType === 'SMS').length >
0
Object.values(metadataMap).filter(
(item) => item.destination.c__destinationType === 'SMS'
).length > 0
) {
Util.logger.info(`Caching dependent Metadata: dataExtension (source for SMS imports)`);

Expand All @@ -225,61 +226,69 @@ class ImportFile extends MetadataType {
* @returns {Promise} Promise
*/
static async preDeployTasks(metadata) {
const fileLocation = cache.getByKey('fileLocation', metadata.r__fileLocation_name);
const fileLocation = cache.getByKey('fileLocation', metadata.source.r__fileLocation_name);
if (!fileLocation) {
throw new Error(`fileLocation ${metadata.r__fileLocation_name} not found in cache`);
}

metadata.fileTransferLocationId = fileLocation.id;
metadata.fileTransferLocationTypeId = fileLocation.locationTypeId;
delete metadata.r__fileLocation_name;
delete metadata.source.r__fileLocation_name;

switch (metadata.c__destinationType) {
switch (metadata.destination.c__destinationType) {
case 'DataExtension': {
if (metadata.r__dataExtension_CustomerKey) {
if (metadata.destination.r__dataExtension_CustomerKey) {
metadata.destinationObjectId = cache.searchForField(
'dataExtension',
metadata.r__dataExtension_CustomerKey,
metadata.destination.r__dataExtension_CustomerKey,
'CustomerKey',
'ObjectID'
);
delete metadata.r__dataExtension_CustomerKey;
delete metadata.destination.r__dataExtension_CustomerKey;
} else {
throw new Error('Import Destination DataExtension not defined');
}
break;
}
case 'List': {
if (metadata.r__list_PathName) {
if (metadata.destination.r__list_PathName) {
metadata.destinationObjectId = cache.getListObjectId(
metadata.r__list_PathName,
metadata.destination.r__list_PathName,
'ObjectID'
);
// destinationId is also needed for List types
metadata.destinationId = cache.getListObjectId(metadata.r__list_PathName, 'ID');
delete metadata.r__list_PathName;
metadata.destinationId = cache.getListObjectId(
metadata.destination.r__list_PathName,
'ID'
);
delete metadata.destination.r__list_PathName;
} else {
throw new Error('Import Destination List not defined');
}
break;
}
case 'SMS': {
if (metadata.c__codeKeyword) {
if (metadata.destination.c__codeKeyword) {
// code
const codeObj = cache.getByKey(
'mobileCode',
metadata.c__codeKeyword.split('.')[0]
metadata.destination.c__codeKeyword.split('.')[0]
);
if (!codeObj) {
throw new Error(`mobileCode ${metadata.c__codeKeyword} not found in cache`);
throw new Error(
`mobileCode ${metadata.destination.c__codeKeyword} not found in cache`
);
}
metadata.code = codeObj;

// keyword
const keywordObj = cache.getByKey('mobileKeyword', metadata.c__codeKeyword);
const keywordObj = cache.getByKey(
'mobileKeyword',
metadata.destination.c__codeKeyword
);
if (!keywordObj) {
throw new Error(
`mobileKeyword ${metadata.c__codeKeyword} not found in cache`
`mobileKeyword ${metadata.destination.c__codeKeyword} not found in cache`
);
}
metadata.keyword = keywordObj;
Expand All @@ -293,25 +302,27 @@ class ImportFile extends MetadataType {
metadata.destinationObjectId = '00000000-0000-0000-0000-000000000000';
metadata.destinationObjectType = 'MobileSubscription';
// source
if (this.dataExtensionsLegacy[metadata.c__sourceObjectKey]) {
if (this.dataExtensionsLegacy[metadata.source.r__dataExtension_CustomerKey]) {
metadata.sourceObjectId =
this.dataExtensionsLegacy[metadata.c__sourceObjectKey].id;
this.dataExtensionsLegacy[metadata.source.r__dataExtension_CustomerKey].id;
metadata.sourceObjectName =
this.dataExtensionsLegacy[metadata.c__sourceObjectKey].dataExtensionName;
delete metadata.c__sourceObjectKey;
this.dataExtensionsLegacy[
metadata.source.r__dataExtension_CustomerKey
].dataExtensionName;
delete metadata.source.r__dataExtension_CustomerKey;
}

Util.logger.debug(
` - importFile ${metadata[this.definition.keyField]}: Import Destination Type ${
metadata.c__destinationType
metadata.destination.c__destinationType
} not fully supported. Deploy might fail.`
);
break;
}
default: {
Util.logger.debug(
` - importFile ${metadata[this.definition.keyField]}: Import Destination Type ${
metadata.c__destinationType
metadata.destination.c__destinationType
} not fully supported. Deploy might fail.`
);
}
Expand All @@ -323,10 +334,13 @@ class ImportFile extends MetadataType {
}
// When the destinationObjectTypeId is 584 it refers to Mobile Connect which is not supported as an Import Type
metadata.destinationObjectTypeId =
this.definition.destinationObjectTypeMapping[metadata.c__destinationType];
this.definition.destinationObjectTypeMapping[metadata.destination.c__destinationType];
metadata.subscriberImportTypeId =
this.definition.subscriberImportTypeMapping[metadata.c__subscriberImportType];
metadata.updateTypeId = this.definition.updateTypeMapping[metadata.c__dataAction];

delete metadata.destination;
delete metadata.source;
return metadata;
}

Expand All @@ -337,7 +351,9 @@ class ImportFile extends MetadataType {
* @returns {MetadataTypeItem} parsed metadata
*/
static postRetrieveTasks(metadata) {
metadata.r__fileLocation_name = cache.searchForField(
metadata.destination = {};
metadata.source = {};
metadata.source.r__fileLocation_name = cache.searchForField(
'fileLocation',
metadata.fileTransferLocationId,
'id',
Expand All @@ -346,14 +362,14 @@ class ImportFile extends MetadataType {
delete metadata.fileTransferLocationId;

// * When the destinationObjectTypeId is 584 it refers to Mobile Connect which is not supported as an Import Type
metadata.c__destinationType = Util.inverseGet(
metadata.destination.c__destinationType = Util.inverseGet(
this.definition.destinationObjectTypeMapping,
metadata.destinationObjectTypeId
);
switch (metadata.c__destinationType) {
switch (metadata.destination.c__destinationType) {
case 'DataExtension': {
try {
metadata.r__dataExtension_CustomerKey = cache.searchForField(
metadata.destination.r__dataExtension_CustomerKey = cache.searchForField(
'dataExtension',
metadata.destinationObjectId,
'ObjectID',
Expand All @@ -368,7 +384,7 @@ class ImportFile extends MetadataType {
}
case 'List': {
try {
metadata.r__list_PathName = cache.getListPathName(
metadata.destination.r__list_PathName = cache.getListPathName(
metadata.destinationObjectId,
'ObjectID'
);
Expand All @@ -383,14 +399,14 @@ class ImportFile extends MetadataType {
if (this.smsImports[metadata.name]) {
const smsImport = this.smsImports[metadata.name];
// code + keyword
metadata.c__codeKeyword =
metadata.destination.c__codeKeyword =
smsImport.code?.code + '.' + smsImport.keyword?.keyword;
// source dataExtension
if (smsImport.sourceObjectKey) {
metadata.c__sourceObjectKey = smsImport.sourceObjectKey;
metadata.source.r__dataExtension_CustomerKey = smsImport.sourceObjectKey;
}
} else {
Util.logger.debug(
Util.logger.warn(
` - ImportFile ${metadata.customerKey}: Could not find mobile code and keyword nor source for this SMS import activity.`
);
}
Expand Down
20 changes: 16 additions & 4 deletions lib/metadataTypes/definitions/ImportFile.definition.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,25 +255,37 @@ export default {
retrieving: true,
template: true,
},
r__dataExtension_CustomerKey: {
'destination.c__codeKeyword': {
isCreateable: false,
isUpdateable: false,
retrieving: true,
template: true,
},
c__destinationType: {
'source.r__dataExtension_CustomerKey': {
isCreateable: false,
isUpdateable: false,
retrieving: true,
template: true,
},
r__list_PathName: {
'destination.r__dataExtension_CustomerKey': {
isCreateable: false,
isUpdateable: false,
retrieving: true,
template: true,
},
r__fileLocation_name: {
'destination.c__destinationType': {
isCreateable: false,
isUpdateable: false,
retrieving: true,
template: true,
},
'destination.r__list_PathName': {
isCreateable: false,
isUpdateable: false,
retrieving: true,
template: true,
},
'source.r__fileLocation_name': {
isCreateable: false,
isUpdateable: false,
retrieving: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,12 @@
"standardQuotedStrings": true,
"c__blankFileProcessing": "Process",
"c__dataAction": "AddUpdate",
"c__destinationType": "DataExtension",
"c__subscriberImportType": "DataExtension",
"r__dataExtension_CustomerKey": "testExisting_dataExtension",
"r__fileLocation_name": "ExactTarget Enhanced FTP"
"destination": {
"c__destinationType": "DataExtension",
"r__dataExtension_CustomerKey": "testExisting_dataExtension"
},
"source": {
"r__fileLocation_name": "ExactTarget Enhanced FTP"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,13 @@
"name": "testNew_importFile",
"sendEmailNotification": false,
"standardQuotedStrings": true,
"r__fileLocation_name": "ExactTarget Enhanced FTP",
"c__destinationType": "DataExtension",
"r__dataExtension_CustomerKey": "testExisting_dataExtension",
"c__subscriberImportType": "DataExtension",
"c__dataAction": "AddUpdate"
"c__dataAction": "AddUpdate",
"destination": {
"c__destinationType": "DataExtension",
"r__dataExtension_CustomerKey": "testExisting_dataExtension"
},
"source": {
"r__fileLocation_name": "ExactTarget Enhanced FTP"
}
}
12 changes: 8 additions & 4 deletions test/resources/9999999/importFile/build-expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"allowErrors": true,
"c__blankFileProcessing": "Skip",
"c__dataAction": "AddUpdate",
"c__destinationType": "DataExtension",
"c__subscriberImportType": "DataExtension",
"customerKey": "testTemplated_importFile",
"dateFormatLocale": "en-US",
Expand All @@ -21,8 +20,13 @@
"maxFileAgeScheduleOffsetHours": 0,
"maxImportFrequencyHours": 0,
"name": "testTemplated_importFile",
"r__dataExtension_CustomerKey": "testTemplated_dataExtension",
"r__fileLocation_name": "ExactTarget Enhanced FTP",
"sendEmailNotification": false,
"standardQuotedStrings": true
"standardQuotedStrings": true,
"destination": {
"c__destinationType": "DataExtension",
"r__dataExtension_CustomerKey": "testTemplated_dataExtension"
},
"source": {
"r__fileLocation_name": "ExactTarget Enhanced FTP"
}
}
13 changes: 9 additions & 4 deletions test/resources/9999999/importFile/get-expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"allowErrors": true,
"c__blankFileProcessing": "Skip",
"c__dataAction": "AddUpdate",
"c__destinationType": "DataExtension",
"c__subscriberImportType": "DataExtension",
"createdDate": "2022-11-09T05:32:30.533",
"customerKey": "testExisting_importFile",
Expand All @@ -23,8 +22,14 @@
"maxImportFrequencyHours": 0,
"modifiedDate": "2022-11-17T07:13:03.95",
"name": "testExisting_importFile",
"r__dataExtension_CustomerKey": "testExisting_dataExtension",
"r__fileLocation_name": "ExactTarget Enhanced FTP",

"sendEmailNotification": false,
"standardQuotedStrings": true
"standardQuotedStrings": true,
"destination": {
"c__destinationType": "DataExtension",
"r__dataExtension_CustomerKey": "testExisting_dataExtension"
},
"source": {
"r__fileLocation_name": "ExactTarget Enhanced FTP"
}
}
12 changes: 9 additions & 3 deletions test/resources/9999999/importFile/get-sms-expected.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"allowErrors": true,
"c__dataAction": "AddUpdate",
"c__destinationType": "SMS",
"c__subscriberImportType": "DataExtension",
"createdDate": "2022-11-24T03:29:01.05",
"customerKey": "testExisting_importFileSMS",
Expand Down Expand Up @@ -67,7 +66,14 @@
"modifiedDate": "2023-07-19T23:06:33.577",
"name": "testExisting_importFileSMS",
"notificationEmailAddress": "joern.berkefeld@accenture.com",
"r__fileLocation_name": "ExactTarget Enhanced FTP",
"sendEmailNotification": true,
"standardQuotedStrings": false
"standardQuotedStrings": false,
"destination": {
"c__destinationType": "SMS",
"c__codeKeyword": "4912312345678.TESTEXISTING_KEYWORD"
},
"source": {
"r__dataExtension_CustomerKey": "testExisting_dataExtension",
"r__fileLocation_name": "ExactTarget Enhanced FTP"
}
}
12 changes: 8 additions & 4 deletions test/resources/9999999/importFile/patch-expected.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
"allowErrors": true,
"c__blankFileProcessing": "Process",
"c__dataAction": "AddUpdate",
"c__destinationType": "DataExtension",
"c__subscriberImportType": "DataExtension",
"createdDate": "2022-11-09T05:32:30.533",
"customerKey": "testExisting_importFile",
Expand All @@ -23,8 +22,13 @@
"maxImportFrequencyHours": 0,
"modifiedDate": "2023-07-18T09:11:26.19",
"name": "testExisting_importFile",
"r__dataExtension_CustomerKey": "testExisting_dataExtension",
"r__fileLocation_name": "ExactTarget Enhanced FTP",
"sendEmailNotification": false,
"standardQuotedStrings": true
"standardQuotedStrings": true,
"destination": {
"c__destinationType": "DataExtension",
"r__dataExtension_CustomerKey": "testExisting_dataExtension"
},
"source": {
"r__fileLocation_name": "ExactTarget Enhanced FTP"
}
}
Loading
Loading