test(iCalendar Node): Unit tests (no-changelog)

This commit is contained in:
Michael Kret 2023-02-10 12:55:07 +02:00 committed by GitHub
parent 649c7ccfb1
commit 40879f67cb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 131 additions and 0 deletions

View file

@ -0,0 +1,72 @@
/* eslint-disable @typescript-eslint/no-loop-func */
import type { WorkflowTestData } from '../../../../test/nodes/types';
import {
getResultNodeData,
setup,
readJsonFileSync,
initBinaryDataManager,
} from '../../../../test/nodes/Helpers';
import { executeWorkflow } from '../../../../test/nodes/ExecuteWorkflow';
describe('Execute iCalendar Node', () => {
beforeEach(async () => {
await initBinaryDataManager();
});
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);
});
}
});

View file

@ -0,0 +1,59 @@
{
"name": "iCalendar test",
"nodes": [
{
"parameters": {},
"id": "987fdc91-f1a7-4882-9975-3d41e183b7f3",
"name": "When clicking \"Execute Workflow\"",
"type": "n8n-nodes-base.manualTrigger",
"typeVersion": 1,
"position": [780, 400]
},
{
"parameters": {
"title": "new event",
"start": "2023-02-27T22:00:00.000Z",
"end": "2023-02-27T22:00:00.000Z",
"allDay": true,
"additionalFields": {
"attendeesUi": {
"attendeeValues": [
{
"name": "Person",
"email": "person1@email.com"
}
]
},
"calName": "default"
}
},
"id": "afe2a25a-d7a3-41f5-a9be-7a2ea3bb260d",
"name": "iCalendar",
"type": "n8n-nodes-base.iCal",
"typeVersion": 1,
"position": [1080, 400]
}
],
"pinData": {},
"connections": {
"When clicking \"Execute Workflow\"": {
"main": [
[
{
"node": "iCalendar",
"type": "main",
"index": 0
}
]
]
}
},
"active": false,
"settings": {},
"versionId": "6c0ed4a8-3c83-44e1-957c-bbe7ef57ebd3",
"id": "116",
"meta": {
"instanceId": "36203ea1ce3cef713fa25999bd9874ae26b9e4c2c3a90a365f2882a154d031d0"
},
"tags": []
}