diff --git a/packages/cli/src/workflows/workflow.service.ts b/packages/cli/src/workflows/workflow.service.ts index dd40c054c01..f8f1b7e7105 100644 --- a/packages/cli/src/workflows/workflow.service.ts +++ b/packages/cli/src/workflows/workflow.service.ts @@ -544,6 +544,9 @@ export class WorkflowService { return workflow; } + const wasActive = workflow.activeVersionId !== null; + const activationMode = wasActive ? 'update' : 'activate'; + await this.workflowRepository.update(workflowId, { activeVersionId: versionId, active: true, @@ -572,7 +575,7 @@ export class WorkflowService { publicApi: false, }); - await this._addToActiveWorkflowManager(user, workflowId, updatedWorkflow, 'activate', { + await this._addToActiveWorkflowManager(user, workflowId, updatedWorkflow, activationMode, { active: workflow.active, activeVersionId: workflow.activeVersionId, activeVersion: workflow.activeVersion, diff --git a/packages/cli/test/integration/workflows/workflows.controller.test.ts b/packages/cli/test/integration/workflows/workflows.controller.test.ts index 6b4f7e53655..8ea5b3929eb 100644 --- a/packages/cli/test/integration/workflows/workflows.controller.test.ts +++ b/packages/cli/test/integration/workflows/workflows.controller.test.ts @@ -2825,7 +2825,7 @@ describe('PATCH /workflows/:workflowId', () => { }); test('should not modify activeVersionId when explicitly provided', async () => { - const workflow = await createWorkflow({}, owner); + const workflow = await createWorkflowWithHistory({}, owner); const payload = { versionId: workflow.versionId, activeVersionId: workflow.versionId, @@ -3033,6 +3033,29 @@ describe('POST /workflows/:workflowId/activate', () => { expect(emitSpy).not.toHaveBeenCalledWith('workflow-deactivated', expect.anything()); }); + + test('should call active workflow manager with activate mode if workflow is not active', async () => { + const workflow = await createWorkflowWithHistory({}, owner); + + await authOwnerAgent + .post(`/workflows/${workflow.id}/activate`) + .send({ versionId: workflow.versionId }); + + expect(activeWorkflowManagerLike.add).toBeCalledWith(workflow.id, 'activate'); + }); + + test('should call active workflow manager with update mode if workflow is active', async () => { + const workflow = await createActiveWorkflow({}, owner); + + const newVersionId = uuid(); + await createWorkflowHistoryItem(workflow.id, { versionId: newVersionId }); + + await authOwnerAgent + .post(`/workflows/${workflow.id}/activate`) + .send({ versionId: newVersionId }); + + expect(activeWorkflowManagerLike.add).toBeCalledWith(workflow.id, 'update'); + }); }); describe('POST /workflows/:workflowId/deactivate', () => {