mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
fix(Summarize Node): Fix spaces in Fields to Split By values converted to underscores (#15020)
This commit is contained in:
@@ -1,5 +1,123 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
||||||
|
|
||||||
|
exports[`Test Summarize Node, aggregateAndSplitData should handle split field values containing spaces when convertKeysToString is not set: split-field-with-spaces-array 1`] = `
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"pairedItems": [
|
||||||
|
0,
|
||||||
|
2,
|
||||||
|
],
|
||||||
|
"returnData": {
|
||||||
|
"Product": "Widget A",
|
||||||
|
"appended_Warehouse": [
|
||||||
|
"WH1",
|
||||||
|
"WH3",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pairedItems": [
|
||||||
|
1,
|
||||||
|
],
|
||||||
|
"returnData": {
|
||||||
|
"Product": "Widget B",
|
||||||
|
"appended_Warehouse": [
|
||||||
|
"WH2",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`Test Summarize Node, aggregateAndSplitData should handle split field values containing spaces when convertKeysToString is not set: split-field-with-spaces-result 1`] = `
|
||||||
|
{
|
||||||
|
"fieldName": "Product",
|
||||||
|
"splits": Map {
|
||||||
|
"Widget A" => {
|
||||||
|
"pairedItems": [
|
||||||
|
0,
|
||||||
|
2,
|
||||||
|
],
|
||||||
|
"returnData": {
|
||||||
|
"appended_Warehouse": [
|
||||||
|
"WH1",
|
||||||
|
"WH3",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"Widget B" => {
|
||||||
|
"pairedItems": [
|
||||||
|
1,
|
||||||
|
],
|
||||||
|
"returnData": {
|
||||||
|
"appended_Warehouse": [
|
||||||
|
"WH2",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`Test Summarize Node, aggregateAndSplitData should handle split field values containing spaces when convertKeysToString is true: split-field-with-spaces-array 1`] = `
|
||||||
|
[
|
||||||
|
{
|
||||||
|
"pairedItems": [
|
||||||
|
0,
|
||||||
|
2,
|
||||||
|
],
|
||||||
|
"returnData": {
|
||||||
|
"Product": "Widget A",
|
||||||
|
"appended_Warehouse": [
|
||||||
|
"WH1",
|
||||||
|
"WH3",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"pairedItems": [
|
||||||
|
1,
|
||||||
|
],
|
||||||
|
"returnData": {
|
||||||
|
"Product": "Widget B",
|
||||||
|
"appended_Warehouse": [
|
||||||
|
"WH2",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
`;
|
||||||
|
|
||||||
|
exports[`Test Summarize Node, aggregateAndSplitData should handle split field values containing spaces when convertKeysToString is true: split-field-with-spaces-result 1`] = `
|
||||||
|
{
|
||||||
|
"fieldName": "Product",
|
||||||
|
"splits": Map {
|
||||||
|
"Widget A" => {
|
||||||
|
"pairedItems": [
|
||||||
|
0,
|
||||||
|
2,
|
||||||
|
],
|
||||||
|
"returnData": {
|
||||||
|
"appended_Warehouse": [
|
||||||
|
"WH1",
|
||||||
|
"WH3",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
"Widget B" => {
|
||||||
|
"pairedItems": [
|
||||||
|
1,
|
||||||
|
],
|
||||||
|
"returnData": {
|
||||||
|
"appended_Warehouse": [
|
||||||
|
"WH2",
|
||||||
|
],
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
exports[`Test Summarize Node, aggregateAndSplitData should not convert numbers to strings: array 1`] = `
|
exports[`Test Summarize Node, aggregateAndSplitData should not convert numbers to strings: array 1`] = `
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -88,6 +88,95 @@ describe('Test Summarize Node, aggregateAndSplitData', () => {
|
|||||||
expect(flattenAggregationResultToArray(result)).toMatchSnapshot('array');
|
expect(flattenAggregationResultToArray(result)).toMatchSnapshot('array');
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('should handle split field values containing spaces when convertKeysToString is not set', () => {
|
||||||
|
const data = [
|
||||||
|
{
|
||||||
|
Product: 'Widget A',
|
||||||
|
Warehouse: 'WH1',
|
||||||
|
Qty: '5',
|
||||||
|
_itemIndex: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Product: 'Widget B',
|
||||||
|
Warehouse: 'WH2',
|
||||||
|
Qty: '3',
|
||||||
|
_itemIndex: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Product: 'Widget A',
|
||||||
|
Warehouse: 'WH3',
|
||||||
|
Qty: '2',
|
||||||
|
_itemIndex: 2,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const aggregations: Aggregations = [
|
||||||
|
{
|
||||||
|
aggregation: 'append',
|
||||||
|
field: 'Warehouse',
|
||||||
|
includeEmpty: true,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const result = aggregateAndSplitData({
|
||||||
|
splitKeys: ['Product'],
|
||||||
|
inputItems: data,
|
||||||
|
fieldsToSummarize: aggregations,
|
||||||
|
options: { continueIfFieldNotFound: true },
|
||||||
|
getValue: fieldValueGetter(),
|
||||||
|
});
|
||||||
|
|
||||||
|
expect(result).toMatchSnapshot('split-field-with-spaces-result');
|
||||||
|
expect(flattenAggregationResultToArray(result)).toMatchSnapshot(
|
||||||
|
'split-field-with-spaces-array',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should handle split field values containing spaces when convertKeysToString is true', () => {
|
||||||
|
const data = [
|
||||||
|
{
|
||||||
|
Product: 'Widget A',
|
||||||
|
Warehouse: 'WH1',
|
||||||
|
Qty: '5',
|
||||||
|
_itemIndex: 0,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Product: 'Widget B',
|
||||||
|
Warehouse: 'WH2',
|
||||||
|
Qty: '3',
|
||||||
|
_itemIndex: 1,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Product: 'Widget A',
|
||||||
|
Warehouse: 'WH3',
|
||||||
|
Qty: '2',
|
||||||
|
_itemIndex: 2,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const aggregations: Aggregations = [
|
||||||
|
{
|
||||||
|
aggregation: 'append',
|
||||||
|
field: 'Warehouse',
|
||||||
|
includeEmpty: true,
|
||||||
|
},
|
||||||
|
];
|
||||||
|
|
||||||
|
const result = aggregateAndSplitData({
|
||||||
|
splitKeys: ['Product'],
|
||||||
|
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',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
describe('with skipEmptySplitFields=true', () => {
|
describe('with skipEmptySplitFields=true', () => {
|
||||||
test('should skip empty split fields', () => {
|
test('should skip empty split fields', () => {
|
||||||
const data = [
|
const data = [
|
||||||
|
|||||||
@@ -225,22 +225,22 @@ export function aggregateAndSplitData({
|
|||||||
|
|
||||||
const groupedItems = new Map<unknown, IDataObject[]>();
|
const groupedItems = new Map<unknown, IDataObject[]>();
|
||||||
for (const item of inputItems) {
|
for (const item of inputItems) {
|
||||||
let key = getValue(item, firstSplitKey);
|
let splitValue = getValue(item, firstSplitKey);
|
||||||
|
|
||||||
if (key && typeof key === 'object') {
|
if (splitValue && typeof splitValue === 'object') {
|
||||||
key = JSON.stringify(key);
|
splitValue = JSON.stringify(splitValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (convertKeysToString) {
|
if (convertKeysToString) {
|
||||||
key = normalizeFieldName(String(key));
|
splitValue = String(splitValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (options.skipEmptySplitFields && typeof key !== 'number' && !key) {
|
if (options.skipEmptySplitFields && typeof splitValue !== 'number' && !splitValue) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
const group = groupedItems.get(key) ?? [];
|
const group = groupedItems.get(splitValue) ?? [];
|
||||||
groupedItems.set(key, group.concat([item]));
|
groupedItems.set(splitValue, group.concat([item]));
|
||||||
}
|
}
|
||||||
|
|
||||||
const splits = new Map(
|
const splits = new Map(
|
||||||
|
|||||||
Reference in New Issue
Block a user