From 1ddad4ea3ab7a36e80c96d0a7d84b5397a8f89d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B6rn=20Berkefeld?= Date: Fri, 30 Jun 2023 10:42:02 +0200 Subject: [PATCH] #1008: ensure deploy returns deployed items, not complete cache --- lib/util/cache.js | 13 +++++++++---- test/type.user.test.js | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/util/cache.js b/lib/util/cache.js index bcea3a35d..b95931e3e 100644 --- a/lib/util/cache.js +++ b/lib/util/cache.js @@ -72,10 +72,15 @@ module.exports = { * @returns {void} */ mergeMetadata: (type, metadataMap, overrideMID) => { - dataStore[overrideMID || currentMID][type] = Object.assign( - metadataMap, - dataStore[currentMID][type] - ); + // ensure cache exists for type + dataStore[currentMID][type] ||= {}; + // if overrideMID is provided, create a copy of current MID cache + if (overrideMID) { + // ! needs to be verified if this is actually needed. When discovering an issue with this method actually overriting metadataMap, this copy-logic was present and i did not want to break things + dataStore[overrideMID][type] = Object.assign({}, dataStore[currentMID][type]); + } + // merge metadataMap into existing cache + Object.assign(dataStore[overrideMID || currentMID][type] || {}, metadataMap); }, /** * standardized method for getting data from cache. diff --git a/test/type.user.test.js b/test/type.user.test.js index cb56fe090..810164a60 100644 --- a/test/type.user.test.js +++ b/test/type.user.test.js @@ -83,7 +83,7 @@ describe('type: user', () => { }); it('Should create & upsert a user', async () => { // WHEN - const expectedCache = ['testNew_user', 'testExisting_user']; + const expectedCache = ['testExisting_user', 'testNew_user']; await handler.deploy('testInstance/_ParentBU_', ['user'], expectedCache); // THEN assert.equal(process.exitCode, false, 'deploy should not have thrown an error');