mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 01:56:46 +00:00
test(core): Add basic expression tests (no-changelog) (#5439)
* test(core): add basic expression tests * test: fix $if test not working properly
This commit is contained in:
@@ -6,6 +6,15 @@ import { DateTime, Duration, Interval } from 'luxon';
|
||||
import { Expression } from '@/Expression';
|
||||
import { Workflow } from '@/Workflow';
|
||||
import * as Helpers from './Helpers';
|
||||
import { baseFixtures } from './ExpressionFixtures/base';
|
||||
import {
|
||||
IConnections,
|
||||
IExecuteData,
|
||||
INode,
|
||||
INodeExecutionData,
|
||||
IRunExecutionData,
|
||||
ITaskData,
|
||||
} from '@/Interfaces';
|
||||
|
||||
describe('Expression', () => {
|
||||
describe('getParameterValue()', () => {
|
||||
@@ -147,4 +156,42 @@ describe('Expression', () => {
|
||||
expect(evaluate('={{Symbol(1).toString()}}')).toEqual(Symbol(1).toString());
|
||||
});
|
||||
});
|
||||
|
||||
describe('Test all expression value fixtures', () => {
|
||||
const nodeTypes = Helpers.NodeTypes();
|
||||
const workflow = new Workflow({
|
||||
nodes: [
|
||||
{
|
||||
name: 'node',
|
||||
typeVersion: 1,
|
||||
type: 'test.set',
|
||||
id: 'uuid-1234',
|
||||
position: [0, 0],
|
||||
parameters: {},
|
||||
},
|
||||
],
|
||||
connections: {},
|
||||
active: false,
|
||||
nodeTypes,
|
||||
});
|
||||
|
||||
const expression = new Expression(workflow);
|
||||
|
||||
const evaluate = (value: string, data: INodeExecutionData[]) => {
|
||||
return expression.getParameterValue(value, null, 0, 0, 'node', data, 'manual', '', {});
|
||||
};
|
||||
|
||||
for (const t of baseFixtures) {
|
||||
if (!t.tests.some((test) => test.type === 'evaluation')) {
|
||||
continue;
|
||||
}
|
||||
test(t.expression, () => {
|
||||
for (const test of t.tests.filter((test) => test.type === 'evaluation')) {
|
||||
expect(evaluate(t.expression, test.input.map((d) => ({ json: d })) as any)).toStrictEqual(
|
||||
test.output,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user