mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 10:02:05 +00:00
fix: Prevent empty path in webhooks (#16864)
Co-authored-by: Roman Davydchuk <roman.davydchuk@n8n.io>
This commit is contained in:
@@ -21,8 +21,10 @@ import {
|
||||
isDefaultNodeName,
|
||||
makeNodeName,
|
||||
isTool,
|
||||
getNodeWebhookPath,
|
||||
} from '../src/node-helpers';
|
||||
import type { Workflow } from '../src/workflow';
|
||||
import { mock } from 'vitest-mock-extended';
|
||||
|
||||
describe('NodeHelpers', () => {
|
||||
describe('getNodeParameters', () => {
|
||||
@@ -4382,6 +4384,7 @@ describe('NodeHelpers', () => {
|
||||
test(testData.description, () => {
|
||||
// If this test has a custom mock return value, configure it
|
||||
if (testData.mockReturnValue) {
|
||||
// eslint-disable-next-line @typescript-eslint/unbound-method
|
||||
vi.mocked(workflowMock.expression.getSimpleParameterValue).mockReturnValueOnce(
|
||||
testData.mockReturnValue,
|
||||
);
|
||||
@@ -5611,4 +5614,48 @@ describe('NodeHelpers', () => {
|
||||
expect(result).toBe(false);
|
||||
});
|
||||
});
|
||||
describe('getNodeWebhookPath', () => {
|
||||
const mockWorkflowId = 'workflow-123';
|
||||
const mockPath = 'test-path';
|
||||
|
||||
it('should return path when restartWebhook is true', () => {
|
||||
const node = mock<INode>({ name: 'TestNode' });
|
||||
|
||||
const result = getNodeWebhookPath(mockWorkflowId, node, mockPath, false, true);
|
||||
|
||||
expect(result).toBe(mockPath);
|
||||
});
|
||||
|
||||
it('should return path when node has webhookId and isFullPath is true', () => {
|
||||
const node = mock<INode>({ name: 'TestNode', webhookId: 'webhook-456' });
|
||||
|
||||
const result = getNodeWebhookPath(mockWorkflowId, node, mockPath, true, false);
|
||||
|
||||
expect(result).toBe(mockPath);
|
||||
});
|
||||
|
||||
it('should return webhookId when node has webhookId, isFullPath is true, and path is empty', () => {
|
||||
const node = mock<INode>({ name: 'TestNode', webhookId: 'webhook-456' });
|
||||
|
||||
const result = getNodeWebhookPath(mockWorkflowId, node, '', true, false);
|
||||
|
||||
expect(result).toBe('webhook-456');
|
||||
});
|
||||
|
||||
it('should return webhookId/path when node has webhookId and isFullPath is false', () => {
|
||||
const node = mock<INode>({ name: 'TestNode', webhookId: 'webhook-456' });
|
||||
|
||||
const result = getNodeWebhookPath(mockWorkflowId, node, mockPath, false, false);
|
||||
|
||||
expect(result).toBe('webhook-456/test-path');
|
||||
});
|
||||
|
||||
it('should return workflowId/nodename/path when node has no webhookId', () => {
|
||||
const node = mock<INode>({ name: 'TestNode', webhookId: undefined });
|
||||
|
||||
const result = getNodeWebhookPath(mockWorkflowId, node, mockPath, false, false);
|
||||
|
||||
expect(result).toBe('workflow-123/testnode/test-path');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user