From ceaae0bbf6b0993b9f01f550fd8285878ceb5f5e Mon Sep 17 00:00:00 2001 From: Serban Stancu Date: Thu, 16 Nov 2023 15:40:47 -0700 Subject: [PATCH] Don't show any circular reference errors when getDataElementValues is called with a list of data elements that don't have circular references. This fixes this issue: https://github.com/adobe/reactor-extension-cloud-connector-edge/issues/5. --- src/__tests__/createGetDataElementValues.test.js | 13 +++++++++++++ src/createGetDataElementValues.js | 8 +++++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/src/__tests__/createGetDataElementValues.test.js b/src/__tests__/createGetDataElementValues.test.js index 3e71a13..144b302 100644 --- a/src/__tests__/createGetDataElementValues.test.js +++ b/src/__tests__/createGetDataElementValues.test.js @@ -44,4 +44,17 @@ describe('function returned by createGetDataElementValues', () => { expect(getDataElementValue).toHaveBeenCalledWith('de1', context); }); }); + + test('sends a cloned dataElementCallStack to getDataElementValue', () => { + const getDataElementValues = createGetDataElementValues( + (dataElementName, { dataElementCallStack }) => { + dataElementCallStack.push(dataElementName); + + expect(dataElementCallStack).toStrictEqual([dataElementName]); + } + ); + + const context = {}; + return getDataElementValues(['de1', 'de2'], context); + }); }); diff --git a/src/createGetDataElementValues.js b/src/createGetDataElementValues.js index 3fc5f6f..5017187 100644 --- a/src/createGetDataElementValues.js +++ b/src/createGetDataElementValues.js @@ -9,10 +9,11 @@ OF ANY KIND, either express or implied. See the License for the specific languag governing permissions and limitations under the License. */ -module.exports = (getDataElementValue) => (tokenList, context) => - Promise.all( +module.exports = (getDataElementValue) => (tokenList, context) => { + const { dataElementCallStack = [] } = context; + + return Promise.all( tokenList.map((t) => { - const { dataElementCallStack = [] } = context; context.dataElementCallStack = dataElementCallStack.slice(); return getDataElementValue(t, context); @@ -26,3 +27,4 @@ module.exports = (getDataElementValue) => (tokenList, context) => return (name) => zipResults[name]; }); +};