mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
fix(Summarize Node): Convert v1 split by values to string (#15525)
This commit is contained in:
@@ -1,5 +1,183 @@
|
|||||||
// Jest Snapshot v1, https://goo.gl/fbAQLP
|
// 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`] = `
|
exports[`Test Summarize Node, aggregateAndSplitData should handle split field values containing spaces when convertKeysToString is not set: split-field-with-spaces-array 1`] = `
|
||||||
[
|
[
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -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', () => {
|
describe('with skipEmptySplitFields=true', () => {
|
||||||
test('should skip empty split fields', () => {
|
test('should skip empty split fields', () => {
|
||||||
const data = [
|
const data = [
|
||||||
|
|||||||
@@ -252,6 +252,7 @@ export function aggregateAndSplitData({
|
|||||||
fieldsToSummarize,
|
fieldsToSummarize,
|
||||||
options,
|
options,
|
||||||
getValue,
|
getValue,
|
||||||
|
convertKeysToString,
|
||||||
}),
|
}),
|
||||||
]),
|
]),
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user