fix(n8n Form Trigger Node): Update error in validateResponseModeConfiguration (no-changelog) (#13162)

This commit is contained in:
Michael Kret
2025-02-11 14:52:21 +02:00
committed by GitHub
parent 78644b0ec7
commit 6abb1f9374
3 changed files with 74 additions and 3 deletions

View File

@@ -16,6 +16,7 @@ import {
resolveRawData,
isFormConnected,
sanitizeHtml,
validateResponseModeConfiguration,
} from '../utils';
describe('FormTrigger, parseFormDescription', () => {
@@ -939,3 +940,58 @@ describe('FormTrigger, isFormConnected', () => {
expect(result).toBe(true);
});
});
describe('validateResponseModeConfiguration', () => {
let webhookFunctions: ReturnType<typeof mock<IWebhookFunctions>>;
beforeEach(() => {
webhookFunctions = mock<IWebhookFunctions>();
webhookFunctions.getNode.mockReturnValue({
name: 'TestNode',
typeVersion: 2.2,
} as INode);
webhookFunctions.getChildNodes.mockReturnValue([]);
});
test('throws error if responseMode is "responseNode" but no Respond to Webhook node is connected', () => {
webhookFunctions.getNodeParameter.mockReturnValue('responseNode');
expect(() => validateResponseModeConfiguration(webhookFunctions)).toThrow(
'No Respond to Webhook node found in the workflow',
);
});
test('throws error if "Respond to Webhook" node is connected but "responseMode" is not "responseNode" in typeVersion <= 2.1', () => {
webhookFunctions.getNodeParameter.mockReturnValue('onReceived');
webhookFunctions.getNode.mockReturnValue({
name: 'TestNode',
typeVersion: 2.1,
} as INode);
webhookFunctions.getChildNodes.mockReturnValue([
{ type: 'n8n-nodes-base.respondToWebhook' } as NodeTypeAndVersion,
]);
expect(() => validateResponseModeConfiguration(webhookFunctions)).toThrow(
'TestNode node not correctly configured',
);
});
test('throws error if "Respond to Webhook" node is connected, version >= 2.2', () => {
webhookFunctions.getNodeParameter.mockReturnValue('responseNode');
webhookFunctions.getChildNodes.mockReturnValue([
{ type: 'n8n-nodes-base.respondToWebhook' } as NodeTypeAndVersion,
]);
expect(() => validateResponseModeConfiguration(webhookFunctions)).toThrow(
'The "Respond to Webhook" node is not supported in workflows initiated by the "n8n Form Trigger"',
);
});
test('does not throw an error mode in not "responseNode" and no "Respond to Webhook" node is connected', () => {
webhookFunctions.getNodeParameter.mockReturnValue('onReceived');
expect(() => validateResponseModeConfiguration(webhookFunctions)).not.toThrow();
});
});