mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
refactor(core): Extract ExecuteContext out of NodeExecutionFunctions (no-changelog) (#11853)
This commit is contained in:
committed by
GitHub
parent
3aa72f613f
commit
75e2b6fd9e
@@ -2,8 +2,6 @@ import { mkdtempSync, readFileSync } from 'fs';
|
||||
import type { IncomingMessage } from 'http';
|
||||
import type { Agent } from 'https';
|
||||
import { mock } from 'jest-mock-extended';
|
||||
import toPlainObject from 'lodash/toPlainObject';
|
||||
import { DateTime } from 'luxon';
|
||||
import type {
|
||||
IBinaryData,
|
||||
IHttpRequestMethods,
|
||||
@@ -12,11 +10,9 @@ import type {
|
||||
IRequestOptions,
|
||||
ITaskDataConnections,
|
||||
IWorkflowExecuteAdditionalData,
|
||||
NodeParameterValue,
|
||||
Workflow,
|
||||
WorkflowHooks,
|
||||
} from 'n8n-workflow';
|
||||
import { ExpressionError } from 'n8n-workflow';
|
||||
import nock from 'nock';
|
||||
import { tmpdir } from 'os';
|
||||
import { join } from 'path';
|
||||
@@ -26,9 +22,7 @@ import Container from 'typedi';
|
||||
import { BinaryDataService } from '@/BinaryData/BinaryData.service';
|
||||
import { InstanceSettings } from '@/InstanceSettings';
|
||||
import {
|
||||
cleanupParameterData,
|
||||
copyInputItems,
|
||||
ensureType,
|
||||
getBinaryDataBuffer,
|
||||
isFilePathBlocked,
|
||||
parseIncomingMessage,
|
||||
@@ -470,39 +464,6 @@ describe('NodeExecuteFunctions', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('cleanupParameterData', () => {
|
||||
it('should stringify Luxon dates in-place', () => {
|
||||
const input = { x: 1, y: DateTime.now() as unknown as NodeParameterValue };
|
||||
expect(typeof input.y).toBe('object');
|
||||
cleanupParameterData(input);
|
||||
expect(typeof input.y).toBe('string');
|
||||
});
|
||||
|
||||
it('should stringify plain Luxon dates in-place', () => {
|
||||
const input = {
|
||||
x: 1,
|
||||
y: toPlainObject(DateTime.now()),
|
||||
};
|
||||
expect(typeof input.y).toBe('object');
|
||||
cleanupParameterData(input);
|
||||
expect(typeof input.y).toBe('string');
|
||||
});
|
||||
|
||||
it('should handle objects with nameless constructors', () => {
|
||||
const input = { x: 1, y: { constructor: {} } as NodeParameterValue };
|
||||
expect(typeof input.y).toBe('object');
|
||||
cleanupParameterData(input);
|
||||
expect(typeof input.y).toBe('object');
|
||||
});
|
||||
|
||||
it('should handle objects without a constructor', () => {
|
||||
const input = { x: 1, y: { constructor: undefined } as unknown as NodeParameterValue };
|
||||
expect(typeof input.y).toBe('object');
|
||||
cleanupParameterData(input);
|
||||
expect(typeof input.y).toBe('object');
|
||||
});
|
||||
});
|
||||
|
||||
describe('copyInputItems', () => {
|
||||
it('should pick only selected properties', () => {
|
||||
const output = copyInputItems(
|
||||
@@ -588,83 +549,6 @@ describe('NodeExecuteFunctions', () => {
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
describe('ensureType', () => {
|
||||
it('throws error for null value', () => {
|
||||
expect(() => ensureType('string', null, 'myParam')).toThrowError(
|
||||
new ExpressionError("Parameter 'myParam' must not be null"),
|
||||
);
|
||||
});
|
||||
|
||||
it('throws error for undefined value', () => {
|
||||
expect(() => ensureType('string', undefined, 'myParam')).toThrowError(
|
||||
new ExpressionError("Parameter 'myParam' could not be 'undefined'"),
|
||||
);
|
||||
});
|
||||
|
||||
it('returns string value without modification', () => {
|
||||
const value = 'hello';
|
||||
const expectedValue = value;
|
||||
const result = ensureType('string', value, 'myParam');
|
||||
expect(result).toBe(expectedValue);
|
||||
});
|
||||
|
||||
it('returns number value without modification', () => {
|
||||
const value = 42;
|
||||
const expectedValue = value;
|
||||
const result = ensureType('number', value, 'myParam');
|
||||
expect(result).toBe(expectedValue);
|
||||
});
|
||||
|
||||
it('returns boolean value without modification', () => {
|
||||
const value = true;
|
||||
const expectedValue = value;
|
||||
const result = ensureType('boolean', value, 'myParam');
|
||||
expect(result).toBe(expectedValue);
|
||||
});
|
||||
|
||||
it('converts object to string if toType is string', () => {
|
||||
const value = { name: 'John' };
|
||||
const expectedValue = JSON.stringify(value);
|
||||
const result = ensureType('string', value, 'myParam');
|
||||
expect(result).toBe(expectedValue);
|
||||
});
|
||||
|
||||
it('converts string to number if toType is number', () => {
|
||||
const value = '10';
|
||||
const expectedValue = 10;
|
||||
const result = ensureType('number', value, 'myParam');
|
||||
expect(result).toBe(expectedValue);
|
||||
});
|
||||
|
||||
it('throws error for invalid conversion to number', () => {
|
||||
const value = 'invalid';
|
||||
expect(() => ensureType('number', value, 'myParam')).toThrowError(
|
||||
new ExpressionError("Parameter 'myParam' must be a number, but we got 'invalid'"),
|
||||
);
|
||||
});
|
||||
|
||||
it('parses valid JSON string to object if toType is object', () => {
|
||||
const value = '{"name": "Alice"}';
|
||||
const expectedValue = JSON.parse(value);
|
||||
const result = ensureType('object', value, 'myParam');
|
||||
expect(result).toEqual(expectedValue);
|
||||
});
|
||||
|
||||
it('throws error for invalid JSON string to object conversion', () => {
|
||||
const value = 'invalid_json';
|
||||
expect(() => ensureType('object', value, 'myParam')).toThrowError(
|
||||
new ExpressionError("Parameter 'myParam' could not be parsed"),
|
||||
);
|
||||
});
|
||||
|
||||
it('throws error for non-array value if toType is array', () => {
|
||||
const value = { name: 'Alice' };
|
||||
expect(() => ensureType('array', value, 'myParam')).toThrowError(
|
||||
new ExpressionError("Parameter 'myParam' must be an array, but we got object"),
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('isFilePathBlocked', () => {
|
||||
|
||||
Reference in New Issue
Block a user