feat(core): Send the right activation mode for activate endpoint (no-changelog) (#22276)

This commit is contained in:
Daria 2025-11-25 13:16:32 +02:00 committed by GitHub
parent d366cb4f37
commit 362f33dbd0
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 28 additions and 2 deletions

View File

@ -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,

View File

@ -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', () => {