From 4d037ca68abe4660b3815da3b99e8b65e2b80c43 Mon Sep 17 00:00:00 2001 From: Shireen Missi <94372015+ShireenMissi@users.noreply.github.com> Date: Tue, 20 May 2025 09:20:19 +0100 Subject: [PATCH] fix(Summarize Node): Convert v1 split by values to string (#15525) --- .../__snapshots__/splitData.test.ts.snap | 178 ++++++++++++++++++ .../test/unitTests/splitData.test.ts | 90 +++++++++ .../nodes/Transform/Summarize/utils.ts | 1 + 3 files changed, 269 insertions(+) diff --git a/packages/nodes-base/nodes/Transform/Summarize/test/unitTests/__snapshots__/splitData.test.ts.snap b/packages/nodes-base/nodes/Transform/Summarize/test/unitTests/__snapshots__/splitData.test.ts.snap index 068ab30d1b..874c931748 100644 --- a/packages/nodes-base/nodes/Transform/Summarize/test/unitTests/__snapshots__/splitData.test.ts.snap +++ b/packages/nodes-base/nodes/Transform/Summarize/test/unitTests/__snapshots__/splitData.test.ts.snap @@ -1,5 +1,183 @@ // Jest Snapshot v1, https://goo.gl/fbAQLP +exports[`Test Summarize Node, aggregateAndSplitData should handle multiple split field values containing null when convertKeysToString is false: split-field-with-spaces-array 1`] = ` +[ + { + "pairedItems": [ + 0, + ], + "returnData": { + "Product": "Widget A", + "Warehouse": "WH1", + "appended_Warehouse": [ + "WH1", + ], + }, + }, + { + "pairedItems": [ + 2, + ], + "returnData": { + "Product": "Widget A", + "Warehouse": null, + "appended_Warehouse": [ + null, + ], + }, + }, + { + "pairedItems": [ + 1, + ], + "returnData": { + "Product": null, + "Warehouse": "WH2", + "appended_Warehouse": [ + "WH2", + ], + }, + }, +] +`; + +exports[`Test Summarize Node, aggregateAndSplitData should handle multiple split field values containing null when convertKeysToString is false: split-field-with-spaces-result 1`] = ` +{ + "fieldName": "Product", + "splits": Map { + "Widget A" => { + "fieldName": "Warehouse", + "splits": Map { + "WH1" => { + "pairedItems": [ + 0, + ], + "returnData": { + "appended_Warehouse": [ + "WH1", + ], + }, + }, + null => { + "pairedItems": [ + 2, + ], + "returnData": { + "appended_Warehouse": [ + null, + ], + }, + }, + }, + }, + null => { + "fieldName": "Warehouse", + "splits": Map { + "WH2" => { + "pairedItems": [ + 1, + ], + "returnData": { + "appended_Warehouse": [ + "WH2", + ], + }, + }, + }, + }, + }, +} +`; + +exports[`Test Summarize Node, aggregateAndSplitData should handle multiple split field values containing null when convertKeysToString is true: split-field-with-spaces-array 1`] = ` +[ + { + "pairedItems": [ + 0, + ], + "returnData": { + "Product": "Widget A", + "Warehouse": "WH1", + "appended_Warehouse": [ + "WH1", + ], + }, + }, + { + "pairedItems": [ + 2, + ], + "returnData": { + "Product": "Widget A", + "Warehouse": "null", + "appended_Warehouse": [ + null, + ], + }, + }, + { + "pairedItems": [ + 1, + ], + "returnData": { + "Product": "null", + "Warehouse": "WH2", + "appended_Warehouse": [ + "WH2", + ], + }, + }, +] +`; + +exports[`Test Summarize Node, aggregateAndSplitData should handle multiple split field values containing null when convertKeysToString is true: split-field-with-spaces-result 1`] = ` +{ + "fieldName": "Product", + "splits": Map { + "Widget A" => { + "fieldName": "Warehouse", + "splits": Map { + "WH1" => { + "pairedItems": [ + 0, + ], + "returnData": { + "appended_Warehouse": [ + "WH1", + ], + }, + }, + "null" => { + "pairedItems": [ + 2, + ], + "returnData": { + "appended_Warehouse": [ + null, + ], + }, + }, + }, + }, + "null" => { + "fieldName": "Warehouse", + "splits": Map { + "WH2" => { + "pairedItems": [ + 1, + ], + "returnData": { + "appended_Warehouse": [ + "WH2", + ], + }, + }, + }, + }, + }, +} +`; + exports[`Test Summarize Node, aggregateAndSplitData should handle split field values containing spaces when convertKeysToString is not set: split-field-with-spaces-array 1`] = ` [ { diff --git a/packages/nodes-base/nodes/Transform/Summarize/test/unitTests/splitData.test.ts b/packages/nodes-base/nodes/Transform/Summarize/test/unitTests/splitData.test.ts index 78c9189ab4..2c531dad77 100644 --- a/packages/nodes-base/nodes/Transform/Summarize/test/unitTests/splitData.test.ts +++ b/packages/nodes-base/nodes/Transform/Summarize/test/unitTests/splitData.test.ts @@ -177,6 +177,96 @@ describe('Test Summarize Node, aggregateAndSplitData', () => { ); }); + test('should handle multiple split field values containing null when convertKeysToString is true', () => { + const data = [ + { + Product: 'Widget A', + Warehouse: 'WH1', + Qty: '5', + _itemIndex: 0, + }, + { + Product: null, + Warehouse: 'WH2', + Qty: '3', + _itemIndex: 1, + }, + { + Product: 'Widget A', + Warehouse: null, + Qty: '2', + _itemIndex: 2, + }, + ]; + + const aggregations: Aggregations = [ + { + aggregation: 'append', + field: 'Warehouse', + includeEmpty: true, + }, + ]; + + const result = aggregateAndSplitData({ + splitKeys: ['Product', 'Warehouse'], + inputItems: data, + fieldsToSummarize: aggregations, + options: { continueIfFieldNotFound: true }, + getValue: fieldValueGetter(), + convertKeysToString: true, + }); + + expect(result).toMatchSnapshot('split-field-with-spaces-result'); + expect(flattenAggregationResultToArray(result)).toMatchSnapshot( + 'split-field-with-spaces-array', + ); + }); + + test('should handle multiple split field values containing null when convertKeysToString is false', () => { + const data = [ + { + Product: 'Widget A', + Warehouse: 'WH1', + Qty: '5', + _itemIndex: 0, + }, + { + Product: null, + Warehouse: 'WH2', + Qty: '3', + _itemIndex: 1, + }, + { + Product: 'Widget A', + Warehouse: null, + Qty: '2', + _itemIndex: 2, + }, + ]; + + const aggregations: Aggregations = [ + { + aggregation: 'append', + field: 'Warehouse', + includeEmpty: true, + }, + ]; + + const result = aggregateAndSplitData({ + splitKeys: ['Product', 'Warehouse'], + inputItems: data, + fieldsToSummarize: aggregations, + options: { continueIfFieldNotFound: true }, + getValue: fieldValueGetter(), + convertKeysToString: false, + }); + + expect(result).toMatchSnapshot('split-field-with-spaces-result'); + expect(flattenAggregationResultToArray(result)).toMatchSnapshot( + 'split-field-with-spaces-array', + ); + }); + describe('with skipEmptySplitFields=true', () => { test('should skip empty split fields', () => { const data = [ diff --git a/packages/nodes-base/nodes/Transform/Summarize/utils.ts b/packages/nodes-base/nodes/Transform/Summarize/utils.ts index 84231e1f90..5347ed610b 100644 --- a/packages/nodes-base/nodes/Transform/Summarize/utils.ts +++ b/packages/nodes-base/nodes/Transform/Summarize/utils.ts @@ -252,6 +252,7 @@ export function aggregateAndSplitData({ fieldsToSummarize, options, getValue, + convertKeysToString, }), ]), );