Skip to content

Commit

Permalink
fix(Data Mapper): Deserialize source edge for custom function with da…
Browse files Browse the repository at this point in the history
…sh in its name (#4384)

Deserialize source edge for custom function with dash in its name
  • Loading branch information
chris-w-dev committed Mar 18, 2024
1 parent 1327f8d commit 9b44f43
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 1 deletion.
3 changes: 2 additions & 1 deletion libs/data-mapper/src/lib/utils/DataMap.Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,8 @@ export const getDestinationNode = (targetKey: string, functions: FunctionData[],
return findFunctionForFunctionName(mapNodeParams.if, functions);
}

const dashIndex = targetKey.indexOf('-');
const guidLength = 36;
const dashIndex = targetKey.lastIndexOf('-', targetKey.length - guidLength);
const destinationFunctionKey = dashIndex === -1 ? targetKey : targetKey.slice(0, dashIndex);
const destinationFunctionGuid = targetKey.slice(dashIndex + 1);

Expand Down
55 changes: 55 additions & 0 deletions libs/data-mapper/src/lib/utils/__test__/DataMapUtils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { FunctionCategory } from '../../models';
import type { FunctionData } from '../../models';
import type { ConnectionDictionary, ConnectionUnit } from '../../models/Connection';
import {
ReservedToken,
Separators,
addAncestorNodesToCanvas,
addParentConnectionForRepeatingElementsNested,
getDestinationNode,
getSourceValueFromLoop,
getTargetValueWithoutLoops,
lexThisThing as separateIntoTokens,
Expand Down Expand Up @@ -980,6 +982,59 @@ describe('utils/DataMap', () => {
]);
});
});

describe('getDestinationNode', () => {
const mockSchemaNodeExtended: SchemaNodeExtended = {
key: '/root',
name: 'root',
qName: 'root',
type: NormalizedDataType.String,
properties: SchemaNodeProperty.None,
nodeProperties: [SchemaNodeProperty.None],
children: [
{
key: '/root/Some-String-Property-With-A-Dash-And-Longer-Than-A-Guid',
name: 'Some-String-Property-With-A-Dash-And-Longer-Than-A-Guid',
qName: 'Some-String-Property-With-A-Dash-And-Longer-Than-A-Guid',
type: NormalizedDataType.String,
properties: SchemaNodeProperty.None,
nodeProperties: [SchemaNodeProperty.None],
children: [],
pathToRoot: [],
arrayItemIndex: undefined,
parentKey: '/root',
},
],
pathToRoot: [],
arrayItemIndex: undefined,
parentKey: undefined,
};

const mockFunctionData: FunctionData = {
key: 'some-function',
functionName: 'Some',
displayName: 'Some',
category: FunctionCategory.Custom,
description: 'Some',
inputs: [],
maxNumberOfInputs: 0,
outputValueType: NormalizedDataType.String,
};

it('returns function data for function target key', () => {
const result = getDestinationNode('some-function-4C117648-E570-4CDA-BA8E-DAFC66ECD402', [mockFunctionData], mockSchemaNodeExtended);
expect(result).toBe(mockFunctionData);
});

it('returns schema node for node target key', () => {
const result = getDestinationNode(
'/root/Some-String-Property-With-A-Dash-And-Longer-Than-A-Guid',
[mockFunctionData],
mockSchemaNodeExtended
);
expect(result).toBe(mockSchemaNodeExtended.children[0]);
});
});
});

const indexed: ConnectionDictionary = {
Expand Down

0 comments on commit 9b44f43

Please sign in to comment.