-
Notifications
You must be signed in to change notification settings - Fork 7.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(core): Fix update workflow cli command being unable to activate a…
…ll workflows (#8412) Co-authored-by: Daniel Schröder <daniel.schroeder@skriptfabrik.com>
- Loading branch information
1 parent
49b52c4
commit ae06fde
Showing
4 changed files
with
210 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
126 changes: 126 additions & 0 deletions
126
packages/cli/test/integration/commands/update/workflow.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
import { Config } from '@oclif/core'; | ||
import { InternalHooks } from '@/InternalHooks'; | ||
import { LoadNodesAndCredentials } from '@/LoadNodesAndCredentials'; | ||
import { UpdateWorkflowCommand } from '@/commands/update/workflow'; | ||
|
||
import * as testDb from '../../shared/testDb'; | ||
import { createWorkflowWithTrigger, getAllWorkflows } from '../../shared/db/workflows'; | ||
import { mockInstance } from '../../../shared/mocking'; | ||
|
||
beforeAll(async () => { | ||
mockInstance(InternalHooks); | ||
mockInstance(LoadNodesAndCredentials); | ||
await testDb.init(); | ||
}); | ||
|
||
beforeEach(async () => { | ||
await testDb.truncate(['Workflow']); | ||
}); | ||
|
||
afterAll(async () => { | ||
await testDb.terminate(); | ||
}); | ||
|
||
test('update:workflow can activate all workflows', async () => { | ||
// | ||
// ARRANGE | ||
// | ||
const workflows = await Promise.all([ | ||
createWorkflowWithTrigger({}), | ||
createWorkflowWithTrigger({}), | ||
]); | ||
expect(workflows).toMatchObject([{ active: false }, { active: false }]); | ||
|
||
// | ||
// ACT | ||
// | ||
const config = new Config({ root: __dirname }); | ||
const updater = new UpdateWorkflowCommand(['--all', '--active=true'], config); | ||
await updater.init(); | ||
await updater.run(); | ||
|
||
// | ||
// 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 | ||
// | ||
const config = new Config({ root: __dirname }); | ||
const updater = new UpdateWorkflowCommand(['--all', '--active=false'], config); | ||
await updater.init(); | ||
await updater.run(); | ||
|
||
// | ||
// 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 | ||
// | ||
const config = new Config({ root: __dirname }); | ||
const updater = new UpdateWorkflowCommand([`--id=${workflows[0].id}`, '--active=true'], config); | ||
await updater.init(); | ||
await updater.run(); | ||
|
||
// | ||
// 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 | ||
// | ||
const config = new Config({ root: __dirname }); | ||
const updater = new UpdateWorkflowCommand([`--id=${workflows[0].id}`, '--active=false'], config); | ||
await updater.init(); | ||
await updater.run(); | ||
|
||
// | ||
// ASSERT | ||
// | ||
const after = (await getAllWorkflows()).sort((wf1, wf2) => wf1.id.localeCompare(wf2.id)); | ||
expect(after).toMatchObject([{ active: false }, { active: true }]); | ||
}); |
70 changes: 70 additions & 0 deletions
70
packages/cli/test/integration/database/repositories/workflow.repository.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
import Container from 'typedi'; | ||
|
||
import { WorkflowRepository } from '@/databases/repositories/workflow.repository'; | ||
|
||
import * as testDb from '../../shared/testDb'; | ||
import { createWorkflowWithTrigger, getAllWorkflows } from '../../shared/db/workflows'; | ||
|
||
describe('WorkflowRepository', () => { | ||
beforeAll(async () => { | ||
await testDb.init(); | ||
}); | ||
|
||
beforeEach(async () => { | ||
await testDb.truncate(['Workflow']); | ||
}); | ||
|
||
afterAll(async () => { | ||
await testDb.terminate(); | ||
}); | ||
|
||
describe('activateAll', () => { | ||
it('should activate all workflows', async () => { | ||
// | ||
// ARRANGE | ||
// | ||
const workflowRepository = Container.get(WorkflowRepository); | ||
const workflows = await Promise.all([ | ||
createWorkflowWithTrigger(), | ||
createWorkflowWithTrigger(), | ||
]); | ||
expect(workflows).toMatchObject([{ active: false }, { active: false }]); | ||
|
||
// | ||
// ACT | ||
// | ||
await workflowRepository.activateAll(); | ||
|
||
// | ||
// ASSERT | ||
// | ||
const after = await getAllWorkflows(); | ||
expect(after).toMatchObject([{ active: true }, { active: true }]); | ||
}); | ||
}); | ||
|
||
describe('deactivateAll', () => { | ||
it('should deactivate all workflows', async () => { | ||
// | ||
// ARRANGE | ||
// | ||
const workflowRepository = Container.get(WorkflowRepository); | ||
const workflows = await Promise.all([ | ||
createWorkflowWithTrigger({ active: true }), | ||
createWorkflowWithTrigger({ active: true }), | ||
]); | ||
expect(workflows).toMatchObject([{ active: true }, { active: true }]); | ||
|
||
// | ||
// ACT | ||
// | ||
await workflowRepository.deactivateAll(); | ||
|
||
// | ||
// ASSERT | ||
// | ||
const after = await getAllWorkflows(); | ||
expect(after).toMatchObject([{ active: false }, { active: false }]); | ||
}); | ||
}); | ||
}); |