refactor(core): Refactor cli command tests (no-changelog) (#9731)

This commit is contained in:
कारतोफ्फेलस्क्रिप्ट™
2024-06-18 10:50:39 +02:00
committed by GitHub
parent fb73ec3994
commit 2d02c73fbd
9 changed files with 160 additions and 250 deletions

View File

@@ -1,29 +1,20 @@
import { Config } from '@oclif/core';
import { InternalHooks } from '@/InternalHooks';
import { LoadNodesAndCredentials } from '@/LoadNodesAndCredentials';
import { UpdateWorkflowCommand } from '@/commands/update/workflow';
import { setupTestCommand } from '@test-integration/utils/testCommand';
import * as testDb from '../../shared/testDb';
import { createWorkflowWithTrigger, getAllWorkflows } from '../../shared/db/workflows';
import { mockInstance } from '../../../shared/mocking';
const oclifConfig = new Config({ root: __dirname });
beforeAll(async () => {
mockInstance(InternalHooks);
mockInstance(LoadNodesAndCredentials);
await testDb.init();
await oclifConfig.load();
});
mockInstance(InternalHooks);
mockInstance(LoadNodesAndCredentials);
const command = setupTestCommand(UpdateWorkflowCommand);
beforeEach(async () => {
await testDb.truncate(['Workflow']);
});
afterAll(async () => {
await testDb.terminate();
});
test('update:workflow can activate all workflows', async () => {
//
// ARRANGE
@@ -37,9 +28,7 @@ test('update:workflow can activate all workflows', async () => {
//
// ACT
//
const updater = new UpdateWorkflowCommand(['--all', '--active=true'], oclifConfig);
await updater.init();
await updater.run();
await command.run(['--all', '--active=true']);
//
// ASSERT
@@ -61,9 +50,7 @@ test('update:workflow can deactivate all workflows', async () => {
//
// ACT
//
const updater = new UpdateWorkflowCommand(['--all', '--active=false'], oclifConfig);
await updater.init();
await updater.run();
await command.run(['--all', '--active=false']);
//
// ASSERT
@@ -87,12 +74,7 @@ test('update:workflow can activate a specific workflow', async () => {
//
// ACT
//
const updater = new UpdateWorkflowCommand(
[`--id=${workflows[0].id}`, '--active=true'],
oclifConfig,
);
await updater.init();
await updater.run();
await command.run([`--id=${workflows[0].id}`, '--active=true']);
//
// ASSERT
@@ -116,12 +98,7 @@ test('update:workflow can deactivate a specific workflow', async () => {
//
// ACT
//
const updater = new UpdateWorkflowCommand(
[`--id=${workflows[0].id}`, '--active=false'],
oclifConfig,
);
await updater.init();
await updater.run();
await command.run([`--id=${workflows[0].id}`, '--active=false']);
//
// ASSERT