mirror of
https://github.com/n8n-io/n8n.git
synced 2024-11-10 06:34:05 -08:00
test(Read Binary Files Node): Unit tests (no-changelog) (#5459)
* ✅ add Read Binary Files tests * ⚡️updated ReadBinaryFiles test * fix test result comparison * fix test result comparison --------- Co-authored-by: Michael Kret <michael.k@radency.com>
This commit is contained in:
parent
0673a39fa0
commit
14bcd4c2f7
|
@ -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);
|
||||
});
|
||||
}
|
||||
});
|
|
@ -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": []
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"title": "Lorem Ipsum"
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"title": "Ipsum Lorem"
|
||||
}
|
Loading…
Reference in a new issue