Skip to content

Commit

Permalink
#984: added a test for importFile
Browse files Browse the repository at this point in the history
  • Loading branch information
phjulia committed Aug 14, 2023
1 parent ae4cc5d commit 309de98
Show file tree
Hide file tree
Showing 9 changed files with 192 additions and 33 deletions.
12 changes: 6 additions & 6 deletions docs/dist/documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -6124,7 +6124,7 @@ CLI entry for SFMC DevTools
* [.isFalse(attrValue)](#Util.isFalse) ⇒ <code>boolean</code>
* [._isValidType(selectedType, [handleOutside])](#Util._isValidType) ⇒ <code>boolean</code>
* [.getTypeAndSubType(selectedType)](#Util.getTypeAndSubType) ⇒ <code>Array.&lt;string&gt;</code>
* [.emailValidator(email)](#Util.emailValidator) ⇒ <code>Boolean</code>
* [.emailValidator(email)](#Util.emailValidator) ⇒ <code>boolean</code>
* [.getRetrieveTypeChoices()](#Util.getRetrieveTypeChoices) ⇒ <code>Array.&lt;TYPE.SupportedMetadataTypes&gt;</code>
* [._createNewLoggerTransport([noLogFile])](#Util._createNewLoggerTransport) ⇒ <code>object</code>
* [.startLogger([restart], [noLogFile])](#Util.startLogger) ⇒ <code>void</code>
Expand Down Expand Up @@ -6280,11 +6280,11 @@ helper that deals with extracting type and subtype

<a name="Util.emailValidator"></a>

### Util.emailValidator(email) ⇒ <code>Boolean</code>
### Util.emailValidator(email) ⇒ <code>boolean</code>
helper that validates email address

**Kind**: static method of [<code>Util</code>](#Util)
**Returns**: <code>Boolean</code> - first elem is type, second elem is subType
**Returns**: <code>boolean</code> - first elem is type, second elem is subType

| Param | Type | Description |
| --- | --- | --- |
Expand Down Expand Up @@ -8056,7 +8056,7 @@ Util that contains logger and simple util methods
* [.isFalse(attrValue)](#Util.isFalse) ⇒ <code>boolean</code>
* [._isValidType(selectedType, [handleOutside])](#Util._isValidType) ⇒ <code>boolean</code>
* [.getTypeAndSubType(selectedType)](#Util.getTypeAndSubType) ⇒ <code>Array.&lt;string&gt;</code>
* [.emailValidator(email)](#Util.emailValidator) ⇒ <code>Boolean</code>
* [.emailValidator(email)](#Util.emailValidator) ⇒ <code>boolean</code>
* [.getRetrieveTypeChoices()](#Util.getRetrieveTypeChoices) ⇒ <code>Array.&lt;TYPE.SupportedMetadataTypes&gt;</code>
* [._createNewLoggerTransport([noLogFile])](#Util._createNewLoggerTransport) ⇒ <code>object</code>
* [.startLogger([restart], [noLogFile])](#Util.startLogger) ⇒ <code>void</code>
Expand Down Expand Up @@ -8212,11 +8212,11 @@ helper that deals with extracting type and subtype

<a name="Util.emailValidator"></a>

### Util.emailValidator(email) ⇒ <code>Boolean</code>
### Util.emailValidator(email) ⇒ <code>boolean</code>
helper that validates email address

**Kind**: static method of [<code>Util</code>](#Util)
**Returns**: <code>Boolean</code> - first elem is type, second elem is subType
**Returns**: <code>boolean</code> - first elem is type, second elem is subType

| Param | Type | Description |
| --- | --- | --- |
Expand Down
17 changes: 6 additions & 11 deletions lib/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -1022,6 +1022,11 @@ class Mcdev {
Object.prototype.hasOwnProperty.call(MetadataTypeInfo[type], methodName)
) {
resultArr.push(...(await MetadataTypeInfo[type][methodName](keyArr)));
if (resultArr.length > 0) {
Util.logger.info(`Retrieving ${type} to have most recent changes`);
const retriever = new Retriever(this.properties, this.buObject);
await retriever.retrieve([type], resultArr, null, false);
}
} else {
resultArr.push(
...(await this.#updateNotificationsGeneric(type, keyArr))
Expand Down Expand Up @@ -1220,11 +1225,6 @@ class Mcdev {
// clear will execute first, and then updateNotifications overwriting result
result = await this.#runMethod('updateNotifications', businessUnit, selectedType, keys);
}
if (Object.values(result)[0].length > 0) {
Util.logger.info(`Retrieving automations to have most recent changes`);
const retriever = new Retriever(this.properties, this.buObject);
await retriever.retrieve([selectedType], Object.values(result), null, false);
}
return result;
}
/**
Expand All @@ -1237,11 +1237,7 @@ class Mcdev {
static async #updateNotificationsGeneric(type, keyArr) {
let keysUpdatedNotifications = [];
const resultArr = [];
if (
!Object.prototype.hasOwnProperty.call(
(MetadataTypeDefinitions[type].sendEmailNotification, 'updateNotifications')
)
) {
if (!MetadataTypeDefinitions[type].fields.sendEmailNotification) {
Util.logger.error(`Update notifications is not supported for this type`);
return resultArr;
}
Expand Down Expand Up @@ -1282,7 +1278,6 @@ class Mcdev {
} catch (ex) {
Util.logger.errorStack(ex, 'mcdev.updateNotificationsGeneric failed');
}
Util.logger.info(`:: Done\n`);
return resultArr;
}
}
Expand Down
19 changes: 8 additions & 11 deletions lib/metadataTypes/MetadataType.js
Original file line number Diff line number Diff line change
Expand Up @@ -2114,24 +2114,21 @@ class MetadataType {
`Searching for ${this.definition.type} keys among downloaded items where notification email address should be updated:`
);
for (const item of Object.values(metadataMap)) {
if (
item['sendEmailNotification'] &&
item['notificationEmailAddress'] !== Util.OPTIONS.completionEmail
) {
keysForDeploy.push(item[this.definition.keyField]);
Util.logger.info(
` - added ${this.definition.type} to updateNotification queue: ${
item[this.definition.keyField]
}`
);
} else {
if (item['notificationEmailAddress'] === Util.OPTIONS.completionEmail) {
Util.logger.info(
Util.getGrayMsg(
` ☇ skipping ${this.definition.type} ${
item[this.definition.keyField]
}: email address does not need to be updated`
)
);
} else {
keysForDeploy.push(item[this.definition.keyField]);
Util.logger.info(
` - added ${this.definition.type} to updateNotification queue: ${
item[this.definition.keyField]
}`
);
}
}
Util.logger.info(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"allowErrors": true,
"createdDate": "2022-11-09T05:32:30.533",
"customerKey": "testExisting_importFile_updateNotifications",
"dateFormatLocale": "en-US",
"deleteFile": false,
"description": "updated on deploy",
"fieldMappingType": "InferFromColumnHeadings",
"fieldMappings": [],
"fileNamingPattern": "blabla",
"fileTransferLocationTypeId": 0,
"fileType": "CSV",
"filter": "",
"hasColumnHeader": true,
"isOrderedImport": true,
"isSequential": true,
"maxFileAgeHours": 0,
"maxFileAgeScheduleOffsetHours": 0,
"maxImportFrequencyHours": 0,
"modifiedDate": "2022-11-17T07:13:03.95",
"name": "testExisting_importFile_updateNotifications",
"sendEmailNotification": true,
"notificationEmailAddress": "test@test.com",
"standardQuotedStrings": true,
"r__fileLocation_name": "ExactTarget Enhanced FTP",
"c__destinationType": "DataExtension",
"r__dataExtension_CustomerKey": "testExisting_dataExtension",
"c__subscriberImportType": "DataExtension",
"c__dataAction": "AddUpdate"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"allowErrors": true,
"customerKey": "testExisting_importFile_updateNotifications",
"dateFormatLocale": "en-US",
"deleteFile": false,
"description": "updated on deploy",
"fieldMappingType": "InferFromColumnHeadings",
"fieldMappings": [],
"fileNamingPattern": "blabla",
"fileTransferLocationTypeId": 0,
"fileType": "CSV",
"filter": "",
"hasColumnHeader": true,
"isOrderedImport": true,
"isSequential": true,
"maxFileAgeHours": 0,
"maxFileAgeScheduleOffsetHours": 0,
"maxImportFrequencyHours": 0,
"name": "testExisting_importFile_updateNotifications",
"sendEmailNotification": false,
"standardQuotedStrings": true,
"fileTransferLocationId": "41a5ded7-0d98-4910-a15f-d09e7ab0af24",
"destinationObjectId": "21711373-72c1-ec11-b83b-48df37d1deb7",
"destinationObjectTypeId": 310,
"subscriberImportTypeId": 255,
"updateTypeId": 0,
"importDefinitionId": "9d16f42c-2260-ed11-b849-48df37d1de8b_updateNotifications",
"createdDate": "2022-11-09T05:53:03.243",
"destinationId": 0,
"modifiedDate": "2023-07-18T09:11:26.19"
}
33 changes: 32 additions & 1 deletion test/resources/9999999/automation/v1/imports/get-response.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"page": 1,
"pageSize": 500,
"count": 1,
"count": 2,
"items": [
{
"allowErrors": true,
Expand Down Expand Up @@ -33,6 +33,37 @@
"subscriberImportTypeId": 255,
"updateTypeId": 0,
"fileTransferLocationTypeId": 0
},
{
"allowErrors": true,
"customerKey": "testExisting_importFile_updateNotifications",
"createdDate": "2022-11-09T05:32:30.533",
"modifiedDate": "2022-11-17T07:13:03.95",
"dateFormatLocale": "en-US",
"deleteFile": false,
"description": "17.11.2022",
"destinationObjectId": "21711373-72c1-ec11-b83b-48df37d1deb7",
"destinationId": 0,
"destinationObjectTypeId": 310,
"fieldMappings": [],
"fieldMappingType": "InferFromColumnHeadings",
"fileNamingPattern": "blabla",
"fileTransferLocationId": "41a5ded7-0d98-4910-a15f-d09e7ab0af24",
"fileType": "CSV",
"filter": "",
"hasColumnHeader": true,
"importDefinitionId": "9d16f42c-2260-ed11-b849-48df37d1de8b_updateNotifications",
"isOrderedImport": true,
"isSequential": true,
"maxFileAgeHours": 0,
"maxImportFrequencyHours": 0,
"maxFileAgeScheduleOffsetHours": 0,
"name": "testExisting_importFile_updateNotifications",
"sendEmailNotification": false,
"standardQuotedStrings": true,
"subscriberImportTypeId": 255,
"updateTypeId": 0,
"fileTransferLocationTypeId": 0
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"allowErrors": true,
"createdDate": "2022-11-09T05:32:30.533",
"customerKey": "testExisting_importFile_updateNotifications",
"dateFormatLocale": "en-US",
"deleteFile": false,
"description": "updated on deploy",
"fieldMappingType": "InferFromColumnHeadings",
"fieldMappings": [],
"fileNamingPattern": "blabla",
"fileTransferLocationTypeId": 0,
"fileType": "CSV",
"filter": "",
"hasColumnHeader": true,
"isOrderedImport": true,
"isSequential": true,
"maxFileAgeHours": 0,
"maxFileAgeScheduleOffsetHours": 0,
"maxImportFrequencyHours": 0,
"modifiedDate": "2022-11-17T07:13:03.95",
"name": "testExisting_importFile_updateNotifications",
"sendEmailNotification": true,
"notificationEmailAddress": "test@test.com",
"standardQuotedStrings": true,
"r__fileLocation_name": "ExactTarget Enhanced FTP",
"c__destinationType": "DataExtension",
"r__dataExtension_CustomerKey": "testExisting_dataExtension",
"c__subscriberImportType": "DataExtension",
"c__dataAction": "AddUpdate"
}
5 changes: 5 additions & 0 deletions test/type.automation.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,11 @@ describe('type: automation', () => {
await testUtils.getExpectedJson('9999999', 'automation', 'updateNotifications'),
'returned metadata was not equal expected for update'
);
assert.equal(
testUtils.getAPIHistoryLength(),
17,
'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
);
return;
});
it('Should NOT update run failure email address', async () => {
Expand Down
48 changes: 44 additions & 4 deletions test/type.importFile.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@ describe('type: importFile', () => {
describe('Retrieve ================', () => {
it('Should retrieve a importFile', async () => {
// WHEN
await handler.retrieve('testInstance/testBU', ['importFile']);
await handler.retrieve(
'testInstance/testBU',
['importFile'],
['testExisting_importFile']
);
// THEN
assert.equal(process.exitCode, false, 'retrieve should not have thrown an error');
// get results from cache
Expand Down Expand Up @@ -54,8 +58,8 @@ describe('type: importFile', () => {
const result = cache.getCache();
assert.equal(
result.importFile ? Object.keys(result.importFile).length : 0,
2,
'two importFiles expected'
3,
'three importFiles expected'
);
// confirm created item
assert.deepEqual(
Expand All @@ -72,7 +76,7 @@ describe('type: importFile', () => {
// check number of API calls
assert.equal(
testUtils.getAPIHistoryLength(),
12,
13,
'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
);
return;
Expand Down Expand Up @@ -183,4 +187,40 @@ describe('type: importFile', () => {
return;
});
});
describe('Update email notifications for an importFile ================', () => {
beforeEach(() => {
testUtils.mockSetup(true);
});
it('Should update email notifications', async () => {
handler.setOptions({ completionEmail: 'test@test.com' });
// WHEN
await handler.updateNotifications('testInstance/testBU', 'importFile', [
'testExisting_importFile_updateNotifications',
]);
// THEN
assert.equal(
process.exitCode,
false,
'updateNotifications should not have thrown an error'
);
assert.deepEqual(
await testUtils.getActualDeployJson(
'testExisting_importFile_updateNotifications',
'importFile'
),
await testUtils.getExpectedJson(
'9999999',
'importFile',
'patch_updateNotifications'
),
'returned deployment JSON was not equal expected'
);
assert.equal(
testUtils.getAPIHistoryLength(),
21,
'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests'
);
return;
});
});
});

0 comments on commit 309de98

Please sign in to comment.