refactor(editor): Remove part of getCurrentWorkflow usages (#16148)

This commit is contained in:
Alex Grozav
2025-07-24 12:51:32 +03:00
committed by GitHub
parent b09f73701d
commit c30dbc6dd4
29 changed files with 578 additions and 391 deletions

View File

@@ -14,11 +14,8 @@ import {
createTestWorkflowExecutionResponse,
createTestWorkflowObject,
} from '@/__tests__/mocks';
import {
NodeConnectionTypes,
WEBHOOK_NODE_TYPE,
type AssignmentCollectionValue,
} from 'n8n-workflow';
import { NodeConnectionTypes, WEBHOOK_NODE_TYPE } from 'n8n-workflow';
import type { AssignmentCollectionValue, IConnections } from 'n8n-workflow';
import * as apiWebhooks from '@n8n/rest-api-client/api/webhooks';
import { mockedStore } from '@/__tests__/utils';
@@ -519,7 +516,7 @@ describe('useWorkflowHelpers', () => {
const inputName = 'main';
const runIndex = 0;
const result = executeData(parentNodes, currentNode, inputName, runIndex);
const result = executeData({}, parentNodes, currentNode, inputName, runIndex);
expect(result).toEqual({
node: {},
@@ -538,18 +535,15 @@ describe('useWorkflowHelpers', () => {
const jsonData = {
name: 'Test',
};
workflowsStore.getCurrentWorkflow.mockReturnValue({
connectionsByDestinationNode: {
Set: {
main: [
[
{ node: 'Start', index: 0, type: 'main' },
{ node: 'Set', index: 0, type: 'main' },
],
],
},
const connectionsBySourceNode: IConnections = {
Start: {
main: [[{ node: 'Set', index: 0, type: 'main' }]],
},
} as never);
Set: {
main: [[{ node: 'Start', index: 0, type: 'main' }]],
},
};
workflowsStore.workflowExecutionData = {
data: {
@@ -575,7 +569,13 @@ describe('useWorkflowHelpers', () => {
},
} as unknown as IExecutionResponse;
const result = executeData(parentNodes, currentNode, inputName, runIndex);
const result = executeData(
connectionsBySourceNode,
parentNodes,
currentNode,
inputName,
runIndex,
);
expect(result).toEqual({
node: {},
@@ -609,18 +609,15 @@ describe('useWorkflowHelpers', () => {
const jsonData = {
name: 'Test',
};
workflowsStore.getCurrentWorkflow.mockReturnValue({
connectionsByDestinationNode: {
Set: {
main: [
[
{ node: 'Start', index: 0, type: 'main' },
{ node: 'Set', index: 0, type: 'main' },
],
],
},
const connectionsBySourceNode: IConnections = {
Start: {
main: [[{ node: 'Set', index: 0, type: 'main' }]],
},
} as never);
Set: {
main: [[{ node: 'Start', index: 0, type: 'main' }]],
},
};
workflowsStore.workflowExecutionData = {
data: {
@@ -646,7 +643,13 @@ describe('useWorkflowHelpers', () => {
},
} as unknown as IExecutionResponse;
const result = executeData(parentNodes, currentNode, inputName, runIndex);
const result = executeData(
connectionsBySourceNode,
parentNodes,
currentNode,
inputName,
runIndex,
);
expect(result).toEqual({
node: {},
@@ -686,22 +689,20 @@ describe('useWorkflowHelpers', () => {
name: 'Test B',
};
workflowsStore.getCurrentWorkflow.mockReturnValue({
connectionsByDestinationNode: {
Set: {
main: [
[
{ node: 'Parent A', index: 0, type: 'main' },
{ node: 'Set', index: 0, type: 'main' },
],
[
{ node: 'Parent B', index: 0, type: 'main' },
{ node: 'Set', index: 0, type: 'main' },
],
],
},
const connectionsBySourceNode: IConnections = {
'Parent A': {
main: [[{ node: 'Set', type: 'main', index: 0 }]],
},
} as never);
'Parent B': {
main: [[{ node: 'Set', type: 'main', index: 1 }]],
},
Set: {
main: [
[{ node: 'Set', type: 'main', index: 0 }],
[{ node: 'Set', type: 'main', index: 1 }],
],
},
};
workflowsStore.workflowExecutionData = {
data: {
@@ -742,7 +743,13 @@ describe('useWorkflowHelpers', () => {
},
} as unknown as IExecutionResponse;
const result = executeData(parentNodes, currentNode, inputName, runIndex);
const result = executeData(
connectionsBySourceNode,
parentNodes,
currentNode,
inputName,
runIndex,
);
expect(result).toEqual({
node: {},
@@ -779,7 +786,7 @@ describe('useWorkflowHelpers', () => {
};
workflowsStore.shouldReplaceInputDataWithPinData = true;
const result = executeData(parentNodes, currentNode, inputName, runIndex);
const result = executeData({}, parentNodes, currentNode, inputName, runIndex);
expect(result.data).toEqual({ main: [[{ json: { key: 'value' } }]] });
expect(result.source).toEqual({ main: [{ previousNode: 'ParentNode' }] });
@@ -802,20 +809,23 @@ describe('useWorkflowHelpers', () => {
} as never,
],
};
workflowsStore.getCurrentWorkflow.mockReturnValue({
connectionsByDestinationNode: {
CurrentNode: {
main: [
[
{ node: 'ParentNode', index: 0, type: 'main' },
{ node: 'CurrentNode', index: 0, type: 'main' },
],
],
},
},
} as never);
const result = executeData(parentNodes, currentNode, inputName, runIndex);
const connectionsBySourceNode: IConnections = {
CurrentNode: {
main: [[{ node: 'CurrentNode', index: 0, type: 'main' }]],
},
ParentNode: {
main: [[{ node: 'CurrentNode', index: 0, type: 'main' }]],
},
};
const result = executeData(
connectionsBySourceNode,
parentNodes,
currentNode,
inputName,
runIndex,
);
expect(result.data).toEqual({ main: [[{ json: { key: 'valueFromRunData' } }]] });
expect(result.source).toEqual({
@@ -841,20 +851,24 @@ describe('useWorkflowHelpers', () => {
} as never,
],
};
workflowsStore.getCurrentWorkflow.mockReturnValue({
connectionsByDestinationNode: {
CurrentNode: {
main: [
[
{ node: 'ParentNode', index: 1, type: 'main' },
{ node: 'CurrentNode', index: 0, type: 'main' },
],
],
},
},
} as never);
const result = executeData(parentNodes, currentNode, inputName, runIndex, parentRunIndex);
const connectionsBySourceNode: IConnections = {
CurrentNode: {
main: [[{ node: 'CurrentNode', index: 0, type: 'main' }]],
},
ParentNode: {
main: [[], [{ node: 'CurrentNode', index: 1, type: 'main' }]],
},
};
const result = executeData(
connectionsBySourceNode,
parentNodes,
currentNode,
inputName,
runIndex,
parentRunIndex,
);
expect(result.data).toEqual({ main: [[{ json: { key: 'valueFromRunData' } }]] });
expect(result.source).toEqual({
@@ -874,7 +888,7 @@ describe('useWorkflowHelpers', () => {
workflowsStore.shouldReplaceInputDataWithPinData = false;
workflowsStore.getWorkflowRunData = null;
const result = executeData(parentNodes, currentNode, inputName, runIndex);
const result = executeData({}, parentNodes, currentNode, inputName, runIndex);
expect(result.data).toEqual({});
expect(result.source).toBeNull();