From 5f89e3a01c1bbb3589ff0464fd5bc991426f55dc Mon Sep 17 00:00:00 2001 From: Benjamin Roedell Date: Fri, 27 Sep 2024 04:34:45 -0400 Subject: [PATCH] fix(API): Fix workflow project transfer (#10651) Co-authored-by: Benjamin Roedell <2271599+benrobot@users.noreply.github.com> --- packages/cli/src/public-api/types.ts | 6 +----- .../v1/handlers/workflows/workflows.handler.ts | 4 +++- .../cli/test/integration/public-api/workflows.test.ts | 11 +++++++++++ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/packages/cli/src/public-api/types.ts b/packages/cli/src/public-api/types.ts index b69acff8d9992..e2d22eac2c0bb 100644 --- a/packages/cli/src/public-api/types.ts +++ b/packages/cli/src/public-api/types.ts @@ -84,11 +84,7 @@ export declare namespace WorkflowRequest { type Activate = Get; type GetTags = Get; type UpdateTags = AuthenticatedRequest<{ id: string }, {}, TagEntity[]>; - type Transfer = AuthenticatedRequest< - { workflowId: string }, - {}, - { destinationProjectId: string } - >; + type Transfer = AuthenticatedRequest<{ id: string }, {}, { destinationProjectId: string }>; } export declare namespace UserRequest { diff --git a/packages/cli/src/public-api/v1/handlers/workflows/workflows.handler.ts b/packages/cli/src/public-api/v1/handlers/workflows/workflows.handler.ts index f46b177c61171..b0956a15c1bd4 100644 --- a/packages/cli/src/public-api/v1/handlers/workflows/workflows.handler.ts +++ b/packages/cli/src/public-api/v1/handlers/workflows/workflows.handler.ts @@ -73,11 +73,13 @@ export = { transferWorkflow: [ projectScope('workflow:move', 'workflow'), async (req: WorkflowRequest.Transfer, res: express.Response) => { + const { id: workflowId } = req.params; + const body = z.object({ destinationProjectId: z.string() }).parse(req.body); await Container.get(EnterpriseWorkflowService).transferOne( req.user, - req.params.workflowId, + workflowId, body.destinationProjectId, ); diff --git a/packages/cli/test/integration/public-api/workflows.test.ts b/packages/cli/test/integration/public-api/workflows.test.ts index 11d198ff98b9f..687b29da6af8d 100644 --- a/packages/cli/test/integration/public-api/workflows.test.ts +++ b/packages/cli/test/integration/public-api/workflows.test.ts @@ -1512,6 +1512,10 @@ describe('PUT /workflows/:id/transfer', () => { const secondProject = await createTeamProject('second-project', member); const workflow = await createWorkflow({}, firstProject); + // Make data more similar to real world scenario by injecting additional records into the database + await createTeamProject('third-project', member); + await createWorkflow({}, firstProject); + /** * Act */ @@ -1523,6 +1527,13 @@ describe('PUT /workflows/:id/transfer', () => { * Assert */ expect(response.statusCode).toBe(204); + + const workflowsInProjectResponse = await authMemberAgent + .get(`/workflows?projectId=${secondProject.id}`) + .send(); + + expect(workflowsInProjectResponse.statusCode).toBe(200); + expect(workflowsInProjectResponse.body.data[0].id).toBe(workflow.id); }); test('if no destination project, should reject', async () => {