mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-14 08:34:07 -08:00
5b9c650e55
* 🧪 Add base for building unit testing within nodes * Improve helper functions * 🧪 If node test * 🧪 Airtable node test * 🧪 If node test improvements * 🧪 Airtable node test improvements * ♻️ cleanup node unit tests * ♻️ refactor getting node result data to use helper method * ⚡ removed unused variables * ♻️ Helper to read json files --------- Co-authored-by: Marcus <marcus@n8n.io> Co-authored-by: Michael Kret <michael.k@radency.com>
59 lines
1.5 KiB
TypeScript
59 lines
1.5 KiB
TypeScript
import { INodeType } from 'n8n-workflow';
|
|
import * as Helpers from '../Helpers';
|
|
import { WorkflowTestData } from '../types';
|
|
|
|
import { ManualTrigger } from '../../../nodes/ManualTrigger/ManualTrigger.node';
|
|
import { Set } from '../../../nodes/Set/Set.node';
|
|
import { If } from '../../../nodes/If/If.node';
|
|
import { NoOp } from '../../../nodes/NoOp/NoOp.node';
|
|
import { Code } from '../../../nodes/Code/Code.node';
|
|
|
|
import { executeWorkflow } from '../ExecuteWorkflow';
|
|
|
|
describe('Execute If Node', () => {
|
|
const tests: Array<WorkflowTestData> = [
|
|
{
|
|
description: 'should execute IF node true/false boolean',
|
|
input: {
|
|
workflowData: Helpers.readJsonFileSync('test/nodes/If/workflow.json'),
|
|
},
|
|
output: {
|
|
nodeData: {
|
|
'On True': [
|
|
[
|
|
{
|
|
value: true,
|
|
},
|
|
],
|
|
],
|
|
'On False': [
|
|
[
|
|
{
|
|
value: false,
|
|
},
|
|
],
|
|
],
|
|
},
|
|
},
|
|
},
|
|
];
|
|
|
|
const nodes: INodeType[] = [new ManualTrigger(), new Code(), new Set(), new If(), new NoOp()];
|
|
const nodeTypes = Helpers.setup(nodes);
|
|
|
|
for (const testData of tests) {
|
|
test(testData.description, async () => {
|
|
// execute workflow
|
|
const { result } = await executeWorkflow(testData, nodeTypes);
|
|
|
|
// check if result node data matches expected test data
|
|
const resultNodeData = Helpers.getResultNodeData(result, testData);
|
|
resultNodeData.forEach(({ nodeName, resultData }) =>
|
|
expect(resultData).toEqual(testData.output.nodeData[nodeName]),
|
|
);
|
|
|
|
expect(result.finished).toEqual(true);
|
|
});
|
|
}
|
|
});
|