From 14bcd4c2f7908591c0b478ab5a1ab4f86fd1089e Mon Sep 17 00:00:00 2001 From: Marcus <56945030+maspio@users.noreply.github.com> Date: Mon, 8 May 2023 13:06:29 +0200 Subject: [PATCH] test(Read Binary Files Node): Unit tests (no-changelog) (#5459) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * ✅ add Read Binary Files tests * ⚡️updated ReadBinaryFiles test * fix test result comparison * fix test result comparison --------- Co-authored-by: Michael Kret --- .../test/ReadBinaryFiles.test.ts | 78 +++++++++++++++++++ .../test/ReadBinaryFiles.workflow.json | 45 +++++++++++ .../ReadBinaryFiles/test/data/sample.json | 3 + .../ReadBinaryFiles/test/data/sample2.json | 3 + 4 files changed, 129 insertions(+) create mode 100644 packages/nodes-base/nodes/ReadBinaryFiles/test/ReadBinaryFiles.test.ts create mode 100644 packages/nodes-base/nodes/ReadBinaryFiles/test/ReadBinaryFiles.workflow.json create mode 100644 packages/nodes-base/nodes/ReadBinaryFiles/test/data/sample.json create mode 100644 packages/nodes-base/nodes/ReadBinaryFiles/test/data/sample2.json diff --git a/packages/nodes-base/nodes/ReadBinaryFiles/test/ReadBinaryFiles.test.ts b/packages/nodes-base/nodes/ReadBinaryFiles/test/ReadBinaryFiles.test.ts new file mode 100644 index 0000000000..8c79fbe480 --- /dev/null +++ b/packages/nodes-base/nodes/ReadBinaryFiles/test/ReadBinaryFiles.test.ts @@ -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); + }); + } +}); diff --git a/packages/nodes-base/nodes/ReadBinaryFiles/test/ReadBinaryFiles.workflow.json b/packages/nodes-base/nodes/ReadBinaryFiles/test/ReadBinaryFiles.workflow.json new file mode 100644 index 0000000000..7fecfa0502 --- /dev/null +++ b/packages/nodes-base/nodes/ReadBinaryFiles/test/ReadBinaryFiles.workflow.json @@ -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": [] +} diff --git a/packages/nodes-base/nodes/ReadBinaryFiles/test/data/sample.json b/packages/nodes-base/nodes/ReadBinaryFiles/test/data/sample.json new file mode 100644 index 0000000000..572ecfcee2 --- /dev/null +++ b/packages/nodes-base/nodes/ReadBinaryFiles/test/data/sample.json @@ -0,0 +1,3 @@ +{ + "title": "Lorem Ipsum" +} diff --git a/packages/nodes-base/nodes/ReadBinaryFiles/test/data/sample2.json b/packages/nodes-base/nodes/ReadBinaryFiles/test/data/sample2.json new file mode 100644 index 0000000000..f9bb627b46 --- /dev/null +++ b/packages/nodes-base/nodes/ReadBinaryFiles/test/data/sample2.json @@ -0,0 +1,3 @@ +{ + "title": "Ipsum Lorem" +}