Skip to content

Commit 4d037ca

Browse files
authored
fix(Summarize Node): Convert v1 split by values to string (#15525)
1 parent 26de979 commit 4d037ca

File tree

3 files changed

+269
-0
lines changed

3 files changed

+269
-0
lines changed

packages/nodes-base/nodes/Transform/Summarize/test/unitTests/__snapshots__/splitData.test.ts.snap

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,183 @@
11
// Jest Snapshot v1, https://goo.gl/fbAQLP
22

3+
exports[`Test Summarize Node, aggregateAndSplitData should handle multiple split field values containing null when convertKeysToString is false: split-field-with-spaces-array 1`] = `
4+
[
5+
{
6+
"pairedItems": [
7+
0,
8+
],
9+
"returnData": {
10+
"Product": "Widget A",
11+
"Warehouse": "WH1",
12+
"appended_Warehouse": [
13+
"WH1",
14+
],
15+
},
16+
},
17+
{
18+
"pairedItems": [
19+
2,
20+
],
21+
"returnData": {
22+
"Product": "Widget A",
23+
"Warehouse": null,
24+
"appended_Warehouse": [
25+
null,
26+
],
27+
},
28+
},
29+
{
30+
"pairedItems": [
31+
1,
32+
],
33+
"returnData": {
34+
"Product": null,
35+
"Warehouse": "WH2",
36+
"appended_Warehouse": [
37+
"WH2",
38+
],
39+
},
40+
},
41+
]
42+
`;
43+
44+
exports[`Test Summarize Node, aggregateAndSplitData should handle multiple split field values containing null when convertKeysToString is false: split-field-with-spaces-result 1`] = `
45+
{
46+
"fieldName": "Product",
47+
"splits": Map {
48+
"Widget A" => {
49+
"fieldName": "Warehouse",
50+
"splits": Map {
51+
"WH1" => {
52+
"pairedItems": [
53+
0,
54+
],
55+
"returnData": {
56+
"appended_Warehouse": [
57+
"WH1",
58+
],
59+
},
60+
},
61+
null => {
62+
"pairedItems": [
63+
2,
64+
],
65+
"returnData": {
66+
"appended_Warehouse": [
67+
null,
68+
],
69+
},
70+
},
71+
},
72+
},
73+
null => {
74+
"fieldName": "Warehouse",
75+
"splits": Map {
76+
"WH2" => {
77+
"pairedItems": [
78+
1,
79+
],
80+
"returnData": {
81+
"appended_Warehouse": [
82+
"WH2",
83+
],
84+
},
85+
},
86+
},
87+
},
88+
},
89+
}
90+
`;
91+
92+
exports[`Test Summarize Node, aggregateAndSplitData should handle multiple split field values containing null when convertKeysToString is true: split-field-with-spaces-array 1`] = `
93+
[
94+
{
95+
"pairedItems": [
96+
0,
97+
],
98+
"returnData": {
99+
"Product": "Widget A",
100+
"Warehouse": "WH1",
101+
"appended_Warehouse": [
102+
"WH1",
103+
],
104+
},
105+
},
106+
{
107+
"pairedItems": [
108+
2,
109+
],
110+
"returnData": {
111+
"Product": "Widget A",
112+
"Warehouse": "null",
113+
"appended_Warehouse": [
114+
null,
115+
],
116+
},
117+
},
118+
{
119+
"pairedItems": [
120+
1,
121+
],
122+
"returnData": {
123+
"Product": "null",
124+
"Warehouse": "WH2",
125+
"appended_Warehouse": [
126+
"WH2",
127+
],
128+
},
129+
},
130+
]
131+
`;
132+
133+
exports[`Test Summarize Node, aggregateAndSplitData should handle multiple split field values containing null when convertKeysToString is true: split-field-with-spaces-result 1`] = `
134+
{
135+
"fieldName": "Product",
136+
"splits": Map {
137+
"Widget A" => {
138+
"fieldName": "Warehouse",
139+
"splits": Map {
140+
"WH1" => {
141+
"pairedItems": [
142+
0,
143+
],
144+
"returnData": {
145+
"appended_Warehouse": [
146+
"WH1",
147+
],
148+
},
149+
},
150+
"null" => {
151+
"pairedItems": [
152+
2,
153+
],
154+
"returnData": {
155+
"appended_Warehouse": [
156+
null,
157+
],
158+
},
159+
},
160+
},
161+
},
162+
"null" => {
163+
"fieldName": "Warehouse",
164+
"splits": Map {
165+
"WH2" => {
166+
"pairedItems": [
167+
1,
168+
],
169+
"returnData": {
170+
"appended_Warehouse": [
171+
"WH2",
172+
],
173+
},
174+
},
175+
},
176+
},
177+
},
178+
}
179+
`;
180+
3181
exports[`Test Summarize Node, aggregateAndSplitData should handle split field values containing spaces when convertKeysToString is not set: split-field-with-spaces-array 1`] = `
4182
[
5183
{

packages/nodes-base/nodes/Transform/Summarize/test/unitTests/splitData.test.ts

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,96 @@ describe('Test Summarize Node, aggregateAndSplitData', () => {
177177
);
178178
});
179179

180+
test('should handle multiple split field values containing null when convertKeysToString is true', () => {
181+
const data = [
182+
{
183+
Product: 'Widget A',
184+
Warehouse: 'WH1',
185+
Qty: '5',
186+
_itemIndex: 0,
187+
},
188+
{
189+
Product: null,
190+
Warehouse: 'WH2',
191+
Qty: '3',
192+
_itemIndex: 1,
193+
},
194+
{
195+
Product: 'Widget A',
196+
Warehouse: null,
197+
Qty: '2',
198+
_itemIndex: 2,
199+
},
200+
];
201+
202+
const aggregations: Aggregations = [
203+
{
204+
aggregation: 'append',
205+
field: 'Warehouse',
206+
includeEmpty: true,
207+
},
208+
];
209+
210+
const result = aggregateAndSplitData({
211+
splitKeys: ['Product', 'Warehouse'],
212+
inputItems: data,
213+
fieldsToSummarize: aggregations,
214+
options: { continueIfFieldNotFound: true },
215+
getValue: fieldValueGetter(),
216+
convertKeysToString: true,
217+
});
218+
219+
expect(result).toMatchSnapshot('split-field-with-spaces-result');
220+
expect(flattenAggregationResultToArray(result)).toMatchSnapshot(
221+
'split-field-with-spaces-array',
222+
);
223+
});
224+
225+
test('should handle multiple split field values containing null when convertKeysToString is false', () => {
226+
const data = [
227+
{
228+
Product: 'Widget A',
229+
Warehouse: 'WH1',
230+
Qty: '5',
231+
_itemIndex: 0,
232+
},
233+
{
234+
Product: null,
235+
Warehouse: 'WH2',
236+
Qty: '3',
237+
_itemIndex: 1,
238+
},
239+
{
240+
Product: 'Widget A',
241+
Warehouse: null,
242+
Qty: '2',
243+
_itemIndex: 2,
244+
},
245+
];
246+
247+
const aggregations: Aggregations = [
248+
{
249+
aggregation: 'append',
250+
field: 'Warehouse',
251+
includeEmpty: true,
252+
},
253+
];
254+
255+
const result = aggregateAndSplitData({
256+
splitKeys: ['Product', 'Warehouse'],
257+
inputItems: data,
258+
fieldsToSummarize: aggregations,
259+
options: { continueIfFieldNotFound: true },
260+
getValue: fieldValueGetter(),
261+
convertKeysToString: false,
262+
});
263+
264+
expect(result).toMatchSnapshot('split-field-with-spaces-result');
265+
expect(flattenAggregationResultToArray(result)).toMatchSnapshot(
266+
'split-field-with-spaces-array',
267+
);
268+
});
269+
180270
describe('with skipEmptySplitFields=true', () => {
181271
test('should skip empty split fields', () => {
182272
const data = [

packages/nodes-base/nodes/Transform/Summarize/utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,6 +252,7 @@ export function aggregateAndSplitData({
252252
fieldsToSummarize,
253253
options,
254254
getValue,
255+
convertKeysToString,
255256
}),
256257
]),
257258
);

0 commit comments

Comments
 (0)