refactor(core): Move active workflows endpoints to a decorated controller class (no-changelog) (#8101)

This is a continuation of migrating all rest endpoints to decorated controller classes
This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2023-12-22 11:28:42 +01:00
committed by GitHub
parent 39e45d8b92
commit 021add0f39
12 changed files with 226 additions and 133 deletions

View File

@@ -2,7 +2,6 @@ import { Container } from 'typedi';
import { NodeApiError, NodeOperationError, Workflow } from 'n8n-workflow';
import type { IWebhookData, WorkflowActivateMode } from 'n8n-workflow';
import { ActiveWorkflows } from 'n8n-core';
import { ActiveExecutions } from '@/ActiveExecutions';
import { ActiveWorkflowRunner } from '@/ActiveWorkflowRunner';
@@ -26,9 +25,9 @@ import { createOwner } from './shared/db/users';
import { createWorkflow } from './shared/db/workflows';
import { ExecutionsService } from '@/executions/executions.service';
import { WorkflowService } from '@/workflows/workflow.service';
import { ActiveWorkflowsService } from '@/services/activeWorkflows.service';
mockInstance(ActiveExecutions);
mockInstance(ActiveWorkflows);
mockInstance(Push);
mockInstance(SecretsHelper);
mockInstance(ExecutionsService);
@@ -45,6 +44,7 @@ setSchedulerAsLoadedNode();
const externalHooks = mockInstance(ExternalHooks);
let activeWorkflowsService: ActiveWorkflowsService;
let activeWorkflowRunner: ActiveWorkflowRunner;
let owner: User;
@@ -59,6 +59,7 @@ const NON_LEADERSHIP_CHANGE_MODES: WorkflowActivateMode[] = [
beforeAll(async () => {
await testDb.init();
activeWorkflowsService = Container.get(ActiveWorkflowsService);
activeWorkflowRunner = Container.get(ActiveWorkflowRunner);
owner = await createOwner();
});
@@ -90,8 +91,8 @@ describe('init()', () => {
test('should start with no active workflows', async () => {
await activeWorkflowRunner.init();
const inStorage = activeWorkflowRunner.allActiveInStorage();
await expect(inStorage).resolves.toHaveLength(0);
const inStorage = await activeWorkflowsService.getAllActiveIdsInStorage();
expect(inStorage).toHaveLength(0);
const inMemory = activeWorkflowRunner.allActiveInMemory();
expect(inMemory).toHaveLength(0);
@@ -102,8 +103,8 @@ describe('init()', () => {
await activeWorkflowRunner.init();
const inStorage = activeWorkflowRunner.allActiveInStorage();
await expect(inStorage).resolves.toHaveLength(1);
const inStorage = await activeWorkflowsService.getAllActiveIdsInStorage();
expect(inStorage).toHaveLength(1);
const inMemory = activeWorkflowRunner.allActiveInMemory();
expect(inMemory).toHaveLength(1);
@@ -115,8 +116,8 @@ describe('init()', () => {
await activeWorkflowRunner.init();
const inStorage = activeWorkflowRunner.allActiveInStorage();
await expect(inStorage).resolves.toHaveLength(2);
const inStorage = await activeWorkflowsService.getAllActiveIdsInStorage();
expect(inStorage).toHaveLength(2);
const inMemory = activeWorkflowRunner.allActiveInMemory();
expect(inMemory).toHaveLength(2);