Skip to content

Commit

Permalink
fix(API): Fix workflow project transfer (#10651)
Browse files Browse the repository at this point in the history
Co-authored-by: Benjamin Roedell <[email protected]>
  • Loading branch information
benrobot and benrobot authored Sep 27, 2024
1 parent f20e945 commit 5f89e3a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
6 changes: 1 addition & 5 deletions packages/cli/src/public-api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
);

Expand Down
11 changes: 11 additions & 0 deletions packages/cli/test/integration/public-api/workflows.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand All @@ -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 () => {
Expand Down

0 comments on commit 5f89e3a

Please sign in to comment.