mirror of
https://github.com/Abdulazizzn/n8n-enterprise-unlocked.git
synced 2025-12-17 18:12:04 +00:00
fix(core): Return correct trigger count for nodes with multiple webhooks (#14300)
Co-authored-by: Danny Martini <danny@n8n.io> Co-authored-by: कारतोफ्फेलस्क्रिप्ट™ <aditya@netroy.in>
This commit is contained in:
@@ -1,12 +1,20 @@
|
||||
import { Container } from '@n8n/di';
|
||||
import { mock } from 'jest-mock-extended';
|
||||
import { Logger } from 'n8n-core';
|
||||
import { FormTrigger } from 'n8n-nodes-base/nodes/Form/FormTrigger.node';
|
||||
import { ScheduleTrigger } from 'n8n-nodes-base/nodes/Schedule/ScheduleTrigger.node';
|
||||
import { NodeApiError, Workflow } from 'n8n-workflow';
|
||||
import type { IWebhookData, IWorkflowBase, WorkflowActivateMode } from 'n8n-workflow';
|
||||
import type {
|
||||
IWebhookData,
|
||||
IWorkflowBase,
|
||||
WorkflowActivateMode,
|
||||
INodeTypeData,
|
||||
} from 'n8n-workflow';
|
||||
|
||||
import { ActiveExecutions } from '@/active-executions';
|
||||
import { ActiveWorkflowManager } from '@/active-workflow-manager';
|
||||
import type { WebhookEntity } from '@/databases/entities/webhook-entity';
|
||||
import { WorkflowRepository } from '@/databases/repositories/workflow.repository';
|
||||
import { ExecutionService } from '@/executions/execution.service';
|
||||
import { ExternalHooks } from '@/external-hooks';
|
||||
import { NodeTypes } from '@/node-types';
|
||||
@@ -43,7 +51,18 @@ beforeAll(async () => {
|
||||
|
||||
activeWorkflowManager = Container.get(ActiveWorkflowManager);
|
||||
|
||||
await utils.initNodeTypes();
|
||||
const nodes: INodeTypeData = {
|
||||
'n8n-nodes-base.scheduleTrigger': {
|
||||
type: new ScheduleTrigger(),
|
||||
sourcePath: '',
|
||||
},
|
||||
'n8n-nodes-base.formTrigger': {
|
||||
type: new FormTrigger(),
|
||||
sourcePath: '',
|
||||
},
|
||||
};
|
||||
|
||||
await utils.initNodeTypes(nodes);
|
||||
|
||||
const owner = await createOwner();
|
||||
createActiveWorkflow = async () => await createWorkflow({ active: true }, owner);
|
||||
@@ -136,6 +155,43 @@ describe('add()', () => {
|
||||
},
|
||||
);
|
||||
});
|
||||
|
||||
test('should count workflow triggers correctly when node has multiple webhooks', async () => {
|
||||
const workflowRepositoryInstance = Container.get(WorkflowRepository);
|
||||
const updateWorkflowTriggerCountSpy = jest.spyOn(
|
||||
workflowRepositoryInstance,
|
||||
'updateWorkflowTriggerCount',
|
||||
);
|
||||
await activeWorkflowManager.init();
|
||||
|
||||
// Mock all of the webhooks
|
||||
const mockWebhooks: IWebhookData[] = [
|
||||
mock<IWebhookData>({ node: 'Form Trigger', httpMethod: 'GET', path: '/webhook-path' }),
|
||||
mock<IWebhookData>({ node: 'Form Trigger', httpMethod: 'POST', path: '/webhook-path' }),
|
||||
];
|
||||
webhookService.getNodeWebhooks.mockReturnValue(mockWebhooks);
|
||||
webhookService.createWebhook.mockReturnValue(
|
||||
mock<WebhookEntity>({ webhookPath: '/webhook-path' }),
|
||||
);
|
||||
|
||||
// Create a workflow which has a form trigger
|
||||
const dbWorkflow = await createWorkflow({
|
||||
nodes: [
|
||||
{
|
||||
id: 'uuid-1',
|
||||
parameters: { path: 'test-webhook-path', options: {} },
|
||||
name: 'Form Trigger',
|
||||
type: 'n8n-nodes-base.formTrigger',
|
||||
typeVersion: 1,
|
||||
position: [500, 300],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
await activeWorkflowManager.add(dbWorkflow.id, 'activate');
|
||||
|
||||
expect(updateWorkflowTriggerCountSpy).toHaveBeenCalledWith(dbWorkflow.id, 1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('removeAll()', () => {
|
||||
|
||||
Reference in New Issue
Block a user