fix(Summarize Node): Convert v1 split by values to string (#15525)

This commit is contained in:
Shireen Missi
2025-05-20 09:20:19 +01:00
committed by GitHub
parent 26de97976a
commit 4d037ca68a
3 changed files with 269 additions and 0 deletions

View File

@@ -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`] = `
[
{

View File

@@ -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 = [

View File

@@ -252,6 +252,7 @@ export function aggregateAndSplitData({
fieldsToSummarize,
options,
getValue,
convertKeysToString,
}),
]),
);