From fe053f8877689311f12060af9bdaa16015f79a21 Mon Sep 17 00:00:00 2001 From: Yuliia Likhytska Date: Sun, 3 Sep 2023 11:39:01 +0200 Subject: [PATCH 1/7] #1084: add updateNotifications support for dataVerification --- docs/dist/documentation.md | 30 ++++++++ lib/index.js | 17 +++-- lib/metadataTypes/Verification.js | 109 ++++++++++++++++++++++++++++++ 3 files changed, 150 insertions(+), 6 deletions(-) diff --git a/docs/dist/documentation.md b/docs/dist/documentation.md index fa3b63b7f..3a9db7f50 100644 --- a/docs/dist/documentation.md +++ b/docs/dist/documentation.md @@ -6241,6 +6241,8 @@ Verification MetadataType * [.preDeployTasks(metadata)](#Verification.preDeployTasks) ⇒ TYPE.VerificationItem * [.postRetrieveTasks(metadata)](#Verification.postRetrieveTasks) ⇒ TYPE.VerificationItem * [.deleteByKey(key)](#Verification.deleteByKey) ⇒ Promise.<boolean> + * [.getKeysToSetNotifications(metadataMap)](#Verification.getKeysToSetNotifications) ⇒ Array.<string> + * [.createOrUpdate(metadataMap, metadataKey, hasError, metadataToUpdate, metadataToCreate)](#Verification.createOrUpdate) ⇒ 'create' \| 'update' \| 'skip' @@ -6350,6 +6352,34 @@ Delete a metadata item from the specified business unit | --- | --- | --- | | key | string | Identifier of item | + + +### Verification.getKeysToSetNotifications(metadataMap) ⇒ Array.<string> +helper function to get a list of keys where notification email addresses or notes should be updated + +**Kind**: static method of [Verification](#Verification) +**Returns**: Array.<string> - list of keys + +| Param | Type | Description | +| --- | --- | --- | +| metadataMap | TYPE.MetadataTypeMap | metadata mapped by their keyField | + + + +### Verification.createOrUpdate(metadataMap, metadataKey, hasError, metadataToUpdate, metadataToCreate) ⇒ 'create' \| 'update' \| 'skip' +helper for [upsert](#MetadataType.upsert) + +**Kind**: static method of [Verification](#Verification) +**Returns**: 'create' \| 'update' \| 'skip' - action to take + +| Param | Type | Description | +| --- | --- | --- | +| metadataMap | TYPE.MetadataTypeMap | list of metadata | +| metadataKey | string | key of item we are looking at | +| hasError | boolean | error flag from previous code | +| metadataToUpdate | Array.<TYPE.MetadataTypeItemDiff> | list of items to update | +| metadataToCreate | Array.<TYPE.MetadataTypeItem> | list of items to create | + ## Retriever diff --git a/lib/index.js b/lib/index.js index 1e9f8a085..2b5c0c660 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1259,14 +1259,19 @@ class Mcdev { */ static async #updateNotifications(cred, bu, type, keyArr) { let keysUpdatedNotifications = []; - if (Util.OPTIONS.errorEmail || Util.OPTIONS.errorNote || Util.OPTIONS.completionNote) { - Util.logger.error( - `--errorEmail, --errorNote and --completionNote options are not available for ${type}` - ); + if (!MetadataTypeDefinitions[type].fields.notificationEmailAddress) { + Util.logger.error(`Update notifications is not supported for this type`); return keysUpdatedNotifications; } - if (!MetadataTypeDefinitions[type].fields.sendEmailNotification) { - Util.logger.error(`Update notifications is not supported for this type`); + if (Util.OPTIONS.errorEmail || Util.OPTIONS.errorNote) { + Util.logger.error(`--errorEmail, --errorNote options are not available for ${type}`); + return keysUpdatedNotifications; + } + if ( + !MetadataTypeDefinitions[type].fields.notificationEmailMessage && + Util.OPTIONS.completionNote + ) { + Util.logger.error(`--completionNote option is not available for ${type}`); return keysUpdatedNotifications; } this.setOptions({ diff --git a/lib/metadataTypes/Verification.js b/lib/metadataTypes/Verification.js index 93ce29fd0..c66243dad 100644 --- a/lib/metadataTypes/Verification.js +++ b/lib/metadataTypes/Verification.js @@ -5,6 +5,7 @@ const MetadataType = require('./MetadataType'); const Automation = require('./Automation'); const Util = require('../util/util'); const cache = require('../util/cache'); +const Cli = require('../util/cli'); /** * Verification MetadataType @@ -222,6 +223,114 @@ class Verification extends MetadataType { static deleteByKey(key) { return super.deleteByKeyREST('/automation/v1/dataverifications/' + key, key); } + /** + * helper function to get a list of keys where notification email addresses or notes should be updated + * + * @param {TYPE.MetadataTypeMap} metadataMap metadata mapped by their keyField + * @returns {string[]} list of keys + */ + static async getKeysToSetNotifications(metadataMap) { + const keysForDeploy = []; + let completionEmail = []; + if (Util.OPTIONS.completionEmail) { + completionEmail = Util.OPTIONS.completionEmail.split(','); + } + if (Object.keys(metadataMap).length) { + Util.logger.info( + `Searching for ${this.definition.type} keys among downloaded items where notification email address should be updated:` + ); + for (const item of Object.values(metadataMap)) { + const oldCompletionEmails = item['notificationEmailAddress']; + const oldCompletionNote = item['notificationEmailMessage']; + + if (Util.OPTIONS.clear && (oldCompletionEmails != '' || oldCompletionNote != '')) { + keysForDeploy.push(item[this.definition.keyField]); + Util.logger.info( + ` - added ${this.definition.type} to updateNotification queue: ${ + item[this.definition.keyField] + }` + ); + continue; + } + + for (const email of completionEmail) { + if (oldCompletionEmails.includes(email) || !Util.emailValidator(email)) { + Util.logger.info( + ` ☇ skipping ${email}- this email address is already in the notifications or is not a valid email` + ); + Util.OPTIONS.completionEmail = completionEmail.slice( + completionEmail.indexOf(email), + 1 + ); + } + } + if (oldCompletionNote == Util.OPTIONS.completionNote) { + Util.logger.verbose( + ` ☇ skipping --completionNote, note does not need to be updated` + ); + Util.OPTIONS.completionNote = undefined; + } + // if email address/-es were not set, ask for input + if ( + Util.OPTIONS.completionNote && + completionEmail.length < 1 && + oldCompletionEmails.length < 1 + ) { + const emails = await Cli.updateNotificationEmails('completionEmail'); + if (emails) { + Util.OPTIONS.completionEmail = emails.join(','); + } else { + Util.OPTIONS.completionNote = undefined; + Util.logger.info( + ` ☇ skipping --completionNote' - the email address for Run completion was not set` + ); + } + } + if (Util.OPTIONS.completionNote || completionEmail.length > 0) { + keysForDeploy.push(item[this.definition.keyField]); + Util.logger.info( + ` - added ${this.definition.type} to updateNotification queue: ${ + item[this.definition.keyField] + }` + ); + } + } + Util.logger.info( + `Found ${keysForDeploy.length} ${this.definition.type} keys to update email notification address` + ); + } + return keysForDeploy; + } + /** + * helper for {@link MetadataType.upsert} + * + * @param {TYPE.MetadataTypeMap} metadataMap list of metadata + * @param {string} metadataKey key of item we are looking at + * @param {boolean} hasError error flag from previous code + * @param {TYPE.MetadataTypeItemDiff[]} metadataToUpdate list of items to update + * @param {TYPE.MetadataTypeItem[]} metadataToCreate list of items to create + * @returns {'create' | 'update' | 'skip'} action to take + */ + static createOrUpdate(metadataMap, metadataKey, hasError, metadataToUpdate, metadataToCreate) { + if (Util.OPTIONS.clear) { + metadataMap[metadataKey].notificationEmailAddress = ''; + metadataMap[metadataKey].notificationEmailMessage = ''; + } + if (Util.OPTIONS.completionEmail) { + metadataMap[metadataKey].notificationEmailAddress = Util.OPTIONS.completionEmail; + } + if (Util.OPTIONS.completionNote) { + metadataMap[metadataKey].notificationEmailMessage = Util.OPTIONS.completionNote; + } + const createOrUpdateAction = super.createOrUpdate( + metadataMap, + metadataKey, + hasError, + metadataToUpdate, + metadataToCreate + ); + return createOrUpdateAction; + } } // Assign definition to static attributes From a31aa38125c01f5f73479db1b06c70b350efb821 Mon Sep 17 00:00:00 2001 From: Yuliia Likhytska Date: Mon, 4 Sep 2023 19:33:05 +0200 Subject: [PATCH 2/7] #1084: test update verification notification email --- ...eNotificationsEmail.verification-meta.json | 11 +++++ .../get-response.json | 12 ++++++ .../updateNotificationsEmail-expected.json | 11 +++++ test/type.verification.test.js | 43 +++++++++++++++++++ 4 files changed, 77 insertions(+) create mode 100644 test/mockRoot/deploy/testInstance/testBU/verification/testExisting_verification._updateNotificationsEmail.verification-meta.json create mode 100644 test/resources/9999999/automation/v1/dataverifications/testExisting_verification_updateNotificationsEmail/get-response.json create mode 100644 test/resources/9999999/verification/updateNotificationsEmail-expected.json diff --git a/test/mockRoot/deploy/testInstance/testBU/verification/testExisting_verification._updateNotificationsEmail.verification-meta.json b/test/mockRoot/deploy/testInstance/testBU/verification/testExisting_verification._updateNotificationsEmail.verification-meta.json new file mode 100644 index 000000000..19814275c --- /dev/null +++ b/test/mockRoot/deploy/testInstance/testBU/verification/testExisting_verification._updateNotificationsEmail.verification-meta.json @@ -0,0 +1,11 @@ +{ + "dataVerificationDefinitionId": "testExisting_verification._updateNotificationsEmail", + "notificationEmailAddress": "test@test.com", + "notificationEmailMessage": "", + "r__dataExtension_CustomerKey": "testExisting_dataExtension", + "shouldEmailOnFailure": true, + "shouldStopOnFailure": true, + "value1": 1, + "value2": 0, + "verificationType": "IsEqualTo" +} diff --git a/test/resources/9999999/automation/v1/dataverifications/testExisting_verification_updateNotificationsEmail/get-response.json b/test/resources/9999999/automation/v1/dataverifications/testExisting_verification_updateNotificationsEmail/get-response.json new file mode 100644 index 000000000..72889c32c --- /dev/null +++ b/test/resources/9999999/automation/v1/dataverifications/testExisting_verification_updateNotificationsEmail/get-response.json @@ -0,0 +1,12 @@ +{ + "dataVerificationDefinitionId": "testExisting_verification_updateNotificationsEmail", + "targetObjectId": "21711373-72c1-ec11-b83b-48df37d1deb7", + "verificationType": "IsEqualTo", + "value1": 1, + "value2": 0, + "shouldStopOnFailure": true, + "shouldEmailOnFailure": false, + "notificationEmailAddress": "test@test.com", + "notificationEmailMessage": "", + "createdBy": 700301950 +} diff --git a/test/resources/9999999/verification/updateNotificationsEmail-expected.json b/test/resources/9999999/verification/updateNotificationsEmail-expected.json new file mode 100644 index 000000000..187c32884 --- /dev/null +++ b/test/resources/9999999/verification/updateNotificationsEmail-expected.json @@ -0,0 +1,11 @@ +{ + "dataVerificationDefinitionId": "testExisting_verification_updateNotificationsEmail", + "notificationEmailAddress": "test@test.com", + "notificationEmailMessage": "", + "r__dataExtension_CustomerKey": "testExisting_dataExtension", + "shouldEmailOnFailure": false, + "shouldStopOnFailure": true, + "value1": 1, + "value2": 0, + "verificationType": "IsEqualTo" +} diff --git a/test/type.verification.test.js b/test/type.verification.test.js index 9e8a79324..8be84b735 100644 --- a/test/type.verification.test.js +++ b/test/type.verification.test.js @@ -170,4 +170,47 @@ describe('type: verification', () => { return; }); }); + describe('UpdateNotifications ================', () => { + it('Should update notification email', async () => { + handler.setOptions({ completionEmail: 'test@test.com' }); + // WHEN + const updatedNotifications = await handler.updateNotifications( + 'testInstance/testBU', + 'verification', + ['testExisting_verification_updateNotificationsEmail'] + ); + // THEN + assert.equal(process.exitCode, false, 'retrieve should not have thrown an error'); + // get results from cache + const result = cache.getCache(); + assert.equal( + result.verification ? Object.keys(result.verification).length : 0, + 2, + 'only two verifications expected' + ); + assert.equal( + updatedNotifications['testInstance/testBU'].length, + 1, + 'one automation key expected' + ); + assert.deepEqual( + await testUtils.getActualJson( + 'testExisting_verification_updateNotificationsEmail', + 'verification' + ), + await testUtils.getExpectedJson( + '9999999', + 'verification', + 'updateNotificationsEmail' + ), + 'returned JSON was not equal expected' + ); + assert.equal( + testUtils.getAPIHistoryLength(), + 29, + 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' + ); + return; + }); + }); }); From 4f35004b51ecbd01925a72c78811890cba4cb476 Mon Sep 17 00:00:00 2001 From: Yuliia Likhytska Date: Thu, 7 Sep 2023 22:23:40 +0200 Subject: [PATCH 3/7] #1084: positive tests for updatenotifications verifications --- ...eNotificationsEmail.verification-meta.json | 11 +++ .../9999999/automation/build-expected.json | 8 +++ .../9999999/automation/retrieve-expected.json | 8 +++ ...trieve-testExisting_automation-expected.md | 2 + .../9999999/automation/template-expected.json | 8 +++ .../get-response.json | 14 ++++ .../get-response.json | 2 +- .../patch-response.json | 12 ++++ .../get-response.json | 12 ++++ .../patch-response.json | 12 ++++ .../updateNotificationsEmail-expected.json | 2 +- .../updateNotificationsNote-expected.json} | 6 +- test/type.automation.test.js | 56 +++++++-------- test/type.query.test.js | 4 +- test/type.verification.test.js | 72 +++++++++++++++---- 15 files changed, 180 insertions(+), 49 deletions(-) create mode 100644 test/mockRoot/deploy/testInstance/testBU/verification/testExisting_verification_updateNotificationsEmail.verification-meta.json create mode 100644 test/resources/9999999/automation/v1/dataverifications/testExisting_verification_updateNotificationsEmail/patch-response.json create mode 100644 test/resources/9999999/automation/v1/dataverifications/testExisting_verification_updateNotificationsNote/get-response.json create mode 100644 test/resources/9999999/automation/v1/dataverifications/testExisting_verification_updateNotificationsNote/patch-response.json rename test/{mockRoot/deploy/testInstance/testBU/verification/testExisting_verification._updateNotificationsEmail.verification-meta.json => resources/9999999/verification/updateNotificationsNote-expected.json} (65%) diff --git a/test/mockRoot/deploy/testInstance/testBU/verification/testExisting_verification_updateNotificationsEmail.verification-meta.json b/test/mockRoot/deploy/testInstance/testBU/verification/testExisting_verification_updateNotificationsEmail.verification-meta.json new file mode 100644 index 000000000..929f3bc41 --- /dev/null +++ b/test/mockRoot/deploy/testInstance/testBU/verification/testExisting_verification_updateNotificationsEmail.verification-meta.json @@ -0,0 +1,11 @@ +{ + "dataVerificationDefinitionId": "testExisting_verification_updateNotificationsEmail", + "notificationEmailAddress": "", + "notificationEmailMessage": "", + "r__dataExtension_CustomerKey": "testExisting_dataExtension", + "shouldEmailOnFailure": true, + "shouldStopOnFailure": true, + "value1": 1, + "value2": 0, + "verificationType": "IsEqualTo" +} diff --git a/test/resources/9999999/automation/build-expected.json b/test/resources/9999999/automation/build-expected.json index d0e111d1e..d46d8e646 100644 --- a/test/resources/9999999/automation/build-expected.json +++ b/test/resources/9999999/automation/build-expected.json @@ -40,6 +40,14 @@ { "name": "testTemplated_39f6a488-20eb-4ba0-b0b9", "r__type": "verification" + }, + { + "name": "testTemplated_verification_updateNotificationsNote", + "r__type": "verification" + }, + { + "name": "testTemplated_verification_updateNotificationsEmail", + "r__type": "verification" } ], "name": "" diff --git a/test/resources/9999999/automation/retrieve-expected.json b/test/resources/9999999/automation/retrieve-expected.json index a598c8aff..361f9661a 100644 --- a/test/resources/9999999/automation/retrieve-expected.json +++ b/test/resources/9999999/automation/retrieve-expected.json @@ -40,6 +40,14 @@ { "name": "testExisting_39f6a488-20eb-4ba0-b0b9", "r__type": "verification" + }, + { + "name": "testExisting_verification_updateNotificationsNote", + "r__type": "verification" + }, + { + "name": "testExisting_verification_updateNotificationsEmail", + "r__type": "verification" } ], "name": "" diff --git a/test/resources/9999999/automation/retrieve-testExisting_automation-expected.md b/test/resources/9999999/automation/retrieve-testExisting_automation-expected.md index 161e31040..d34228f92 100644 --- a/test/resources/9999999/automation/retrieve-testExisting_automation-expected.md +++ b/test/resources/9999999/automation/retrieve-testExisting_automation-expected.md @@ -29,3 +29,5 @@ | _1.5: query_
testExisting_query | | _1.6: script_
testExisting_script | | _1.7: verification_
testExisting_39f6a488-20eb-4ba0-b0b9 | +| _1.8: verification_
testExisting_verification_updateNotificationsNote | +| _1.9: verification_
testExisting_verification_updateNotificationsEmail | diff --git a/test/resources/9999999/automation/template-expected.json b/test/resources/9999999/automation/template-expected.json index 9e3db99fc..6cbcaf6cf 100644 --- a/test/resources/9999999/automation/template-expected.json +++ b/test/resources/9999999/automation/template-expected.json @@ -40,6 +40,14 @@ { "name": "{{{prefix}}}39f6a488-20eb-4ba0-b0b9", "r__type": "verification" + }, + { + "name": "{{{prefix}}}verification_updateNotificationsNote", + "r__type": "verification" + }, + { + "name": "{{{prefix}}}verification_updateNotificationsEmail", + "r__type": "verification" } ], "name": "" diff --git a/test/resources/9999999/automation/v1/automations/08afb0e2-b00a-4c88-ad2e-1f7f8788c560/get-response.json b/test/resources/9999999/automation/v1/automations/08afb0e2-b00a-4c88-ad2e-1f7f8788c560/get-response.json index 3c982a924..cb6888112 100644 --- a/test/resources/9999999/automation/v1/automations/08afb0e2-b00a-4c88-ad2e-1f7f8788c560/get-response.json +++ b/test/resources/9999999/automation/v1/automations/08afb0e2-b00a-4c88-ad2e-1f7f8788c560/get-response.json @@ -85,6 +85,20 @@ "activityObjectId": "testExisting_39f6a488-20eb-4ba0-b0b9", "objectTypeId": 1000, "displayOrder": 7 + }, + { + "id": "f3774dc2-a271-4a44-8cbe-f630a6d6545e", + "name": "testExisting_dataExtension", + "activityObjectId": "testExisting_verification_updateNotificationsNote", + "objectTypeId": 1000, + "displayOrder": 8 + }, + { + "id": "f3774dc2-a271-4a44-8cbe-f630a6d6545e", + "name": "testExisting_dataExtension", + "activityObjectId": "testExisting_verification_updateNotificationsEmail", + "objectTypeId": 1000, + "displayOrder": 9 } ] } diff --git a/test/resources/9999999/automation/v1/dataverifications/testExisting_verification_updateNotificationsEmail/get-response.json b/test/resources/9999999/automation/v1/dataverifications/testExisting_verification_updateNotificationsEmail/get-response.json index 72889c32c..9029d133d 100644 --- a/test/resources/9999999/automation/v1/dataverifications/testExisting_verification_updateNotificationsEmail/get-response.json +++ b/test/resources/9999999/automation/v1/dataverifications/testExisting_verification_updateNotificationsEmail/get-response.json @@ -6,7 +6,7 @@ "value2": 0, "shouldStopOnFailure": true, "shouldEmailOnFailure": false, - "notificationEmailAddress": "test@test.com", + "notificationEmailAddress": "", "notificationEmailMessage": "", "createdBy": 700301950 } diff --git a/test/resources/9999999/automation/v1/dataverifications/testExisting_verification_updateNotificationsEmail/patch-response.json b/test/resources/9999999/automation/v1/dataverifications/testExisting_verification_updateNotificationsEmail/patch-response.json new file mode 100644 index 000000000..6d8370eff --- /dev/null +++ b/test/resources/9999999/automation/v1/dataverifications/testExisting_verification_updateNotificationsEmail/patch-response.json @@ -0,0 +1,12 @@ +{ + "dataVerificationDefinitionId": "testExisting_verification_updateNotificationsEmail", + "targetObjectId": "21711373-72c1-ec11-b83b-48df37d1deb7", + "verificationType": "IsEqualTo", + "value1": 1, + "value2": 0, + "shouldStopOnFailure": true, + "shouldEmailOnFailure": true, + "notificationEmailAddress": "test@test.com", + "notificationEmailMessage": "", + "createdBy": 700301950 +} diff --git a/test/resources/9999999/automation/v1/dataverifications/testExisting_verification_updateNotificationsNote/get-response.json b/test/resources/9999999/automation/v1/dataverifications/testExisting_verification_updateNotificationsNote/get-response.json new file mode 100644 index 000000000..e7ce8363e --- /dev/null +++ b/test/resources/9999999/automation/v1/dataverifications/testExisting_verification_updateNotificationsNote/get-response.json @@ -0,0 +1,12 @@ +{ + "dataVerificationDefinitionId": "testExisting_verification_updateNotificationsNote", + "targetObjectId": "21711373-72c1-ec11-b83b-48df37d1deb7", + "verificationType": "IsEqualTo", + "value1": 1, + "value2": 0, + "shouldStopOnFailure": true, + "shouldEmailOnFailure": false, + "notificationEmailAddress": "test@test.com", + "notificationEmailMessage": "", + "createdBy": 700301950 +} diff --git a/test/resources/9999999/automation/v1/dataverifications/testExisting_verification_updateNotificationsNote/patch-response.json b/test/resources/9999999/automation/v1/dataverifications/testExisting_verification_updateNotificationsNote/patch-response.json new file mode 100644 index 000000000..87a0707ef --- /dev/null +++ b/test/resources/9999999/automation/v1/dataverifications/testExisting_verification_updateNotificationsNote/patch-response.json @@ -0,0 +1,12 @@ +{ + "dataVerificationDefinitionId": "testExisting_verification_updateNotificationsNote", + "targetObjectId": "21711373-72c1-ec11-b83b-48df37d1deb7", + "verificationType": "IsEqualTo", + "value1": 1, + "value2": 0, + "shouldStopOnFailure": true, + "shouldEmailOnFailure": true, + "notificationEmailAddress": "test@test.com", + "notificationEmailMessage": "test", + "createdBy": 700301950 +} diff --git a/test/resources/9999999/verification/updateNotificationsEmail-expected.json b/test/resources/9999999/verification/updateNotificationsEmail-expected.json index 187c32884..b7e493f00 100644 --- a/test/resources/9999999/verification/updateNotificationsEmail-expected.json +++ b/test/resources/9999999/verification/updateNotificationsEmail-expected.json @@ -3,7 +3,7 @@ "notificationEmailAddress": "test@test.com", "notificationEmailMessage": "", "r__dataExtension_CustomerKey": "testExisting_dataExtension", - "shouldEmailOnFailure": false, + "shouldEmailOnFailure": true, "shouldStopOnFailure": true, "value1": 1, "value2": 0, diff --git a/test/mockRoot/deploy/testInstance/testBU/verification/testExisting_verification._updateNotificationsEmail.verification-meta.json b/test/resources/9999999/verification/updateNotificationsNote-expected.json similarity index 65% rename from test/mockRoot/deploy/testInstance/testBU/verification/testExisting_verification._updateNotificationsEmail.verification-meta.json rename to test/resources/9999999/verification/updateNotificationsNote-expected.json index 19814275c..bfbc84e94 100644 --- a/test/mockRoot/deploy/testInstance/testBU/verification/testExisting_verification._updateNotificationsEmail.verification-meta.json +++ b/test/resources/9999999/verification/updateNotificationsNote-expected.json @@ -1,7 +1,7 @@ -{ - "dataVerificationDefinitionId": "testExisting_verification._updateNotificationsEmail", +{ + "dataVerificationDefinitionId": "testExisting_verification_updateNotificationsNote", "notificationEmailAddress": "test@test.com", - "notificationEmailMessage": "", + "notificationEmailMessage": "test", "r__dataExtension_CustomerKey": "testExisting_dataExtension", "shouldEmailOnFailure": true, "shouldStopOnFailure": true, diff --git a/test/type.automation.test.js b/test/type.automation.test.js index bd5479b4f..1ccf9dbb9 100644 --- a/test/type.automation.test.js +++ b/test/type.automation.test.js @@ -49,7 +49,7 @@ describe('type: automation', () => { ); assert.equal( testUtils.getAPIHistoryLength(), - 48, + 50, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -122,7 +122,7 @@ describe('type: automation', () => { ); assert.equal( testUtils.getAPIHistoryLength(), - 40, + 42, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -191,7 +191,7 @@ describe('type: automation', () => { assert.equal( testUtils.getAPIHistoryLength(), - 48, + 50, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -259,7 +259,7 @@ describe('type: automation', () => { assert.equal( testUtils.getAPIHistoryLength(), - 44, + 46, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -295,7 +295,7 @@ describe('type: automation', () => { // check number of API calls assert.equal( testUtils.getAPIHistoryLength(), - 33, + 35, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -339,7 +339,7 @@ describe('type: automation', () => { // check number of API calls assert.equal( testUtils.getAPIHistoryLength(), - 70, + 74, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -383,7 +383,7 @@ describe('type: automation', () => { // check number of API calls assert.equal( testUtils.getAPIHistoryLength(), - 72, + 76, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -427,7 +427,7 @@ describe('type: automation', () => { // check number of API calls assert.equal( testUtils.getAPIHistoryLength(), - 73, + 77, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -467,7 +467,7 @@ describe('type: automation', () => { // check number of API calls assert.equal( testUtils.getAPIHistoryLength(), - 65, + 69, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -508,7 +508,7 @@ describe('type: automation', () => { // check number of API calls assert.equal( testUtils.getAPIHistoryLength(), - 71, + 75, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -549,7 +549,7 @@ describe('type: automation', () => { // check number of API calls assert.equal( testUtils.getAPIHistoryLength(), - 73, + 77, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -600,7 +600,7 @@ describe('type: automation', () => { ); assert.equal( testUtils.getAPIHistoryLength(), - 35, + 37, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -651,7 +651,7 @@ describe('type: automation', () => { ); assert.equal( testUtils.getAPIHistoryLength(), - 33, + 35, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -924,7 +924,7 @@ describe('type: automation', () => { ); assert.equal( testUtils.getAPIHistoryLength(), - 36, + 38, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -960,7 +960,7 @@ describe('type: automation', () => { ); assert.equal( testUtils.getAPIHistoryLength(), - 36, + 38, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -996,7 +996,7 @@ describe('type: automation', () => { ); assert.equal( testUtils.getAPIHistoryLength(), - 36, + 38, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -1032,7 +1032,7 @@ describe('type: automation', () => { ); assert.equal( testUtils.getAPIHistoryLength(), - 36, + 38, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -1068,7 +1068,7 @@ describe('type: automation', () => { ); assert.equal( testUtils.getAPIHistoryLength(), - 36, + 38, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -1110,7 +1110,7 @@ describe('type: automation', () => { ); assert.equal( testUtils.getAPIHistoryLength(), - 36, + 38, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -1150,7 +1150,7 @@ describe('type: automation', () => { ); assert.equal( testUtils.getAPIHistoryLength(), - 36, + 38, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -1190,7 +1190,7 @@ describe('type: automation', () => { ); assert.equal( testUtils.getAPIHistoryLength(), - 36, + 38, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -1232,7 +1232,7 @@ describe('type: automation', () => { ); assert.equal( testUtils.getAPIHistoryLength(), - 36, + 38, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -1270,7 +1270,7 @@ describe('type: automation', () => { ); assert.equal( testUtils.getAPIHistoryLength(), - 36, + 38, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -1306,7 +1306,7 @@ describe('type: automation', () => { ); assert.equal( testUtils.getAPIHistoryLength(), - 36, + 38, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -1396,7 +1396,7 @@ describe('type: automation', () => { assert.equal( testUtils.getAPIHistoryLength(), - 36, + 38, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -1432,7 +1432,7 @@ describe('type: automation', () => { ); assert.equal( testUtils.getAPIHistoryLength(), - 36, + 38, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -1468,7 +1468,7 @@ describe('type: automation', () => { ); assert.equal( testUtils.getAPIHistoryLength(), - 36, + 38, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -1500,7 +1500,7 @@ describe('type: automation', () => { ); assert.equal( testUtils.getAPIHistoryLength(), - 36, + 38, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; diff --git a/test/type.query.test.js b/test/type.query.test.js index 31fe795c3..276e15ba1 100644 --- a/test/type.query.test.js +++ b/test/type.query.test.js @@ -458,7 +458,7 @@ describe('type: query', () => { // check number of API calls assert.equal( testUtils.getAPIHistoryLength(), - 64, + 66, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -498,7 +498,7 @@ describe('type: query', () => { // check number of API calls assert.equal( testUtils.getAPIHistoryLength(), - 66, + 68, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; diff --git a/test/type.verification.test.js b/test/type.verification.test.js index 8be84b735..5b3a4537a 100644 --- a/test/type.verification.test.js +++ b/test/type.verification.test.js @@ -24,15 +24,15 @@ describe('type: verification', () => { const result = cache.getCache(); assert.equal( result.verification ? Object.keys(result.verification).length : 0, - 1, - 'only one verification expected' + 3, + 'only 3 verifications expected' ); assert.equal( retrieved['testInstance/testBU']?.verification ? Object.keys(retrieved['testInstance/testBU']?.verification).length : 0, - 1, - 'one verifications to be retrieved' + 3, + '3 verifications to be retrieved' ); assert.deepEqual( @@ -45,7 +45,7 @@ describe('type: verification', () => { ); assert.equal( testUtils.getAPIHistoryLength(), - 24, + 26, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -65,15 +65,15 @@ describe('type: verification', () => { const result = cache.getCache(); assert.equal( result.verification ? Object.keys(result.verification).length : 0, - 2, - 'two verifications expected' + 4, + '4 verifications expected' ); assert.equal( deployed['testInstance/testBU']?.verification ? Object.keys(deployed['testInstance/testBU']?.verification).length : 0, - 2, - 'two verifications to be deployed' + 3, + '3 verifications to be deployed' ); // confirm created item assert.deepEqual( @@ -93,7 +93,7 @@ describe('type: verification', () => { // check number of API calls assert.equal( testUtils.getAPIHistoryLength(), - 26, + 29, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -146,7 +146,7 @@ describe('type: verification', () => { ); assert.equal( testUtils.getAPIHistoryLength(), - 24, + 26, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -171,6 +171,9 @@ describe('type: verification', () => { }); }); describe('UpdateNotifications ================', () => { + beforeEach(() => { + testUtils.mockSetup(true); + }); it('Should update notification email', async () => { handler.setOptions({ completionEmail: 'test@test.com' }); // WHEN @@ -185,8 +188,8 @@ describe('type: verification', () => { const result = cache.getCache(); assert.equal( result.verification ? Object.keys(result.verification).length : 0, - 2, - 'only two verifications expected' + 3, + 'only one verification expected' ); assert.equal( updatedNotifications['testInstance/testBU'].length, @@ -203,11 +206,52 @@ describe('type: verification', () => { 'verification', 'updateNotificationsEmail' ), + 'returned metadata was not equal expected for update query' + ); + assert.equal( + testUtils.getAPIHistoryLength(), + 31, + 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' + ); + return; + }); + it('Should update notification note', async () => { + handler.setOptions({ completionNote: 'test' }); + // WHEN + const updatedNotifications = await handler.updateNotifications( + 'testInstance/testBU', + 'verification', + ['testExisting_verification_updateNotificationsNote'] + ); + // THEN + assert.equal(process.exitCode, false, 'retrieve should not have thrown an error'); + // get results from cache + const result = cache.getCache(); + assert.equal( + result.verification ? Object.keys(result.verification).length : 0, + 3, + 'only 3 verifications expected' + ); + assert.equal( + updatedNotifications['testInstance/testBU'].length, + 1, + 'one automation key expected' + ); + assert.deepEqual( + await testUtils.getActualJson( + 'testExisting_verification_updateNotificationsNote', + 'verification' + ), + await testUtils.getExpectedJson( + '9999999', + 'verification', + 'updateNotificationsNote' + ), 'returned JSON was not equal expected' ); assert.equal( testUtils.getAPIHistoryLength(), - 29, + 31, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; From 3c82b21830dd6b77660097fc777260ea9b549b76 Mon Sep 17 00:00:00 2001 From: Yuliia Likhytska Date: Fri, 8 Sep 2023 22:05:39 +0200 Subject: [PATCH 4/7] #1084: additional tests for verification --- .../9999999/automation/build-expected.json | 12 ++ .../9999999/automation/retrieve-expected.json | 12 ++ ...trieve-testExisting_automation-expected.md | 3 + .../9999999/automation/template-expected.json | 12 ++ .../get-response.json | 21 +++ .../get-response.json | 12 ++ .../patch-response.json | 12 ++ .../get-response.json | 12 ++ .../patch-response.json | 12 ++ .../get-response.json | 12 ++ .../patch-response.json | 12 ++ .../NOTupdateNotificationsEmail-expected.json | 11 ++ .../9999999/verification/clear-expected.json} | 4 +- test/type.automation.test.js | 56 +++---- test/type.query.test.js | 4 +- test/type.verification.test.js | 138 +++++++++++++++--- 16 files changed, 296 insertions(+), 49 deletions(-) create mode 100644 test/resources/9999999/automation/v1/dataverifications/testExisting_verification_NOTupdateNotificationsEmail/get-response.json create mode 100644 test/resources/9999999/automation/v1/dataverifications/testExisting_verification_NOTupdateNotificationsEmail/patch-response.json create mode 100644 test/resources/9999999/automation/v1/dataverifications/testExisting_verification_NOTupdateNotificationsNote/get-response.json create mode 100644 test/resources/9999999/automation/v1/dataverifications/testExisting_verification_NOTupdateNotificationsNote/patch-response.json create mode 100644 test/resources/9999999/automation/v1/dataverifications/testExisting_verification_clear/get-response.json create mode 100644 test/resources/9999999/automation/v1/dataverifications/testExisting_verification_clear/patch-response.json create mode 100644 test/resources/9999999/verification/NOTupdateNotificationsEmail-expected.json rename test/{mockRoot/deploy/testInstance/testBU/verification/testExisting_verification_updateNotificationsEmail.verification-meta.json => resources/9999999/verification/clear-expected.json} (75%) diff --git a/test/resources/9999999/automation/build-expected.json b/test/resources/9999999/automation/build-expected.json index d46d8e646..ce762f784 100644 --- a/test/resources/9999999/automation/build-expected.json +++ b/test/resources/9999999/automation/build-expected.json @@ -48,6 +48,18 @@ { "name": "testTemplated_verification_updateNotificationsEmail", "r__type": "verification" + }, + { + "name": "testTemplated_verification_NOTupdateNotificationsEmail", + "r__type": "verification" + }, + { + "name": "testTemplated_verification_NOTupdateNotificationsNote", + "r__type": "verification" + }, + { + "name": "testTemplated_verification_clear", + "r__type": "verification" } ], "name": "" diff --git a/test/resources/9999999/automation/retrieve-expected.json b/test/resources/9999999/automation/retrieve-expected.json index 361f9661a..6f66533b3 100644 --- a/test/resources/9999999/automation/retrieve-expected.json +++ b/test/resources/9999999/automation/retrieve-expected.json @@ -48,6 +48,18 @@ { "name": "testExisting_verification_updateNotificationsEmail", "r__type": "verification" + }, + { + "name": "testExisting_verification_NOTupdateNotificationsEmail", + "r__type": "verification" + }, + { + "name": "testExisting_verification_NOTupdateNotificationsNote", + "r__type": "verification" + }, + { + "name": "testExisting_verification_clear", + "r__type": "verification" } ], "name": "" diff --git a/test/resources/9999999/automation/retrieve-testExisting_automation-expected.md b/test/resources/9999999/automation/retrieve-testExisting_automation-expected.md index d34228f92..67a8afb07 100644 --- a/test/resources/9999999/automation/retrieve-testExisting_automation-expected.md +++ b/test/resources/9999999/automation/retrieve-testExisting_automation-expected.md @@ -31,3 +31,6 @@ | _1.7: verification_
testExisting_39f6a488-20eb-4ba0-b0b9 | | _1.8: verification_
testExisting_verification_updateNotificationsNote | | _1.9: verification_
testExisting_verification_updateNotificationsEmail | +| _1.10: verification_
testExisting_verification_NOTupdateNotificationsEmail | +| _1.11: verification_
testExisting_verification_NOTupdateNotificationsNote | +| _1.12: verification_
testExisting_verification_clear | diff --git a/test/resources/9999999/automation/template-expected.json b/test/resources/9999999/automation/template-expected.json index 6cbcaf6cf..5928fb1d8 100644 --- a/test/resources/9999999/automation/template-expected.json +++ b/test/resources/9999999/automation/template-expected.json @@ -48,6 +48,18 @@ { "name": "{{{prefix}}}verification_updateNotificationsEmail", "r__type": "verification" + }, + { + "name": "{{{prefix}}}verification_NOTupdateNotificationsEmail", + "r__type": "verification" + }, + { + "name": "{{{prefix}}}verification_NOTupdateNotificationsNote", + "r__type": "verification" + }, + { + "name": "{{{prefix}}}verification_clear", + "r__type": "verification" } ], "name": "" diff --git a/test/resources/9999999/automation/v1/automations/08afb0e2-b00a-4c88-ad2e-1f7f8788c560/get-response.json b/test/resources/9999999/automation/v1/automations/08afb0e2-b00a-4c88-ad2e-1f7f8788c560/get-response.json index cb6888112..c147cd7e0 100644 --- a/test/resources/9999999/automation/v1/automations/08afb0e2-b00a-4c88-ad2e-1f7f8788c560/get-response.json +++ b/test/resources/9999999/automation/v1/automations/08afb0e2-b00a-4c88-ad2e-1f7f8788c560/get-response.json @@ -99,6 +99,27 @@ "activityObjectId": "testExisting_verification_updateNotificationsEmail", "objectTypeId": 1000, "displayOrder": 9 + }, + { + "id": "f3774dc2-a271-4a44-8cbe-f630a6d6545e", + "name": "testExisting_dataExtension", + "activityObjectId": "testExisting_verification_NOTupdateNotificationsEmail", + "objectTypeId": 1000, + "displayOrder": 10 + }, + { + "id": "f3774dc2-a271-4a44-8cbe-f630a6d6545e", + "name": "testExisting_dataExtension", + "activityObjectId": "testExisting_verification_NOTupdateNotificationsNote", + "objectTypeId": 1000, + "displayOrder": 11 + }, + { + "id": "f3774dc2-a271-4a44-8cbe-f630a6d6545e", + "name": "testExisting_dataExtension", + "activityObjectId": "testExisting_verification_clear", + "objectTypeId": 1000, + "displayOrder": 12 } ] } diff --git a/test/resources/9999999/automation/v1/dataverifications/testExisting_verification_NOTupdateNotificationsEmail/get-response.json b/test/resources/9999999/automation/v1/dataverifications/testExisting_verification_NOTupdateNotificationsEmail/get-response.json new file mode 100644 index 000000000..356fe53f5 --- /dev/null +++ b/test/resources/9999999/automation/v1/dataverifications/testExisting_verification_NOTupdateNotificationsEmail/get-response.json @@ -0,0 +1,12 @@ +{ + "dataVerificationDefinitionId": "testExisting_verification_NOTupdateNotificationsEmail", + "targetObjectId": "21711373-72c1-ec11-b83b-48df37d1deb7", + "verificationType": "IsEqualTo", + "value1": 1, + "value2": 0, + "shouldStopOnFailure": true, + "shouldEmailOnFailure": false, + "notificationEmailAddress": "", + "notificationEmailMessage": "", + "createdBy": 700301950 +} diff --git a/test/resources/9999999/automation/v1/dataverifications/testExisting_verification_NOTupdateNotificationsEmail/patch-response.json b/test/resources/9999999/automation/v1/dataverifications/testExisting_verification_NOTupdateNotificationsEmail/patch-response.json new file mode 100644 index 000000000..356fe53f5 --- /dev/null +++ b/test/resources/9999999/automation/v1/dataverifications/testExisting_verification_NOTupdateNotificationsEmail/patch-response.json @@ -0,0 +1,12 @@ +{ + "dataVerificationDefinitionId": "testExisting_verification_NOTupdateNotificationsEmail", + "targetObjectId": "21711373-72c1-ec11-b83b-48df37d1deb7", + "verificationType": "IsEqualTo", + "value1": 1, + "value2": 0, + "shouldStopOnFailure": true, + "shouldEmailOnFailure": false, + "notificationEmailAddress": "", + "notificationEmailMessage": "", + "createdBy": 700301950 +} diff --git a/test/resources/9999999/automation/v1/dataverifications/testExisting_verification_NOTupdateNotificationsNote/get-response.json b/test/resources/9999999/automation/v1/dataverifications/testExisting_verification_NOTupdateNotificationsNote/get-response.json new file mode 100644 index 000000000..a2f87058c --- /dev/null +++ b/test/resources/9999999/automation/v1/dataverifications/testExisting_verification_NOTupdateNotificationsNote/get-response.json @@ -0,0 +1,12 @@ +{ + "dataVerificationDefinitionId": "testExisting_verification_NOTupdateNotificationsNote", + "targetObjectId": "21711373-72c1-ec11-b83b-48df37d1deb7", + "verificationType": "IsEqualTo", + "value1": 1, + "value2": 0, + "shouldStopOnFailure": true, + "shouldEmailOnFailure": false, + "notificationEmailAddress": "test@test.com", + "notificationEmailMessage": "test", + "createdBy": 700301950 +} diff --git a/test/resources/9999999/automation/v1/dataverifications/testExisting_verification_NOTupdateNotificationsNote/patch-response.json b/test/resources/9999999/automation/v1/dataverifications/testExisting_verification_NOTupdateNotificationsNote/patch-response.json new file mode 100644 index 000000000..d57a61a13 --- /dev/null +++ b/test/resources/9999999/automation/v1/dataverifications/testExisting_verification_NOTupdateNotificationsNote/patch-response.json @@ -0,0 +1,12 @@ +{ + "dataVerificationDefinitionId": "testExisting_verification_NOTupdateNotificationsEmail", + "targetObjectId": "21711373-72c1-ec11-b83b-48df37d1deb7", + "verificationType": "IsEqualTo", + "value1": 1, + "value2": 0, + "shouldStopOnFailure": true, + "shouldEmailOnFailure": false, + "notificationEmailAddress": "test@test.com", + "notificationEmailMessage": "test", + "createdBy": 700301950 +} diff --git a/test/resources/9999999/automation/v1/dataverifications/testExisting_verification_clear/get-response.json b/test/resources/9999999/automation/v1/dataverifications/testExisting_verification_clear/get-response.json new file mode 100644 index 000000000..18e4fa385 --- /dev/null +++ b/test/resources/9999999/automation/v1/dataverifications/testExisting_verification_clear/get-response.json @@ -0,0 +1,12 @@ +{ + "dataVerificationDefinitionId": "testExisting_verification_clear", + "targetObjectId": "21711373-72c1-ec11-b83b-48df37d1deb7", + "verificationType": "IsEqualTo", + "value1": 1, + "value2": 0, + "shouldStopOnFailure": true, + "shouldEmailOnFailure": false, + "notificationEmailAddress": "test@test.com", + "notificationEmailMessage": "test", + "createdBy": 700301950 +} diff --git a/test/resources/9999999/automation/v1/dataverifications/testExisting_verification_clear/patch-response.json b/test/resources/9999999/automation/v1/dataverifications/testExisting_verification_clear/patch-response.json new file mode 100644 index 000000000..611c8b15b --- /dev/null +++ b/test/resources/9999999/automation/v1/dataverifications/testExisting_verification_clear/patch-response.json @@ -0,0 +1,12 @@ +{ + "dataVerificationDefinitionId": "testExisting_verification_clear", + "targetObjectId": "21711373-72c1-ec11-b83b-48df37d1deb7", + "verificationType": "IsEqualTo", + "value1": 1, + "value2": 0, + "shouldStopOnFailure": true, + "shouldEmailOnFailure": true, + "notificationEmailAddress": "", + "notificationEmailMessage": "", + "createdBy": 700301950 +} diff --git a/test/resources/9999999/verification/NOTupdateNotificationsEmail-expected.json b/test/resources/9999999/verification/NOTupdateNotificationsEmail-expected.json new file mode 100644 index 000000000..40003bb8a --- /dev/null +++ b/test/resources/9999999/verification/NOTupdateNotificationsEmail-expected.json @@ -0,0 +1,11 @@ +{ + "dataVerificationDefinitionId": "testExisting_verification_NOTupdateNotificationsEmail", + "notificationEmailAddress": "", + "notificationEmailMessage": "", + "r__dataExtension_CustomerKey": "testExisting_dataExtension", + "shouldEmailOnFailure": false, + "shouldStopOnFailure": true, + "value1": 1, + "value2": 0, + "verificationType": "IsEqualTo" +} diff --git a/test/mockRoot/deploy/testInstance/testBU/verification/testExisting_verification_updateNotificationsEmail.verification-meta.json b/test/resources/9999999/verification/clear-expected.json similarity index 75% rename from test/mockRoot/deploy/testInstance/testBU/verification/testExisting_verification_updateNotificationsEmail.verification-meta.json rename to test/resources/9999999/verification/clear-expected.json index 929f3bc41..f587fba89 100644 --- a/test/mockRoot/deploy/testInstance/testBU/verification/testExisting_verification_updateNotificationsEmail.verification-meta.json +++ b/test/resources/9999999/verification/clear-expected.json @@ -1,5 +1,5 @@ -{ - "dataVerificationDefinitionId": "testExisting_verification_updateNotificationsEmail", +{ + "dataVerificationDefinitionId": "testExisting_verification_clear", "notificationEmailAddress": "", "notificationEmailMessage": "", "r__dataExtension_CustomerKey": "testExisting_dataExtension", diff --git a/test/type.automation.test.js b/test/type.automation.test.js index 1ccf9dbb9..37c148ec8 100644 --- a/test/type.automation.test.js +++ b/test/type.automation.test.js @@ -49,7 +49,7 @@ describe('type: automation', () => { ); assert.equal( testUtils.getAPIHistoryLength(), - 50, + 53, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -122,7 +122,7 @@ describe('type: automation', () => { ); assert.equal( testUtils.getAPIHistoryLength(), - 42, + 45, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -191,7 +191,7 @@ describe('type: automation', () => { assert.equal( testUtils.getAPIHistoryLength(), - 50, + 53, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -259,7 +259,7 @@ describe('type: automation', () => { assert.equal( testUtils.getAPIHistoryLength(), - 46, + 49, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -295,7 +295,7 @@ describe('type: automation', () => { // check number of API calls assert.equal( testUtils.getAPIHistoryLength(), - 35, + 41, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -339,7 +339,7 @@ describe('type: automation', () => { // check number of API calls assert.equal( testUtils.getAPIHistoryLength(), - 74, + 80, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -383,7 +383,7 @@ describe('type: automation', () => { // check number of API calls assert.equal( testUtils.getAPIHistoryLength(), - 76, + 82, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -427,7 +427,7 @@ describe('type: automation', () => { // check number of API calls assert.equal( testUtils.getAPIHistoryLength(), - 77, + 83, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -467,7 +467,7 @@ describe('type: automation', () => { // check number of API calls assert.equal( testUtils.getAPIHistoryLength(), - 69, + 75, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -508,7 +508,7 @@ describe('type: automation', () => { // check number of API calls assert.equal( testUtils.getAPIHistoryLength(), - 75, + 81, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -549,7 +549,7 @@ describe('type: automation', () => { // check number of API calls assert.equal( testUtils.getAPIHistoryLength(), - 77, + 83, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -600,7 +600,7 @@ describe('type: automation', () => { ); assert.equal( testUtils.getAPIHistoryLength(), - 37, + 40, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -651,7 +651,7 @@ describe('type: automation', () => { ); assert.equal( testUtils.getAPIHistoryLength(), - 35, + 41, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -924,7 +924,7 @@ describe('type: automation', () => { ); assert.equal( testUtils.getAPIHistoryLength(), - 38, + 41, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -960,7 +960,7 @@ describe('type: automation', () => { ); assert.equal( testUtils.getAPIHistoryLength(), - 38, + 41, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -996,7 +996,7 @@ describe('type: automation', () => { ); assert.equal( testUtils.getAPIHistoryLength(), - 38, + 41, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -1032,7 +1032,7 @@ describe('type: automation', () => { ); assert.equal( testUtils.getAPIHistoryLength(), - 38, + 41, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -1068,7 +1068,7 @@ describe('type: automation', () => { ); assert.equal( testUtils.getAPIHistoryLength(), - 38, + 41, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -1110,7 +1110,7 @@ describe('type: automation', () => { ); assert.equal( testUtils.getAPIHistoryLength(), - 38, + 41, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -1150,7 +1150,7 @@ describe('type: automation', () => { ); assert.equal( testUtils.getAPIHistoryLength(), - 38, + 41, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -1190,7 +1190,7 @@ describe('type: automation', () => { ); assert.equal( testUtils.getAPIHistoryLength(), - 38, + 41, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -1232,7 +1232,7 @@ describe('type: automation', () => { ); assert.equal( testUtils.getAPIHistoryLength(), - 38, + 41, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -1270,7 +1270,7 @@ describe('type: automation', () => { ); assert.equal( testUtils.getAPIHistoryLength(), - 38, + 41, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -1306,7 +1306,7 @@ describe('type: automation', () => { ); assert.equal( testUtils.getAPIHistoryLength(), - 38, + 41, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -1396,7 +1396,7 @@ describe('type: automation', () => { assert.equal( testUtils.getAPIHistoryLength(), - 38, + 41, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -1432,7 +1432,7 @@ describe('type: automation', () => { ); assert.equal( testUtils.getAPIHistoryLength(), - 38, + 41, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -1468,7 +1468,7 @@ describe('type: automation', () => { ); assert.equal( testUtils.getAPIHistoryLength(), - 38, + 41, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -1500,7 +1500,7 @@ describe('type: automation', () => { ); assert.equal( testUtils.getAPIHistoryLength(), - 38, + 41, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; diff --git a/test/type.query.test.js b/test/type.query.test.js index 276e15ba1..a96d47a21 100644 --- a/test/type.query.test.js +++ b/test/type.query.test.js @@ -458,7 +458,7 @@ describe('type: query', () => { // check number of API calls assert.equal( testUtils.getAPIHistoryLength(), - 66, + 69, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -498,7 +498,7 @@ describe('type: query', () => { // check number of API calls assert.equal( testUtils.getAPIHistoryLength(), - 68, + 71, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; diff --git a/test/type.verification.test.js b/test/type.verification.test.js index 5b3a4537a..2d0dc4d58 100644 --- a/test/type.verification.test.js +++ b/test/type.verification.test.js @@ -24,15 +24,15 @@ describe('type: verification', () => { const result = cache.getCache(); assert.equal( result.verification ? Object.keys(result.verification).length : 0, - 3, - 'only 3 verifications expected' + 6, + 'only 6 verifications expected' ); assert.equal( retrieved['testInstance/testBU']?.verification ? Object.keys(retrieved['testInstance/testBU']?.verification).length : 0, - 3, - '3 verifications to be retrieved' + 6, + '6 verifications to be retrieved' ); assert.deepEqual( @@ -45,7 +45,7 @@ describe('type: verification', () => { ); assert.equal( testUtils.getAPIHistoryLength(), - 26, + 29, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -65,15 +65,15 @@ describe('type: verification', () => { const result = cache.getCache(); assert.equal( result.verification ? Object.keys(result.verification).length : 0, - 4, - '4 verifications expected' + 7, + '7 verifications expected' ); assert.equal( deployed['testInstance/testBU']?.verification ? Object.keys(deployed['testInstance/testBU']?.verification).length : 0, - 3, - '3 verifications to be deployed' + 2, + '2 verifications to be deployed' ); // confirm created item assert.deepEqual( @@ -93,7 +93,7 @@ describe('type: verification', () => { // check number of API calls assert.equal( testUtils.getAPIHistoryLength(), - 29, + 31, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -146,7 +146,7 @@ describe('type: verification', () => { ); assert.equal( testUtils.getAPIHistoryLength(), - 26, + 29, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -188,8 +188,8 @@ describe('type: verification', () => { const result = cache.getCache(); assert.equal( result.verification ? Object.keys(result.verification).length : 0, - 3, - 'only one verification expected' + 6, + 'only 6 verification expected' ); assert.equal( updatedNotifications['testInstance/testBU'].length, @@ -210,7 +210,7 @@ describe('type: verification', () => { ); assert.equal( testUtils.getAPIHistoryLength(), - 31, + 34, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -229,8 +229,8 @@ describe('type: verification', () => { const result = cache.getCache(); assert.equal( result.verification ? Object.keys(result.verification).length : 0, - 3, - 'only 3 verifications expected' + 6, + 'only 6 verifications expected' ); assert.equal( updatedNotifications['testInstance/testBU'].length, @@ -251,7 +251,111 @@ describe('type: verification', () => { ); assert.equal( testUtils.getAPIHistoryLength(), - 31, + 34, + 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' + ); + return; + }); + it('Should NOT update notification email', async () => { + handler.setOptions({ completionEmail: 'notAnEmail' }); + // WHEN + const updatedNotifications = await handler.updateNotifications( + 'testInstance/testBU', + 'verification', + ['testExisting_verification_NOTupdateNotificationsEmail'] + ); + // THEN + assert.equal(process.exitCode, false, 'retrieve should not have thrown an error'); + // get results from cache + const result = cache.getCache(); + assert.equal( + result.verification ? Object.keys(result.verification).length : 0, + 6, + 'only 6 verification expected' + ); + assert.equal( + updatedNotifications['testInstance/testBU'].length, + 1, + 'one automation key expected' + ); + assert.deepEqual( + await testUtils.getActualJson( + 'testExisting_verification_NOTupdateNotificationsEmail', + 'verification' + ), + await testUtils.getExpectedJson( + '9999999', + 'verification', + 'NOTupdateNotificationsEmail' + ), + 'returned metadata was not equal expected for update query' + ); + assert.equal( + testUtils.getAPIHistoryLength(), + 34, + 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' + ); + return; + }); + it('Should NOT update notification note', async () => { + handler.setOptions({ completionNote: 'test' }); + // WHEN + const updatedNotifications = await handler.updateNotifications( + 'testInstance/testBU', + 'verification', + ['testExisting_verification_NOTupdateNotificationsNote'] + ); + // THEN + assert.equal(process.exitCode, false, 'retrieve should not have thrown an error'); + // get results from cache + const result = cache.getCache(); + assert.equal( + result.verification ? Object.keys(result.verification).length : 0, + 1, + 'only 1 verifications expected' + ); + assert.equal( + updatedNotifications['testInstance/testBU'].length, + 0, + '0 automation key expected' + ); + assert.equal( + testUtils.getAPIHistoryLength(), + 4, + 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' + ); + return; + }); + it('Should clear notifications', async () => { + handler.setOptions({ clear: 'true' }); + // WHEN + const updatedNotifications = await handler.updateNotifications( + 'testInstance/testBU', + 'verification', + ['testExisting_verification_clear'] + ); + // THEN + assert.equal(process.exitCode, false, 'retrieve should not have thrown an error'); + // get results from cache + const result = cache.getCache(); + assert.equal( + result.verification ? Object.keys(result.verification).length : 0, + 6, + 'only 6 verifications expected' + ); + assert.equal( + updatedNotifications['testInstance/testBU'].length, + 1, + '1 automation key expected' + ); + assert.deepEqual( + await testUtils.getActualJson('testExisting_verification_clear', 'verification'), + await testUtils.getExpectedJson('9999999', 'verification', 'clear'), + 'returned metadata was not equal expected for update query' + ); + assert.equal( + testUtils.getAPIHistoryLength(), + 34, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; From 9f23d8e87878bf6f2c585bbe33c8c9b4ec56c1d6 Mon Sep 17 00:00:00 2001 From: Yuliia Likhytska Date: Fri, 8 Sep 2023 22:21:19 +0200 Subject: [PATCH 5/7] #1084: fix tests --- test/type.automation.test.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/type.automation.test.js b/test/type.automation.test.js index 37c148ec8..c21830bf5 100644 --- a/test/type.automation.test.js +++ b/test/type.automation.test.js @@ -295,7 +295,7 @@ describe('type: automation', () => { // check number of API calls assert.equal( testUtils.getAPIHistoryLength(), - 41, + 38, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; @@ -651,7 +651,7 @@ describe('type: automation', () => { ); assert.equal( testUtils.getAPIHistoryLength(), - 41, + 38, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return; From 4ee25358b9a30df27896cd0816702a1cfd293345 Mon Sep 17 00:00:00 2001 From: Yuliia Likhytska Date: Sun, 10 Sep 2023 21:24:34 +0200 Subject: [PATCH 6/7] #1084: allow executing the function without keys or --like --- lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index 2b5c0c660..b348cdb6d 100644 --- a/lib/index.js +++ b/lib/index.js @@ -835,7 +835,7 @@ class Mcdev { case 'updateNotifications': { lang_past = 'updated notifications for'; lang_present = 'updating notifications for'; - requireKeyOrLike = true; + requireKeyOrLike = false; checkMetadataSupport = false; break; } From 354adc562c2fab655f5b9ac65ba7ec2386e49e81 Mon Sep 17 00:00:00 2001 From: Yuliia Likhytska Date: Sun, 10 Sep 2023 21:26:17 +0200 Subject: [PATCH 7/7] #1084: set shouldEmailOnFailure property --- lib/metadataTypes/Verification.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/metadataTypes/Verification.js b/lib/metadataTypes/Verification.js index c66243dad..7014a5006 100644 --- a/lib/metadataTypes/Verification.js +++ b/lib/metadataTypes/Verification.js @@ -315,9 +315,11 @@ class Verification extends MetadataType { if (Util.OPTIONS.clear) { metadataMap[metadataKey].notificationEmailAddress = ''; metadataMap[metadataKey].notificationEmailMessage = ''; + metadataMap[metadataKey].shouldEmailOnFailure = false; } if (Util.OPTIONS.completionEmail) { metadataMap[metadataKey].notificationEmailAddress = Util.OPTIONS.completionEmail; + metadataMap[metadataKey].shouldEmailOnFailure = true; } if (Util.OPTIONS.completionNote) { metadataMap[metadataKey].notificationEmailMessage = Util.OPTIONS.completionNote;