refactor(core): Use DI for WorkflowRunner (no-changelog) (#8372)
This commit is contained in:
committed by
GitHub
parent
bf11c7c1bd
commit
c70fa66e76
@@ -1,5 +1,4 @@
|
||||
import { Container } from 'typedi';
|
||||
|
||||
import { NodeApiError, NodeOperationError, Workflow } from 'n8n-workflow';
|
||||
import type { IWebhookData, WorkflowActivateMode } from 'n8n-workflow';
|
||||
|
||||
@@ -12,20 +11,20 @@ import { SecretsHelper } from '@/SecretsHelpers';
|
||||
import { WebhookService } from '@/services/webhook.service';
|
||||
import * as WebhookHelpers from '@/WebhookHelpers';
|
||||
import * as AdditionalData from '@/WorkflowExecuteAdditionalData';
|
||||
import { WorkflowRunner } from '@/WorkflowRunner';
|
||||
import type { User } from '@db/entities/User';
|
||||
import type { WebhookEntity } from '@db/entities/WebhookEntity';
|
||||
import { NodeTypes } from '@/NodeTypes';
|
||||
import { chooseRandomly } from './shared/random';
|
||||
import { OrchestrationService } from '@/services/orchestration.service';
|
||||
import { ExecutionService } from '@/executions/execution.service';
|
||||
import { WorkflowService } from '@/workflows/workflow.service';
|
||||
import { ActiveWorkflowsService } from '@/services/activeWorkflows.service';
|
||||
|
||||
import { mockInstance } from '../shared/mocking';
|
||||
import { chooseRandomly } from './shared/random';
|
||||
import { setSchedulerAsLoadedNode } from './shared/utils';
|
||||
import * as testDb from './shared/testDb';
|
||||
import { createOwner } from './shared/db/users';
|
||||
import { createWorkflow } from './shared/db/workflows';
|
||||
import { ExecutionService } from '@/executions/execution.service';
|
||||
import { WorkflowService } from '@/workflows/workflow.service';
|
||||
import { ActiveWorkflowsService } from '@/services/activeWorkflows.service';
|
||||
|
||||
mockInstance(ActiveExecutions);
|
||||
mockInstance(Push);
|
||||
@@ -182,26 +181,6 @@ describe('isActive()', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('runWorkflow()', () => {
|
||||
test('should call `WorkflowRunner.run()`', async () => {
|
||||
const workflow = await createWorkflow({ active: true }, owner);
|
||||
|
||||
await activeWorkflowRunner.init();
|
||||
|
||||
const additionalData = await AdditionalData.getBase('fake-user-id');
|
||||
|
||||
const runSpy = jest
|
||||
.spyOn(WorkflowRunner.prototype, 'run')
|
||||
.mockResolvedValue('fake-execution-id');
|
||||
|
||||
const [node] = workflow.nodes;
|
||||
|
||||
await activeWorkflowRunner.runWorkflow(workflow, node, [[]], additionalData, 'trigger');
|
||||
|
||||
expect(runSpy).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('executeErrorWorkflow()', () => {
|
||||
test('should call `WorkflowExecuteAdditionalData.executeErrorWorkflow()`', async () => {
|
||||
const workflow = await createWorkflow({ active: true }, owner);
|
||||
|
||||
@@ -4,7 +4,6 @@ import type { SuperAgentTest } from 'supertest';
|
||||
import type { InstalledPackages } from '@db/entities/InstalledPackages';
|
||||
import type { InstalledNodes } from '@db/entities/InstalledNodes';
|
||||
import { LoadNodesAndCredentials } from '@/LoadNodesAndCredentials';
|
||||
import { Push } from '@/push';
|
||||
import { CommunityPackagesService } from '@/services/communityPackages.service';
|
||||
|
||||
import { mockInstance } from '../shared/mocking';
|
||||
@@ -16,7 +15,6 @@ const communityPackagesService = mockInstance(CommunityPackagesService, {
|
||||
hasMissingPackages: false,
|
||||
});
|
||||
mockInstance(LoadNodesAndCredentials);
|
||||
mockInstance(Push);
|
||||
|
||||
const testServer = setupTestServer({ endpointGroups: ['community-packages'] });
|
||||
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
import type { User } from '@db/entities/User';
|
||||
import { Push } from '@/push';
|
||||
import { EnterpriseExecutionsService } from '@/executions/execution.service.ee';
|
||||
import { WaitTracker } from '@/WaitTracker';
|
||||
|
||||
import { createSuccessfulExecution, getAllExecutions } from './shared/db/executions';
|
||||
import { createOwner } from './shared/db/users';
|
||||
import { createWorkflow } from './shared/db/workflows';
|
||||
import * as testDb from './shared/testDb';
|
||||
import { setupTestServer } from './shared/utils';
|
||||
import { mockInstance } from '../shared/mocking';
|
||||
import { EnterpriseExecutionsService } from '@/executions/execution.service.ee';
|
||||
|
||||
mockInstance(EnterpriseExecutionsService);
|
||||
mockInstance(WaitTracker);
|
||||
|
||||
mockInstance(Push);
|
||||
let testServer = setupTestServer({ endpointGroups: ['executions'] });
|
||||
|
||||
let owner: User;
|
||||
|
||||
@@ -7,7 +7,6 @@ import type { User } from '@db/entities/User';
|
||||
import { SharedWorkflowRepository } from '@db/repositories/sharedWorkflow.repository';
|
||||
import { WorkflowHistoryRepository } from '@db/repositories/workflowHistory.repository';
|
||||
import { ActiveWorkflowRunner } from '@/ActiveWorkflowRunner';
|
||||
import { Push } from '@/push';
|
||||
import { ExecutionService } from '@/executions/execution.service';
|
||||
|
||||
import { randomApiKey } from '../shared/random';
|
||||
@@ -27,7 +26,6 @@ let workflowRunner: ActiveWorkflowRunner;
|
||||
const testServer = utils.setupTestServer({ endpointGroups: ['publicApi'] });
|
||||
const license = testServer.license;
|
||||
|
||||
mockInstance(Push);
|
||||
mockInstance(ExecutionService);
|
||||
|
||||
beforeAll(async () => {
|
||||
|
||||
@@ -11,14 +11,15 @@ import { v4 as uuid } from 'uuid';
|
||||
|
||||
import config from '@/config';
|
||||
import { WorkflowEntity } from '@db/entities/WorkflowEntity';
|
||||
import { AUTH_COOKIE_NAME } from '@/constants';
|
||||
|
||||
import { LoadNodesAndCredentials } from '@/LoadNodesAndCredentials';
|
||||
import { SettingsRepository } from '@db/repositories/settings.repository';
|
||||
import { mockNodeTypesData } from '../../../unit/Helpers';
|
||||
import { OrchestrationService } from '@/services/orchestration.service';
|
||||
import { mockInstance } from '../../../shared/mocking';
|
||||
import { AUTH_COOKIE_NAME } from '@/constants';
|
||||
import { ExecutionService } from '@/executions/execution.service';
|
||||
import { LoadNodesAndCredentials } from '@/LoadNodesAndCredentials';
|
||||
import { Push } from '@/push';
|
||||
import { OrchestrationService } from '@/services/orchestration.service';
|
||||
|
||||
import { mockNodeTypesData } from '../../../unit/Helpers';
|
||||
import { mockInstance } from '../../../shared/mocking';
|
||||
|
||||
export { setupTestServer } from './testServer';
|
||||
|
||||
@@ -30,6 +31,7 @@ export { setupTestServer } from './testServer';
|
||||
* Initialize node types.
|
||||
*/
|
||||
export async function initActiveWorkflowRunner() {
|
||||
mockInstance(Push);
|
||||
mockInstance(OrchestrationService);
|
||||
|
||||
mockInstance(ExecutionService);
|
||||
|
||||
@@ -12,6 +12,7 @@ import { issueJWT } from '@/auth/jwt';
|
||||
import { registerController } from '@/decorators';
|
||||
import { rawBodyReader, bodyParser, setupAuthMiddlewares } from '@/middlewares';
|
||||
import { PostHogClient } from '@/posthog';
|
||||
import { Push } from '@/push';
|
||||
import { License } from '@/License';
|
||||
import { Logger } from '@/Logger';
|
||||
import { InternalHooks } from '@/InternalHooks';
|
||||
@@ -78,6 +79,7 @@ export const setupTestServer = ({
|
||||
mockInstance(Logger);
|
||||
mockInstance(InternalHooks);
|
||||
mockInstance(PostHogClient);
|
||||
mockInstance(Push);
|
||||
|
||||
const testServer: TestServer = {
|
||||
app,
|
||||
|
||||
@@ -6,7 +6,6 @@ import type { INode } from 'n8n-workflow';
|
||||
import type { User } from '@db/entities/User';
|
||||
import { WorkflowHistoryRepository } from '@db/repositories/workflowHistory.repository';
|
||||
import { ActiveWorkflowRunner } from '@/ActiveWorkflowRunner';
|
||||
import { Push } from '@/push';
|
||||
import { WorkflowSharingService } from '@/workflows/workflowSharing.service';
|
||||
|
||||
import { mockInstance } from '../../shared/mocking';
|
||||
@@ -30,7 +29,6 @@ let authAnotherMemberAgent: SuperAgentTest;
|
||||
let saveCredential: SaveCredentialFunction;
|
||||
|
||||
const activeWorkflowRunner = mockInstance(ActiveWorkflowRunner);
|
||||
mockInstance(Push);
|
||||
|
||||
const sharingSpy = jest.spyOn(License.prototype, 'isSharingEnabled').mockReturnValue(true);
|
||||
const testServer = utils.setupTestServer({
|
||||
|
||||
@@ -9,7 +9,6 @@ import type { WorkflowEntity } from '@db/entities/WorkflowEntity';
|
||||
import type { ListQuery } from '@/requests';
|
||||
import { WorkflowHistoryRepository } from '@db/repositories/workflowHistory.repository';
|
||||
import { ActiveWorkflowRunner } from '@/ActiveWorkflowRunner';
|
||||
import { Push } from '@/push';
|
||||
import { EnterpriseWorkflowService } from '@/workflows/workflow.service.ee';
|
||||
|
||||
import { mockInstance } from '../../shared/mocking';
|
||||
@@ -34,7 +33,6 @@ const license = testServer.license;
|
||||
const { objectContaining, arrayContaining, any } = expect;
|
||||
|
||||
const activeWorkflowRunnerLike = mockInstance(ActiveWorkflowRunner);
|
||||
mockInstance(Push);
|
||||
|
||||
beforeAll(async () => {
|
||||
owner = await createOwner();
|
||||
|
||||
Reference in New Issue
Block a user