n8n/packages/cli/test/integration/commands/update/workflow.test.ts
Tomi Turtiainen 5156313074
Some checks are pending
Test Master / install-and-build (push) Waiting to run
Test Master / Unit tests (18.x) (push) Blocked by required conditions
Test Master / Unit tests (20.x) (push) Blocked by required conditions
Test Master / Unit tests (22.4) (push) Blocked by required conditions
Test Master / Lint (push) Blocked by required conditions
Test Master / Notify Slack on failure (push) Blocked by required conditions
Benchmark Docker Image CI / build (push) Waiting to run
refactor(core): Enable import/order eslint rule (#10794)
2024-09-12 19:07:18 +03:00

107 lines
2.7 KiB
TypeScript

import { UpdateWorkflowCommand } from '@/commands/update/workflow';
import { LoadNodesAndCredentials } from '@/load-nodes-and-credentials';
import { setupTestCommand } from '@test-integration/utils/test-command';
import { mockInstance } from '../../../shared/mocking';
import { createWorkflowWithTrigger, getAllWorkflows } from '../../shared/db/workflows';
import * as testDb from '../../shared/test-db';
mockInstance(LoadNodesAndCredentials);
const command = setupTestCommand(UpdateWorkflowCommand);
beforeEach(async () => {
await testDb.truncate(['Workflow']);
});
test('update:workflow can activate all workflows', async () => {
//
// ARRANGE
//
const workflows = await Promise.all([
createWorkflowWithTrigger({}),
createWorkflowWithTrigger({}),
]);
expect(workflows).toMatchObject([{ active: false }, { active: false }]);
//
// ACT
//
await command.run(['--all', '--active=true']);
//
// ASSERT
//
const after = await getAllWorkflows();
expect(after).toMatchObject([{ active: true }, { active: true }]);
});
test('update:workflow can deactivate all workflows', async () => {
//
// ARRANGE
//
const workflows = await Promise.all([
createWorkflowWithTrigger({ active: true }),
createWorkflowWithTrigger({ active: true }),
]);
expect(workflows).toMatchObject([{ active: true }, { active: true }]);
//
// ACT
//
await command.run(['--all', '--active=false']);
//
// ASSERT
//
const after = await getAllWorkflows();
expect(after).toMatchObject([{ active: false }, { active: false }]);
});
test('update:workflow can activate a specific workflow', async () => {
//
// ARRANGE
//
const workflows = (
await Promise.all([
createWorkflowWithTrigger({ active: false }),
createWorkflowWithTrigger({ active: false }),
])
).sort((wf1, wf2) => wf1.id.localeCompare(wf2.id));
expect(workflows).toMatchObject([{ active: false }, { active: false }]);
//
// ACT
//
await command.run([`--id=${workflows[0].id}`, '--active=true']);
//
// ASSERT
//
const after = (await getAllWorkflows()).sort((wf1, wf2) => wf1.id.localeCompare(wf2.id));
expect(after).toMatchObject([{ active: true }, { active: false }]);
});
test('update:workflow can deactivate a specific workflow', async () => {
//
// ARRANGE
//
const workflows = (
await Promise.all([
createWorkflowWithTrigger({ active: true }),
createWorkflowWithTrigger({ active: true }),
])
).sort((wf1, wf2) => wf1.id.localeCompare(wf2.id));
expect(workflows).toMatchObject([{ active: true }, { active: true }]);
//
// ACT
//
await command.run([`--id=${workflows[0].id}`, '--active=false']);
//
// ASSERT
//
const after = (await getAllWorkflows()).sort((wf1, wf2) => wf1.id.localeCompare(wf2.id));
expect(after).toMatchObject([{ active: false }, { active: true }]);
});