/* eslint-disable @typescript-eslint/no-loop-func */
import type { WorkflowTestData } from '@test/nodes/types';
import type { IDataObject } from 'n8n-workflow';

import {
	getResultNodeData,
	setup,
	initBinaryDataService,
	readJsonFileSync,
} from '@test/nodes/Helpers';
import { executeWorkflow } from '@test/nodes/ExecuteWorkflow';

import path from 'path';
import os from 'node:os';

if (os.platform() !== 'win32') {
	describe('Execute Compression Node', () => {
		beforeEach(async () => {
			await initBinaryDataService();
		});

		const workflowData = readJsonFileSync('nodes/Compression/test/node/workflow.compression.json');

		const node = workflowData.nodes.find((n: IDataObject) => n.name === 'Read Binary File');
		node.parameters.filePath = path.join(__dirname, 'lorem.txt');

		const tests: WorkflowTestData[] = [
			{
				description: 'nodes/Compression/test/node/workflow.compression.json',
				input: {
					workflowData,
				},
				output: {
					nodeData: {
						Compression1: [
							[
								{
									json: {},
									binary: {
										file_0: {
											mimeType: 'text/plain',
											fileType: 'text',
											fileExtension: 'txt',
											data: '[encoded data, 4096 characters]',
											fileName: 'lorem.txt',
											fileSize: '3.07 kB',
										},
									},
								},
							],
						],
					},
				},
			},
		];

		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 }) => {
					expect(resultData).toEqual(testData.output.nodeData[nodeName]);
				});

				expect(result.finished).toEqual(true);
			});
		}
	});
} else {
	describe('Execute Compression Node', () => {
		it('Skipped because compression results are different on platform win32', () => {
			expect(true).toBe(true);
		});
	});
}
