Skip to content

Commit

Permalink
test(Read Binary Files Node): Unit tests (no-changelog) (n8n-io#5459)
Browse files Browse the repository at this point in the history
* ✅ add Read Binary Files tests

* ⚡️updated ReadBinaryFiles test

* fix test result comparison

* fix test result comparison

---------

Co-authored-by: Michael Kret <[email protected]>
  • Loading branch information
maspio and michael-radency authored May 8, 2023
1 parent 0673a39 commit 14bcd4c
Show file tree
Hide file tree
Showing 4 changed files with 129 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/* eslint-disable @typescript-eslint/no-loop-func */
import * as Helpers from '../../../test/nodes/Helpers';
import type { WorkflowTestData } from '../../../test/nodes/types';
import { executeWorkflow } from '../../../test/nodes/ExecuteWorkflow';
import path from 'path';

describe('Test Read Binary Files Node', () => {
beforeEach(async () => {
await Helpers.initBinaryDataManager();
});

const workflow = Helpers.readJsonFileSync(
'nodes/ReadBinaryFiles/test/ReadBinaryFiles.workflow.json',
);
const node = workflow.nodes.find((n: any) => n.name === 'Read Binary Files');
const dir = path.join(__dirname, 'data').split('\\').join('/');
node.parameters.fileSelector = `${dir}/*.json`;

const tests: WorkflowTestData[] = [
{
description: 'nodes/ReadBinaryFiles/test/ReadBinaryFiles.workflow.json',
input: {
workflowData: workflow,
},
output: {
nodeData: {
'Read Binary Files': [
[
{
binary: {
data: {
mimeType: 'application/json',
fileType: 'json',
fileExtension: 'json',
data: 'ewoJInRpdGxlIjogIkxvcmVtIElwc3VtIgp9Cg==',
directory: dir,
fileName: 'sample.json',
fileSize: '28 B',
},
},
json: {},
},
{
binary: {
data: {
mimeType: 'application/json',
fileType: 'json',
fileExtension: 'json',
data: 'ewoJInRpdGxlIjogIklwc3VtIExvcmVtIgp9Cg==',
directory: dir,
fileName: 'sample2.json',
fileSize: '28 B',
},
},
json: {},
},
],
],
},
},
},
];

const nodeTypes = Helpers.setup(tests);

for (const testData of tests) {
test(testData.description, async () => {
const { result } = await executeWorkflow(testData, nodeTypes);

const resultNodeData = Helpers.getResultNodeData(result, testData);
resultNodeData.forEach(({ nodeName, resultData }) =>
expect(resultData).toEqual(testData.output.nodeData[nodeName]),
);

expect(result.finished).toEqual(true);
});
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
{
"name": "Read Binary Files test",
"nodes": [
{
"parameters": {},
"id": "90c8a569-5351-44a4-9073-b8d114108676",
"name": "When clicking \"Execute Workflow\"",
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [680, 640]
},
{
"parameters": {
"fileSelector": "C:/Test/data/*.json"
},
"id": "b4974ce2-9bc8-4242-b6f9-86b43608b521",
"name": "Read Binary Files",
"type": "n8n-nodes-base.readBinaryFiles",
"typeVersion": 1,
"position": [880, 640]
}
],
"pinData": {},
"connections": {
"When clicking \"Execute Workflow\"": {
"main": [
[
{
"node": "Read Binary Files",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {},
"versionId": "973f1d06-f5e6-4e05-8136-02f6518ad37b",
"id": "190",
"meta": {
"instanceId": "104a4d08d8897b8bdeb38aaca515021075e0bd8544c983c2bb8c86e6a8e6081c"
},
"tags": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"title": "Lorem Ipsum"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"title": "Ipsum Lorem"
}

0 comments on commit 14bcd4c

Please sign in to comment.