Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(API): Fix workflow project transfer #10651

Merged
merged 5 commits into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -1518,6 +1518,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 @@ -1529,6 +1533,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