✔️ Fix tests

This commit is contained in:
Jan Oberhauser 2019-08-09 12:19:28 +02:00
parent 14f3d2f9c7
commit 281e943dcc
5 changed files with 274 additions and 247 deletions

View file

@ -11,7 +11,6 @@ import {
ITriggerFunctions as ITriggerFunctionsBase, ITriggerFunctions as ITriggerFunctionsBase,
IWebhookFunctions as IWebhookFunctionsBase, IWebhookFunctions as IWebhookFunctionsBase,
IWorkflowSettings as IWorkflowSettingsWorkflow, IWorkflowSettings as IWorkflowSettingsWorkflow,
WorkflowExecuteMode,
} from 'n8n-workflow'; } from 'n8n-workflow';

View file

@ -3,7 +3,6 @@ import {
IHookFunctions, IHookFunctions,
ILoadOptionsFunctions, ILoadOptionsFunctions,
IWorkflowSettings, IWorkflowSettings,
WorkflowExecute,
BINARY_ENCODING, BINARY_ENCODING,
} from './'; } from './';
@ -12,7 +11,6 @@ import {
IContextObject, IContextObject,
ICredentialDataDecryptedObject, ICredentialDataDecryptedObject,
IDataObject, IDataObject,
IExecuteData,
IExecuteFunctions, IExecuteFunctions,
IExecuteSingleFunctions, IExecuteSingleFunctions,
INode, INode,

View file

@ -5,7 +5,7 @@ import {
INodeParameters, INodeParameters,
INodeType, INodeType,
INodeTypes, INodeTypes,
INodeTypesObject, INodeTypeData,
IRun, IRun,
ITaskData, ITaskData,
IWorkflowExecuteAdditionalData, IWorkflowExecuteAdditionalData,
@ -19,8 +19,10 @@ import {
class NodeTypesClass implements INodeTypes { class NodeTypesClass implements INodeTypes {
nodeTypes: INodeTypesObject = { nodeTypes: INodeTypeData = {
'n8n-nodes-base.merge': { 'n8n-nodes-base.merge': {
sourcePath: '',
type: {
description: { description: {
displayName: 'Merge', displayName: 'Merge',
name: 'merge', name: 'merge',
@ -112,7 +114,10 @@ class NodeTypesClass implements INodeTypes {
return [returnData]; return [returnData];
} }
}, },
},
'n8n-nodes-base.set': { 'n8n-nodes-base.set': {
sourcePath: '',
type: {
description: { description: {
displayName: 'Set', displayName: 'Set',
name: 'set', name: 'set',
@ -171,19 +176,30 @@ class NodeTypesClass implements INodeTypes {
execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> { execute(this: IExecuteFunctions): Promise<INodeExecutionData[][]> {
const items = this.getInputData(); const items = this.getInputData();
const returnData: INodeExecutionData[] = [];
let item: INodeExecutionData; let item: INodeExecutionData;
for (let itemIndex = 0; itemIndex < items.length; itemIndex++) { for (let itemIndex = 0; itemIndex < items.length; itemIndex++) {
item = items[itemIndex]; item = items[itemIndex];
const newItem: INodeExecutionData = {
json: JSON.parse(JSON.stringify(item.json)),
};
// Add number values // Add number values
(this.getNodeParameter('values.number', itemIndex, []) as INodeParameters[]).forEach((setItem) => { (this.getNodeParameter('values.number', itemIndex, []) as INodeParameters[]).forEach((setItem) => {
set(item.json, setItem.name as string, setItem.value); set(newItem.json, setItem.name as string, setItem.value);
}); });
returnData.push(newItem);
} }
return this.prepareOutputData(items); return this.prepareOutputData(returnData);
} }
}, },
},
'n8n-nodes-base.start': { 'n8n-nodes-base.start': {
sourcePath: '',
type: {
description: { description: {
displayName: 'Start', displayName: 'Start',
name: 'start', name: 'start',
@ -204,16 +220,17 @@ class NodeTypesClass implements INodeTypes {
return this.prepareOutputData(items); return this.prepareOutputData(items);
}, },
}, },
},
}; };
async init(nodeTypes: INodeTypesObject): Promise<void> { } async init(nodeTypes: INodeTypeData): Promise<void> { }
getAll(): INodeType[] { getAll(): INodeType[] {
return Object.values(this.nodeTypes); return Object.values(this.nodeTypes).map((data) => data.type);
} }
getByName(nodeType: string): INodeType { getByName(nodeType: string): INodeType {
return this.nodeTypes[nodeType]; return this.nodeTypes[nodeType].type;
} }
} }
@ -235,12 +252,12 @@ export function WorkflowExecuteAdditionalData(waitPromise: IDeferredPromise<IRun
credentials: {}, credentials: {},
hooks: { hooks: {
nodeExecuteAfter: [ nodeExecuteAfter: [
async (executionId: string, nodeName: string, data: ITaskData): Promise<void> => { async (nodeName: string, data: ITaskData): Promise<void> => {
nodeExecutionOrder.push(nodeName); nodeExecutionOrder.push(nodeName);
}, },
], ],
workflowExecuteAfter: [ workflowExecuteAfter: [
async (fullRunData: IRun, executionId: string): Promise<void> => { async (fullRunData: IRun): Promise<void> => {
waitPromise.resolve(fullRunData); waitPromise.resolve(fullRunData);
}, },
], ],

View file

@ -587,11 +587,14 @@ describe('WorkflowExecute', () => {
const workflowExecute = new WorkflowExecute(additionalData, executionMode); const workflowExecute = new WorkflowExecute(additionalData, executionMode);
const executionId = await workflowExecute.run(workflowInstance, undefined); const executionData = await workflowExecute.run(workflowInstance, undefined);
expect(executionId).toBeDefined();
const result = await waitPromise.promise(); const result = await waitPromise.promise();
// Check if the data from WorkflowExecute is identical to data received
// by the webhooks
expect(executionData).toEqual(result);
// Check if the output data of the nodes is correct // Check if the output data of the nodes is correct
for (const nodeName of Object.keys(testData.output.nodeData)) { for (const nodeName of Object.keys(testData.output.nodeData)) {
if (result.data.resultData.runData[nodeName] === undefined) { if (result.data.resultData.runData[nodeName] === undefined) {

View file

@ -1,13 +1,19 @@
import { import {
INodeType, INodeType,
INodeTypes, INodeTypes,
INodeTypesObject, INodeTypeData,
} from '../src'; } from '../src';
export interface INodeTypesObject {
[key: string]: INodeType;
}
class NodeTypesClass implements INodeTypes { class NodeTypesClass implements INodeTypes {
nodeTypes: INodeTypesObject = { nodeTypes: INodeTypeData = {
'test.set': { 'test.set': {
sourcePath: '',
type: {
description: { description: {
displayName: 'Set', displayName: 'Set',
name: 'set', name: 'set',
@ -35,8 +41,11 @@ class NodeTypesClass implements INodeTypes {
} }
] ]
} }
}
}, },
'test.setMulti': { 'test.setMulti': {
sourcePath: '',
type: {
description: { description: {
displayName: 'Set Multi', displayName: 'Set Multi',
name: 'setMulti', name: 'setMulti',
@ -83,17 +92,18 @@ class NodeTypesClass implements INodeTypes {
}, },
] ]
} }
}
}, },
}; };
async init(nodeTypes: INodeTypesObject): Promise<void> { } async init(nodeTypes: INodeTypeData): Promise<void> { }
getAll(): INodeType[] { getAll(): INodeType[] {
return Object.values(this.nodeTypes); return Object.values(this.nodeTypes).map((data) => data.type);
} }
getByName(nodeType: string): INodeType { getByName(nodeType: string): INodeType {
return this.nodeTypes[nodeType]; return this.nodeTypes[nodeType].type;
} }
} }