✔️ 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,
IWebhookFunctions as IWebhookFunctionsBase,
IWorkflowSettings as IWorkflowSettingsWorkflow,
WorkflowExecuteMode,
} from 'n8n-workflow';

View file

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

View file

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

View file

@ -587,11 +587,14 @@ describe('WorkflowExecute', () => {
const workflowExecute = new WorkflowExecute(additionalData, executionMode);
const executionId = await workflowExecute.run(workflowInstance, undefined);
expect(executionId).toBeDefined();
const executionData = await workflowExecute.run(workflowInstance, undefined);
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
for (const nodeName of Object.keys(testData.output.nodeData)) {
if (result.data.resultData.runData[nodeName] === undefined) {

View file

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