fix: Fix loading workflows with null connection value (no-changelog) (#11592)

This commit is contained in:
Alex Grozav
2024-11-06 16:16:47 +02:00
committed by GitHub
parent 8022472784
commit 93fae5d8a7
4 changed files with 239 additions and 11 deletions

View File

@@ -1,6 +1,7 @@
import { mock } from 'jest-mock-extended';
import { NodeConnectionType } from '@/Interfaces';
import type { IConnection } from '@/Interfaces';
import type {
IBinaryKeyData,
IConnections,
@@ -2084,4 +2085,154 @@ describe('Workflow', () => {
expect(triggerResponse.closeFunction).toHaveBeenCalled();
});
});
describe('__getConnectionsByDestination', () => {
it('should return empty object when there are no connections', () => {
const workflow = new Workflow({
nodes: [],
connections: {},
active: false,
nodeTypes: mock<INodeTypes>(),
});
const result = workflow.__getConnectionsByDestination({});
expect(result).toEqual({});
});
it('should return connections by destination node', () => {
const connections: IConnections = {
Node1: {
[NodeConnectionType.Main]: [
[
{ node: 'Node2', type: NodeConnectionType.Main, index: 0 },
{ node: 'Node3', type: NodeConnectionType.Main, index: 1 },
],
],
},
};
const workflow = new Workflow({
nodes: [],
connections,
active: false,
nodeTypes: mock<INodeTypes>(),
});
const result = workflow.__getConnectionsByDestination(connections);
expect(result).toEqual({
Node2: {
[NodeConnectionType.Main]: [[{ node: 'Node1', type: NodeConnectionType.Main, index: 0 }]],
},
Node3: {
[NodeConnectionType.Main]: [
[],
[{ node: 'Node1', type: NodeConnectionType.Main, index: 0 }],
],
},
});
});
it('should handle multiple connection types', () => {
const connections: IConnections = {
Node1: {
[NodeConnectionType.Main]: [[{ node: 'Node2', type: NodeConnectionType.Main, index: 0 }]],
[NodeConnectionType.AiAgent]: [
[{ node: 'Node3', type: NodeConnectionType.AiAgent, index: 0 }],
],
},
};
const workflow = new Workflow({
nodes: [],
connections,
active: false,
nodeTypes: mock<INodeTypes>(),
});
const result = workflow.__getConnectionsByDestination(connections);
expect(result).toEqual({
Node2: {
[NodeConnectionType.Main]: [[{ node: 'Node1', type: NodeConnectionType.Main, index: 0 }]],
},
Node3: {
[NodeConnectionType.AiAgent]: [
[{ node: 'Node1', type: NodeConnectionType.AiAgent, index: 0 }],
],
},
});
});
it('should handle nodes with no connections', () => {
const connections: IConnections = {
Node1: {
[NodeConnectionType.Main]: [[]],
},
};
const workflow = new Workflow({
nodes: [],
connections,
active: false,
nodeTypes: mock<INodeTypes>(),
});
const result = workflow.__getConnectionsByDestination(connections);
expect(result).toEqual({});
});
// @issue https://linear.app/n8n/issue/N8N-7880/cannot-load-some-templates
it('should handle nodes with null connections', () => {
const connections: IConnections = {
Node1: {
[NodeConnectionType.Main]: [
null as unknown as IConnection[],
[{ node: 'Node2', type: NodeConnectionType.Main, index: 0 }],
],
},
};
const workflow = new Workflow({
nodes: [],
connections,
active: false,
nodeTypes: mock<INodeTypes>(),
});
const result = workflow.__getConnectionsByDestination(connections);
expect(result).toEqual({
Node2: {
[NodeConnectionType.Main]: [[{ node: 'Node1', type: NodeConnectionType.Main, index: 1 }]],
},
});
});
it('should handle nodes with multiple input connections', () => {
const connections: IConnections = {
Node1: {
[NodeConnectionType.Main]: [[{ node: 'Node2', type: NodeConnectionType.Main, index: 0 }]],
},
Node3: {
[NodeConnectionType.Main]: [[{ node: 'Node2', type: NodeConnectionType.Main, index: 0 }]],
},
};
const workflow = new Workflow({
nodes: [],
connections,
active: false,
nodeTypes: mock<INodeTypes>(),
});
const result = workflow.__getConnectionsByDestination(connections);
expect(result).toEqual({
Node2: {
[NodeConnectionType.Main]: [
[
{ node: 'Node1', type: NodeConnectionType.Main, index: 0 },
{ node: 'Node3', type: NodeConnectionType.Main, index: 0 },
],
],
},
});
});
});
});