n8n/packages/nodes-base/nodes/ICalendar/test/node/ICalendar.test.ts
Iván Ovejero 6d6e2488c6
refactor(core): Generalize binary data manager interface (no-changelog) (#7164)
Depends on: #7092 | Story:
[PAY-768](https://linear.app/n8n/issue/PAY-768)

This PR: 
- Generalizes the `IBinaryDataManager` interface.
- Adjusts `Filesystem.ts` to satisfy the interface.
- Sets up an S3 client stub to be filled in in the next PR.
- Turns `BinaryDataManager` into an injectable service.
- Adjusts the config schema and adds new validators.

Note that the PR looks large but all the main changes are in
`packages/core/src/binaryData`.

Out of scope:
- `BinaryDataManager` (now `BinaryDataService`) and `Filesystem.ts` (now
`fs.client.ts`) were slightly refactored for maintainability, but fully
overhauling them is **not** the focus of this PR, which is meant to
clear the way for the S3 implementation. Future improvements for these
two should include setting up a backwards-compatible dir structure that
makes it easier to locate binary data files to delete, removing
duplication, simplifying cloning methods, using integers for binary data
size instead of `prettyBytes()`, writing tests for existing binary data
logic, etc.

---------

Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
2023-09-22 17:22:12 +02:00

73 lines
2.2 KiB
TypeScript

/* eslint-disable @typescript-eslint/no-loop-func */
import type { WorkflowTestData } from '@test/nodes/types';
import {
getResultNodeData,
setup,
readJsonFileSync,
initBinaryDataService,
} from '@test/nodes/Helpers';
import { executeWorkflow } from '@test/nodes/ExecuteWorkflow';
describe('Execute iCalendar Node', () => {
beforeEach(async () => {
await initBinaryDataService();
});
const workflowData = readJsonFileSync('nodes/ICalendar/test/node/workflow.iCalendar.json');
const tests: WorkflowTestData[] = [
{
description: 'nodes/ICalendar/test/node/workflow.iCalendar.json',
input: {
workflowData,
},
output: {
nodeData: {
iCalendar: [
[
{
json: {},
binary: {
data: {
mimeType: 'text/calendar',
fileType: 'text',
fileExtension: 'ics',
data: 'QkVHSU46VkNBTEVOREFSDQpWRVJTSU9OOjIuMA0KQ0FMU0NBTEU6R1JFR09SSUFODQpQUk9ESUQ6YWRhbWdpYmJvbnMvaWNzDQpNRVRIT0Q6UFVCTElTSA0KWC1XUi1DQUxOQU1FOmRlZmF1bHQNClgtUFVCTElTSEVELVRUTDpQVDFIDQpCRUdJTjpWRVZFTlQNClVJRDpMWC1zckVYdkI1MXA1ZUxNS1gwTnkNClNVTU1BUlk6bmV3IGV2ZW50DQpEVFNUQU1QOjIwMjMwMjEwVDA5MzYwMFoNCkRUU1RBUlQ7VkFMVUU9REFURToyMDIzMDIyOA0KRFRFTkQ7VkFMVUU9REFURToyMDIzMDMwMQ0KQVRURU5ERUU7UlNWUD1GQUxTRTtDTj1QZXJzb246bWFpbHRvOnBlcnNvbjFAZW1haWwuY29tDQpFTkQ6VkVWRU5UDQpFTkQ6VkNBTEVOREFSDQo=',
fileName: 'event.ics',
fileSize: '359 B',
},
},
},
],
],
},
},
},
];
const nodeTypes = setup(tests);
for (const testData of tests) {
test(testData.description, async () => {
const { result } = await executeWorkflow(testData, nodeTypes);
const resultNodeData = getResultNodeData(result, testData);
resultNodeData.forEach(({ nodeName, resultData }) => {
//@ts-ignore
expect(resultData[0][0].binary.data.data.length).toEqual(
testData.output.nodeData[nodeName][0][0].binary.data.data.length,
);
//uid every time would be different, so we need to delete it in order to compare objects
//@ts-ignore
delete resultData[0][0].binary.data.data;
delete testData.output.nodeData[nodeName][0][0].binary.data.data;
expect(resultData).toEqual(testData.output.nodeData[nodeName]);
});
expect(result.finished).toEqual(true);
});
}
});