From c906e7391b806be1622aa717dd01a124aa0ec2fd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E0=A4=95=E0=A4=BE=E0=A4=B0=E0=A4=A4=E0=A5=8B=E0=A4=AB?= =?UTF-8?q?=E0=A5=8D=E0=A4=AB=E0=A5=87=E0=A4=B2=E0=A4=B8=E0=A5=8D=E0=A4=95?= =?UTF-8?q?=E0=A5=8D=E0=A4=B0=E0=A4=BF=E0=A4=AA=E0=A5=8D=E0=A4=9F=E2=84=A2?= Date: Fri, 30 Jun 2023 08:51:39 +0200 Subject: [PATCH] fix(core): Route `/rest/workflows/new` correctly (no-changelog) (#6572) --- .../src/workflows/workflows.controller.ee.ts | 1 + .../integration/workflows.controller.ee.test.ts | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/packages/cli/src/workflows/workflows.controller.ee.ts b/packages/cli/src/workflows/workflows.controller.ee.ts index 14b4d56d965a6..c50860c359263 100644 --- a/packages/cli/src/workflows/workflows.controller.ee.ts +++ b/packages/cli/src/workflows/workflows.controller.ee.ts @@ -87,6 +87,7 @@ EEWorkflowController.put( EEWorkflowController.get( '/:id(\\w+)', + (req, res, next) => (req.params.id === 'new' ? next('router') : next()), // skip ee router and use free one for naming ResponseHelper.send(async (req: WorkflowRequest.Get) => { const { id: workflowId } = req.params; diff --git a/packages/cli/test/integration/workflows.controller.ee.test.ts b/packages/cli/test/integration/workflows.controller.ee.test.ts index f2949c3ed5a8b..f84a6449aeb7c 100644 --- a/packages/cli/test/integration/workflows.controller.ee.test.ts +++ b/packages/cli/test/integration/workflows.controller.ee.test.ts @@ -196,6 +196,23 @@ describe('GET /workflows', () => { }); }); +describe('GET /workflows/new', () => { + [true, false].forEach((sharingEnabled) => { + test(`should return an auto-incremented name, even when sharing is ${ + sharingEnabled ? 'enabled' : 'disabled' + }`, async () => { + sharingSpy.mockReturnValueOnce(sharingEnabled); + + await createWorkflow({ name: 'My workflow' }, owner); + await createWorkflow({ name: 'My workflow 7' }, owner); + + const response = await authOwnerAgent.get('/workflows/new'); + expect(response.statusCode).toBe(200); + expect(response.body.data.name).toEqual('My workflow 8'); + }); + }); +}); + describe('GET /workflows/:id', () => { test('GET should fail with invalid id due to route rule', async () => { const response = await authOwnerAgent.get('/workflows/potatoes');