From 309de98352edeebf66020279f1b372fd8381d700 Mon Sep 17 00:00:00 2001 From: Yuliia Likhytska Date: Mon, 14 Aug 2023 15:00:23 +0200 Subject: [PATCH] #984: added a test for importFile --- docs/dist/documentation.md | 12 ++--- lib/index.js | 17 +++---- lib/metadataTypes/MetadataType.js | 19 ++++---- ...e_updateNotifications.importFile-meta.json | 30 ++++++++++++ .../patch-response.json | 31 ++++++++++++ .../automation/v1/imports/get-response.json | 33 ++++++++++++- .../patch_updateNotifications-expected.json | 30 ++++++++++++ test/type.automation.test.js | 5 ++ test/type.importFile.test.js | 48 +++++++++++++++++-- 9 files changed, 192 insertions(+), 33 deletions(-) create mode 100644 test/mockRoot/deploy/testInstance/testBU/importFile/testExisting_importFile_updateNotifications.importFile-meta.json create mode 100644 test/resources/9999999/automation/v1/imports/9d16f42c-2260-ed11-b849-48df37d1de8b_updateNotifications/patch-response.json create mode 100644 test/resources/9999999/importFile/patch_updateNotifications-expected.json diff --git a/docs/dist/documentation.md b/docs/dist/documentation.md index 9821ee742..1889de40b 100644 --- a/docs/dist/documentation.md +++ b/docs/dist/documentation.md @@ -6124,7 +6124,7 @@ CLI entry for SFMC DevTools * [.isFalse(attrValue)](#Util.isFalse) ⇒ boolean * [._isValidType(selectedType, [handleOutside])](#Util._isValidType) ⇒ boolean * [.getTypeAndSubType(selectedType)](#Util.getTypeAndSubType) ⇒ Array.<string> - * [.emailValidator(email)](#Util.emailValidator) ⇒ Boolean + * [.emailValidator(email)](#Util.emailValidator) ⇒ boolean * [.getRetrieveTypeChoices()](#Util.getRetrieveTypeChoices) ⇒ Array.<TYPE.SupportedMetadataTypes> * [._createNewLoggerTransport([noLogFile])](#Util._createNewLoggerTransport) ⇒ object * [.startLogger([restart], [noLogFile])](#Util.startLogger) ⇒ void @@ -6280,11 +6280,11 @@ helper that deals with extracting type and subtype -### Util.emailValidator(email) ⇒ Boolean +### Util.emailValidator(email) ⇒ boolean helper that validates email address **Kind**: static method of [Util](#Util) -**Returns**: Boolean - first elem is type, second elem is subType +**Returns**: boolean - first elem is type, second elem is subType | Param | Type | Description | | --- | --- | --- | @@ -8056,7 +8056,7 @@ Util that contains logger and simple util methods * [.isFalse(attrValue)](#Util.isFalse) ⇒ boolean * [._isValidType(selectedType, [handleOutside])](#Util._isValidType) ⇒ boolean * [.getTypeAndSubType(selectedType)](#Util.getTypeAndSubType) ⇒ Array.<string> - * [.emailValidator(email)](#Util.emailValidator) ⇒ Boolean + * [.emailValidator(email)](#Util.emailValidator) ⇒ boolean * [.getRetrieveTypeChoices()](#Util.getRetrieveTypeChoices) ⇒ Array.<TYPE.SupportedMetadataTypes> * [._createNewLoggerTransport([noLogFile])](#Util._createNewLoggerTransport) ⇒ object * [.startLogger([restart], [noLogFile])](#Util.startLogger) ⇒ void @@ -8212,11 +8212,11 @@ helper that deals with extracting type and subtype -### Util.emailValidator(email) ⇒ Boolean +### Util.emailValidator(email) ⇒ boolean helper that validates email address **Kind**: static method of [Util](#Util) -**Returns**: Boolean - first elem is type, second elem is subType +**Returns**: boolean - first elem is type, second elem is subType | Param | Type | Description | | --- | --- | --- | diff --git a/lib/index.js b/lib/index.js index 4dac6794a..e1f7d5a49 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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)) @@ -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; } /** @@ -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; } @@ -1282,7 +1278,6 @@ class Mcdev { } catch (ex) { Util.logger.errorStack(ex, 'mcdev.updateNotificationsGeneric failed'); } - Util.logger.info(`:: Done\n`); return resultArr; } } diff --git a/lib/metadataTypes/MetadataType.js b/lib/metadataTypes/MetadataType.js index cbf289e74..00540921e 100644 --- a/lib/metadataTypes/MetadataType.js +++ b/lib/metadataTypes/MetadataType.js @@ -2114,17 +2114,7 @@ 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} ${ @@ -2132,6 +2122,13 @@ class MetadataType { }: 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( diff --git a/test/mockRoot/deploy/testInstance/testBU/importFile/testExisting_importFile_updateNotifications.importFile-meta.json b/test/mockRoot/deploy/testInstance/testBU/importFile/testExisting_importFile_updateNotifications.importFile-meta.json new file mode 100644 index 000000000..1e041b354 --- /dev/null +++ b/test/mockRoot/deploy/testInstance/testBU/importFile/testExisting_importFile_updateNotifications.importFile-meta.json @@ -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" +} diff --git a/test/resources/9999999/automation/v1/imports/9d16f42c-2260-ed11-b849-48df37d1de8b_updateNotifications/patch-response.json b/test/resources/9999999/automation/v1/imports/9d16f42c-2260-ed11-b849-48df37d1de8b_updateNotifications/patch-response.json new file mode 100644 index 000000000..886964e97 --- /dev/null +++ b/test/resources/9999999/automation/v1/imports/9d16f42c-2260-ed11-b849-48df37d1de8b_updateNotifications/patch-response.json @@ -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" +} diff --git a/test/resources/9999999/automation/v1/imports/get-response.json b/test/resources/9999999/automation/v1/imports/get-response.json index 000537e3b..688158665 100644 --- a/test/resources/9999999/automation/v1/imports/get-response.json +++ b/test/resources/9999999/automation/v1/imports/get-response.json @@ -1,7 +1,7 @@ { "page": 1, "pageSize": 500, - "count": 1, + "count": 2, "items": [ { "allowErrors": true, @@ -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 } ] } diff --git a/test/resources/9999999/importFile/patch_updateNotifications-expected.json b/test/resources/9999999/importFile/patch_updateNotifications-expected.json new file mode 100644 index 000000000..1e041b354 --- /dev/null +++ b/test/resources/9999999/importFile/patch_updateNotifications-expected.json @@ -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" +} diff --git a/test/type.automation.test.js b/test/type.automation.test.js index b2f5067ce..e1815575b 100644 --- a/test/type.automation.test.js +++ b/test/type.automation.test.js @@ -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 () => { diff --git a/test/type.importFile.test.js b/test/type.importFile.test.js index 76e9c3642..cede06c0e 100644 --- a/test/type.importFile.test.js +++ b/test/type.importFile.test.js @@ -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 @@ -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( @@ -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; @@ -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; + }); + }); });