fix( Switch Node): Disable expressions for Number of Outputs in v3.3 (#19075)

Co-authored-by: Roman Davydchuk <roman.davydchuk@n8n.io>
This commit is contained in:
Shireen Missi
2025-09-12 11:46:09 +02:00
committed by GitHub
parent a13961179f
commit f37e9da13a
3 changed files with 70 additions and 2 deletions

View File

@@ -1,5 +1,57 @@
import { NodeTestHarness } from '@nodes-testing/node-test-harness';
import type { INodeTypeBaseDescription } from 'n8n-workflow';
import { SwitchV3 } from '../SwitchV3.node';
describe('Execute Switch Node', () => {
new NodeTestHarness().setupTests();
describe('Version-specific behavior', () => {
const baseDescription: INodeTypeBaseDescription = {
displayName: 'Switch',
name: 'n8n-nodes-base.switch',
group: ['transform'],
description: 'Route items to different outputs',
};
it('should have two numberOutputs parameters with different version conditions', () => {
const switchNode = new SwitchV3(baseDescription);
const numberOutputsParams = switchNode.description.properties.filter(
(prop) => prop.name === 'numberOutputs',
);
expect(numberOutputsParams).toHaveLength(2);
});
it('should have noDataExpression: true for version 3.3+ numberOutputs parameter', () => {
const switchNode = new SwitchV3(baseDescription);
const numberOutputsParamWithNoExpression = switchNode.description.properties.find(
(prop) => prop.name === 'numberOutputs' && prop.noDataExpression === true,
);
expect(numberOutputsParamWithNoExpression).toBeDefined();
expect(numberOutputsParamWithNoExpression?.noDataExpression).toBe(true);
expect(numberOutputsParamWithNoExpression?.displayOptions?.show?.['@version']).toEqual([
{ _cnd: { gte: 3.3 } },
]);
});
it('should have numberOutputs parameter without noDataExpression for older versions', () => {
const switchNode = new SwitchV3(baseDescription);
const numberOutputsParamWithoutNoExpression = switchNode.description.properties.find(
(prop) => prop.name === 'numberOutputs' && !prop.noDataExpression,
);
expect(numberOutputsParamWithoutNoExpression).toBeDefined();
expect(numberOutputsParamWithoutNoExpression?.noDataExpression).toBeUndefined();
expect(numberOutputsParamWithoutNoExpression?.displayOptions?.show?.['@version']).toEqual([
{ _cnd: { lt: 3.3 } },
]);
});
it('should include version 3.3 in supported versions', () => {
const switchNode = new SwitchV3(baseDescription);
expect(switchNode.description.version).toContain(3.3);
});
});
});