first commit
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
Security: Sync from Public / sync-from-public (push) Has been cancelled
Test: Benchmark Nightly / build (push) Has been cancelled
Test: Benchmark Nightly / Notify Cats on failure (push) Has been cancelled
CI: Python / Checks (push) Has been cancelled
Test: Evals Python / Workflow Comparison Python (push) Has been cancelled
Util: Check Docs URLs / check-docs-urls (push) Has been cancelled
Test: Visual Storybook / Cloudflare Pages (push) Has been cancelled
Test: E2E Performance / build-and-test-performance (push) Has been cancelled
Test: Workflows Nightly / Run Workflow Tests (push) Has been cancelled
Util: Cleanup CI Docker Images / Delete stale CI images (push) Has been cancelled
Test: Benchmark Destroy Env / build (push) Has been cancelled
Util: Update Node Popularity / update-popularity (push) Has been cancelled
Test: E2E Coverage Weekly / Coverage Tests (push) Has been cancelled
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
import { mockInstance } from '@n8n/backend-test-utils';
|
||||
import { GlobalConfig } from '@n8n/config';
|
||||
import type { User, WorkflowEntity } from '@n8n/db';
|
||||
import { WorkflowRepository, DbConnection, AuthRolesService, BinaryDataRepository } from '@n8n/db';
|
||||
import { Container } from '@n8n/di';
|
||||
import { mock } from 'jest-mock-extended';
|
||||
import type { IRun } from 'n8n-workflow';
|
||||
|
||||
import { Execute } from '../execute';
|
||||
|
||||
import { ActiveExecutions } from '@/active-executions';
|
||||
import { DeprecationService } from '@/deprecation/deprecation.service';
|
||||
import { MessageEventBus } from '@/eventbus/message-event-bus/message-event-bus';
|
||||
import { TelemetryEventRelay } from '@/events/relays/telemetry.event-relay';
|
||||
import { WorkflowFailureNotificationEventRelay } from '@/events/relays/workflow-failure-notification.event-relay';
|
||||
import { ExternalHooks } from '@/external-hooks';
|
||||
import { LoadNodesAndCredentials } from '@/load-nodes-and-credentials';
|
||||
import { CommunityPackagesService } from '@/modules/community-packages/community-packages.service';
|
||||
import { PostHogClient } from '@/posthog';
|
||||
import { OwnershipService } from '@/services/ownership.service';
|
||||
import { ShutdownService } from '@/shutdown/shutdown.service';
|
||||
import { TaskRunnerModule } from '@/task-runners/task-runner-module';
|
||||
import { WorkflowRunner } from '@/workflow-runner';
|
||||
|
||||
const taskRunnerModule = mockInstance(TaskRunnerModule);
|
||||
const workflowRepository = mockInstance(WorkflowRepository);
|
||||
const ownershipService = mockInstance(OwnershipService);
|
||||
const workflowRunner = mockInstance(WorkflowRunner);
|
||||
const activeExecutions = mockInstance(ActiveExecutions);
|
||||
const loadNodesAndCredentials = mockInstance(LoadNodesAndCredentials);
|
||||
const shutdownService = mockInstance(ShutdownService);
|
||||
const deprecationService = mockInstance(DeprecationService);
|
||||
mockInstance(MessageEventBus);
|
||||
const posthogClient = mockInstance(PostHogClient);
|
||||
const telemetryEventRelay = mockInstance(TelemetryEventRelay);
|
||||
const externalHooks = mockInstance(ExternalHooks);
|
||||
mockInstance(CommunityPackagesService);
|
||||
mockInstance(WorkflowFailureNotificationEventRelay);
|
||||
|
||||
const dbConnection = mockInstance(DbConnection);
|
||||
dbConnection.init.mockResolvedValue(undefined);
|
||||
dbConnection.migrate.mockResolvedValue(undefined);
|
||||
mockInstance(AuthRolesService);
|
||||
mockInstance(BinaryDataRepository);
|
||||
|
||||
test('should start a task runner', async () => {
|
||||
// arrange
|
||||
|
||||
const workflow = mock<WorkflowEntity>({
|
||||
id: '123',
|
||||
nodes: [{ type: 'n8n-nodes-base.manualTrigger' }],
|
||||
});
|
||||
|
||||
const run = mock<IRun>({ data: { resultData: { error: undefined } } });
|
||||
|
||||
loadNodesAndCredentials.init.mockResolvedValue(undefined);
|
||||
shutdownService.shutdown.mockReturnValue();
|
||||
deprecationService.warn.mockReturnValue();
|
||||
posthogClient.init.mockResolvedValue();
|
||||
telemetryEventRelay.init.mockResolvedValue();
|
||||
externalHooks.init.mockResolvedValue();
|
||||
|
||||
workflowRepository.findOneBy.mockResolvedValue(workflow);
|
||||
ownershipService.getInstanceOwner.mockResolvedValue(mock<User>({ id: '123' }));
|
||||
workflowRunner.run.mockResolvedValue('123');
|
||||
activeExecutions.getPostExecutePromise.mockResolvedValue(run);
|
||||
|
||||
Container.set(
|
||||
GlobalConfig,
|
||||
mock<GlobalConfig>({
|
||||
taskRunners: {},
|
||||
nodes: {},
|
||||
}),
|
||||
);
|
||||
|
||||
const cmd = new Execute();
|
||||
// @ts-expect-error Protected property
|
||||
cmd.flags = { id: '123' };
|
||||
|
||||
// act
|
||||
|
||||
await cmd.init();
|
||||
await cmd.run();
|
||||
|
||||
// assert
|
||||
|
||||
expect(taskRunnerModule.start).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
Reference in New Issue
Block a user