mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-10 14:44:05 -08:00
bdb84130d6
* ✨ Add pairedItem support * 👕 Fix lint issue * 🐛 Fix resolution in frontend * 🐛 Fix resolution issue * 🐛 Fix resolution in frontend * 🐛 Fix another resolution issue in frontend * ⚡ Try to automatically add pairedItem data if possible * ⚡ Cleanup * ⚡ Display expression errors in editor UI * 🐛 Fix issue that it did not display errors in production * 🐛 Fix auto-fix of missing pairedItem data * 🐛 Fix frontend resolution for not executed nodes * ⚡ Fail execution on pairedItem resolve issue and display information about itemIndex and runIndex * ⚡ Allow that pairedItem is only set to number if runIndex is 0 * ✨ Improve Expression Errors * ⚡ Remove no longer needed code * ⚡ Make errors more helpful * ⚡ Add additional errors * 👕 Fix lint issue * ⚡ Add pairedItem support to core nodes * ⚡ Improve support in Merge-Node * ⚡ Fix issue with not correctly converted incoming pairedItem data * 🐛 Fix frontend resolve issue * 🐛 Fix frontend parameter name display issue * ⚡ Improve errors * 👕 Fix lint issue * ⚡ Improve errors * ⚡ Make it possible to display parameter name in error messages * ⚡ Improve error messages * ⚡ Fix error message * ⚡ Improve error messages * ⚡ Add another error message * ⚡ Simplify
200 lines
4.5 KiB
TypeScript
200 lines
4.5 KiB
TypeScript
import { Workflow, WorkflowDataProxy } from '../src';
|
|
import * as Helpers from './Helpers';
|
|
import { IConnections, INode, INodeExecutionData, IRunExecutionData } from '../src/Interfaces';
|
|
|
|
describe('WorkflowDataProxy', () => {
|
|
describe('test data proxy', () => {
|
|
const nodes: INode[] = [
|
|
{
|
|
parameters: {},
|
|
name: 'Start',
|
|
type: 'test.set',
|
|
typeVersion: 1,
|
|
position: [100, 200],
|
|
},
|
|
{
|
|
parameters: {
|
|
functionCode:
|
|
'// Code here will run only once, no matter how many input items there are.\n// More info and help: https://docs.n8n.io/nodes/n8n-nodes-base.function\nconst { DateTime, Duration, Interval } = require("luxon");\n\nconst data = [\n {\n "length": 105\n },\n {\n "length": 160\n },\n {\n "length": 121\n },\n {\n "length": 275\n },\n {\n "length": 950\n },\n];\n\nreturn data.map(fact => ({json: fact}));',
|
|
},
|
|
name: 'Function',
|
|
type: 'test.set',
|
|
typeVersion: 1,
|
|
position: [280, 200],
|
|
},
|
|
{
|
|
parameters: {
|
|
keys: {
|
|
key: [
|
|
{
|
|
currentKey: 'length',
|
|
newKey: 'data',
|
|
},
|
|
],
|
|
},
|
|
},
|
|
name: 'Rename',
|
|
type: 'test.set',
|
|
typeVersion: 1,
|
|
position: [460, 200],
|
|
},
|
|
];
|
|
|
|
const connections: IConnections = {
|
|
Start: {
|
|
main: [
|
|
[
|
|
{
|
|
node: 'Function',
|
|
type: 'main',
|
|
index: 0,
|
|
},
|
|
],
|
|
],
|
|
},
|
|
Function: {
|
|
main: [
|
|
[
|
|
{
|
|
node: 'Rename',
|
|
type: 'main',
|
|
index: 0,
|
|
},
|
|
],
|
|
],
|
|
},
|
|
};
|
|
|
|
const runExecutionData: IRunExecutionData = {
|
|
resultData: {
|
|
runData: {
|
|
Function: [
|
|
{
|
|
startTime: 1,
|
|
executionTime: 1,
|
|
// @ts-ignore
|
|
data: {
|
|
main: [
|
|
[
|
|
{
|
|
json: { length: 105 },
|
|
},
|
|
{
|
|
json: { length: 160 },
|
|
},
|
|
{
|
|
json: { length: 121 },
|
|
},
|
|
{
|
|
json: { length: 275 },
|
|
},
|
|
{
|
|
json: { length: 950 },
|
|
},
|
|
],
|
|
],
|
|
},
|
|
source: [],
|
|
},
|
|
],
|
|
Rename: [
|
|
{
|
|
startTime: 1,
|
|
executionTime: 1,
|
|
// @ts-ignore
|
|
data: {
|
|
main: [
|
|
[
|
|
{
|
|
json: { data: 105 },
|
|
},
|
|
{
|
|
json: { data: 160 },
|
|
},
|
|
{
|
|
json: { data: 121 },
|
|
},
|
|
{
|
|
json: { data: 275 },
|
|
},
|
|
{
|
|
json: { data: 950 },
|
|
},
|
|
],
|
|
],
|
|
},
|
|
source: [],
|
|
},
|
|
],
|
|
},
|
|
},
|
|
};
|
|
|
|
const renameNodeConnectionInputData: INodeExecutionData[] = [
|
|
{ json: { length: 105 } },
|
|
{ json: { length: 160 } },
|
|
{ json: { length: 121 } },
|
|
{ json: { length: 275 } },
|
|
{ json: { length: 950 } },
|
|
];
|
|
|
|
const nodeTypes = Helpers.NodeTypes();
|
|
const workflow = new Workflow({ nodes, connections, active: false, nodeTypes });
|
|
|
|
const dataProxy = new WorkflowDataProxy(
|
|
workflow,
|
|
runExecutionData,
|
|
0,
|
|
0,
|
|
'Rename',
|
|
renameNodeConnectionInputData || [],
|
|
{},
|
|
'manual',
|
|
'America/New_York',
|
|
{},
|
|
);
|
|
const proxy = dataProxy.getDataProxy();
|
|
|
|
test('test $("NodeName").all()', () => {
|
|
expect(proxy.$('Rename').all()[1].json.data).toEqual(160);
|
|
});
|
|
test('test $("NodeName").all() length', () => {
|
|
expect(proxy.$('Rename').all().length).toEqual(5);
|
|
});
|
|
test('test $("NodeName").item()', () => {
|
|
expect(proxy.$('Rename').item().json.data).toEqual(105);
|
|
});
|
|
test('test $("NodeName").item(2)', () => {
|
|
expect(proxy.$('Rename').item(2).json.data).toEqual(121);
|
|
});
|
|
test('test $("NodeName").first()', () => {
|
|
expect(proxy.$('Rename').first().json.data).toEqual(105);
|
|
});
|
|
test('test $("NodeName").last()', () => {
|
|
expect(proxy.$('Rename').last().json.data).toEqual(950);
|
|
});
|
|
|
|
test('test $input.all()', () => {
|
|
expect(proxy.$input.all()[1].json.length).toEqual(160);
|
|
});
|
|
test('test $input.all() length', () => {
|
|
expect(proxy.$input.all().length).toEqual(5);
|
|
});
|
|
test('test $input.item()', () => {
|
|
expect(proxy.$input.item().json.length).toEqual(105);
|
|
});
|
|
test('test $thisItem', () => {
|
|
expect(proxy.$thisItem.json.length).toEqual(105);
|
|
});
|
|
test('test $input.item(2)', () => {
|
|
expect(proxy.$input.item(2).json.length).toEqual(121);
|
|
});
|
|
test('test $input.first()', () => {
|
|
expect(proxy.$input.first().json.length).toEqual(105);
|
|
});
|
|
test('test $input.last()', () => {
|
|
expect(proxy.$input.last().json.length).toEqual(950);
|
|
});
|
|
});
|
|
});
|