forked from Jordan-Hall/n8n
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(Read Binary Files Node): Unit tests (no-changelog) (n8n-io#5459)
* ✅ 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
1 parent
0673a39
commit 14bcd4c
Showing
4 changed files
with
129 additions
and
0 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
packages/nodes-base/nodes/ReadBinaryFiles/test/ReadBinaryFiles.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
} | ||
}); |
45 changes: 45 additions & 0 deletions
45
packages/nodes-base/nodes/ReadBinaryFiles/test/ReadBinaryFiles.workflow.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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": [] | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/nodes-base/nodes/ReadBinaryFiles/test/data/sample.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"title": "Lorem Ipsum" | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/nodes-base/nodes/ReadBinaryFiles/test/data/sample2.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"title": "Ipsum Lorem" | ||
} |