From 1a098bd4917d0eb3297b46ace17a59c9717f46ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Berkefeld?= Date: Tue, 7 Jan 2025 14:54:17 +0100 Subject: [PATCH] #1856: ensure upserted senderProfiles are saved with CreatedDate, ModifiedDate, createdBy and modifiedBy --- @types/lib/metadataTypes/SenderProfile.d.ts | 7 +++++++ .../lib/metadataTypes/SenderProfile.d.ts.map | 2 +- lib/metadataTypes/SenderProfile.js | 20 +++++++++++++++++++ test/general.test.js | 10 +++++----- .../9999999/senderProfile/patch-expected.json | 20 +++++++++++-------- test/type.senderProfile.test.js | 2 +- 6 files changed, 46 insertions(+), 15 deletions(-) diff --git a/@types/lib/metadataTypes/SenderProfile.d.ts b/@types/lib/metadataTypes/SenderProfile.d.ts index 2eea3588d..0d093840a 100644 --- a/@types/lib/metadataTypes/SenderProfile.d.ts +++ b/@types/lib/metadataTypes/SenderProfile.d.ts @@ -65,6 +65,13 @@ declare class SenderProfile extends MetadataType { * @returns {Promise.} Promise */ static preDeployTasks(metadata: MetadataTypeItem): Promise; + /** + * Gets executed after deployment of metadata type + * + * @param {MetadataTypeMap} upsertResults metadata mapped by their keyField as returned by update/create + * @returns {Promise.} - + */ + static postDeployTasks(upsertResults: MetadataTypeMap): Promise; } declare namespace SenderProfile { let definition: { diff --git a/@types/lib/metadataTypes/SenderProfile.d.ts.map b/@types/lib/metadataTypes/SenderProfile.d.ts.map index 2485f02ad..e14d10af8 100644 --- a/@types/lib/metadataTypes/SenderProfile.d.ts.map +++ b/@types/lib/metadataTypes/SenderProfile.d.ts.map @@ -1 +1 @@ -{"version":3,"file":"SenderProfile.d.ts","sourceRoot":"","sources":["../../../lib/metadataTypes/SenderProfile.js"],"names":[],"mappings":";uBAQa,OAAO,wBAAwB,EAAE,QAAQ;0BACzC,OAAO,wBAAwB,EAAE,WAAW;8BAC5C,OAAO,wBAAwB,EAAE,eAAe;+BAChD,OAAO,wBAAwB,EAAE,gBAAgB;mCACjD,OAAO,wBAAwB,EAAE,oBAAoB;kCACrD,OAAO,wBAAwB,EAAE,mBAAmB;8BACpD,OAAO,wBAAwB,EAAE,eAAe;iCAChD,OAAO,wBAAwB,EAAE,kBAAkB;gCACnD,OAAO,wBAAwB,EAAE,iBAAiB;0BAClD,OAAO,wBAAwB,EAAE,WAAW;AAVzD;;;;;;;;;;;GAWG;AAEH;;;;GAIG;AACH;IACI;;;;;;;;OAQG;IACH,8BANW,MAAM,MACN,IAAI,GAAG,MAAM,EAAE,OACf,IAAI,GAAG,MAAM,EAAE,QACf,MAAM,GACJ,OAAO,CAAE,kBAAkB,CAAC,CAexC;IAED;;;;;OAKG;IACH,4BAHW,gBAAgB,gBAK1B;IAED;;;;;OAKG;IACH,4BAHW,gBAAgB,gBAK1B;IAYD;;;;;OAKG;IACH,mCAHW,gBAAgB,GACd,gBAAgB,CAsC5B;IAED;;;;;OAKG;IACH,gCAHW,gBAAgB,GACd,OAAO,CAAE,gBAAgB,CAAC,CAkCtC;CA+EJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yBA/OwB,mBAAmB"} \ No newline at end of file +{"version":3,"file":"SenderProfile.d.ts","sourceRoot":"","sources":["../../../lib/metadataTypes/SenderProfile.js"],"names":[],"mappings":";uBAQa,OAAO,wBAAwB,EAAE,QAAQ;0BACzC,OAAO,wBAAwB,EAAE,WAAW;8BAC5C,OAAO,wBAAwB,EAAE,eAAe;+BAChD,OAAO,wBAAwB,EAAE,gBAAgB;mCACjD,OAAO,wBAAwB,EAAE,oBAAoB;kCACrD,OAAO,wBAAwB,EAAE,mBAAmB;8BACpD,OAAO,wBAAwB,EAAE,eAAe;iCAChD,OAAO,wBAAwB,EAAE,kBAAkB;gCACnD,OAAO,wBAAwB,EAAE,iBAAiB;0BAClD,OAAO,wBAAwB,EAAE,WAAW;AAVzD;;;;;;;;;;;GAWG;AAEH;;;;GAIG;AACH;IACI;;;;;;;;OAQG;IACH,8BANW,MAAM,MACN,IAAI,GAAG,MAAM,EAAE,OACf,IAAI,GAAG,MAAM,EAAE,QACf,MAAM,GACJ,OAAO,CAAE,kBAAkB,CAAC,CAexC;IAED;;;;;OAKG;IACH,4BAHW,gBAAgB,gBAK1B;IAED;;;;;OAKG;IACH,4BAHW,gBAAgB,gBAK1B;IAYD;;;;;OAKG;IACH,mCAHW,gBAAgB,GACd,gBAAgB,CAsC5B;IAED;;;;;OAKG;IACH,gCAHW,gBAAgB,GACd,OAAO,CAAE,gBAAgB,CAAC,CAkCtC;IAED;;;;;OAKG;IACH,sCAHW,eAAe,GACb,OAAO,CAAE,IAAI,CAAC,CAc1B;CA+EJ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;yBAnQwB,mBAAmB"} \ No newline at end of file diff --git a/lib/metadataTypes/SenderProfile.js b/lib/metadataTypes/SenderProfile.js index 6b9a49b4b..9b0585eaa 100644 --- a/lib/metadataTypes/SenderProfile.js +++ b/lib/metadataTypes/SenderProfile.js @@ -162,6 +162,26 @@ class SenderProfile extends MetadataType { return metadata; } + /** + * Gets executed after deployment of metadata type + * + * @param {MetadataTypeMap} upsertResults metadata mapped by their keyField as returned by update/create + * @returns {Promise.} - + */ + static async postDeployTasks(upsertResults) { + // re-retrieve all upserted items to ensure we have all fields (createdDate and modifiedDate are otherwise not present) + Util.logger.debug( + `Caching all ${this.definition.type} post-deploy to ensure we have all fields` + ); + const typeCache = await this.retrieveForCache(); + // update values in upsertResults with retrieved values before saving to disk + for (const key of Object.keys(upsertResults)) { + if (typeCache.metadata[key]) { + upsertResults[key] = typeCache.metadata[key]; + } + } + } + /** * * @param {MetadataTypeItem} item single metadata item diff --git a/test/general.test.js b/test/general.test.js index ad35543c5..0bee42393 100644 --- a/test/general.test.js +++ b/test/general.test.js @@ -569,7 +569,7 @@ describe('GENERAL', () => { ); assert.equal( testUtils.getAPIHistoryLength(), - 16, + 17, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); }); @@ -632,7 +632,7 @@ describe('GENERAL', () => { ); assert.equal( testUtils.getAPIHistoryLength(), - 17, + 18, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); }); @@ -697,7 +697,7 @@ describe('GENERAL', () => { ); assert.equal( testUtils.getAPIHistoryLength(), - 14, + 15, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); }); @@ -2249,7 +2249,7 @@ describe('GENERAL', () => { ); assert.equal( testUtils.getAPIHistoryLength(), - 16, + 17, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); }); @@ -2298,7 +2298,7 @@ describe('GENERAL', () => { ); assert.equal( testUtils.getAPIHistoryLength(), - 11, + 12, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); }); diff --git a/test/resources/9999999/senderProfile/patch-expected.json b/test/resources/9999999/senderProfile/patch-expected.json index 763196b77..88591c539 100644 --- a/test/resources/9999999/senderProfile/patch-expected.json +++ b/test/resources/9999999/senderProfile/patch-expected.json @@ -1,15 +1,19 @@ { "FallbackFromAddress": "", - "AutoForwardToEmailAddress": "joern.berkefeld@accenture.com", - "AutoForwardToName": "Jörn Berkefeld", - "AutoReply": false, + "CreatedDate": "2021-08-03T11:14:00", + "ModifiedDate": "2021-08-03T11:14:00", "CustomerKey": "testExisting_senderProfile", - "Description": "updated via deploy", - "DirectForward": false, - "FromAddress": "joern.berkefeld@accenture.com", - "FromName": "Jörn Berkefeld", "Name": "testExisting_senderProfile", + "Description": "Send from joern.berkefeld@accenture.com", + "FromName": "Jörn Berkefeld", + "FromAddress": "joern.berkefeld@accenture.com", + "UseDefaultRMMRules": true, + "AutoForwardToEmailAddress": "", + "AutoForwardToName": "", + "DirectForward": false, + "AutoReply": false, "SenderHeaderEmailAddress": "", "SenderHeaderName": "", - "UseDefaultRMMRules": false + "createdBy": "Jörn Berkefeld", + "modifiedBy": "Jörn Berkefeld" } diff --git a/test/type.senderProfile.test.js b/test/type.senderProfile.test.js index 6dbe76343..46a383c58 100644 --- a/test/type.senderProfile.test.js +++ b/test/type.senderProfile.test.js @@ -76,7 +76,7 @@ describe('type: senderProfile', () => { // check number of API calls assert.equal( testUtils.getAPIHistoryLength(), - 6, + 7, 'Unexpected number of requests made. Run testUtils.logAPIHistoryDebug() to see the requests' ); return;