From b12a3678a02974ddee34e6cbe3db51a53fcf9a30 Mon Sep 17 00:00:00 2001 From: Marc-Roig Date: Mon, 22 May 2023 11:09:08 +0200 Subject: [PATCH] update contract for POST PUT workflows body --- ...review-workflows-content-types.test.api.js | 4 +- .../admin/ee/review-workflows.test.api.js | 54 +++++++++++-------- .../ee/server/controllers/workflows/index.js | 4 +- 3 files changed, 35 insertions(+), 27 deletions(-) diff --git a/api-tests/core/admin/ee/review-workflows-content-types.test.api.js b/api-tests/core/admin/ee/review-workflows-content-types.test.api.js index 644399cb0e..fde65ef9b9 100644 --- a/api-tests/core/admin/ee/review-workflows-content-types.test.api.js +++ b/api-tests/core/admin/ee/review-workflows-content-types.test.api.js @@ -44,13 +44,13 @@ describeOnCondition(edition === 'EE')('Review workflows', () => { const createWorkflow = async (data) => { const name = `${data.name}-${Math.random().toString(36)}`; return requests.admin.post('/admin/review-workflows/workflows?populate=*', { - body: { ...baseWorkflow, name, ...data }, + body: { data: { ...baseWorkflow, name, ...data } }, }); }; const updateWorkflow = async (id, data) => { return requests.admin.put(`/admin/review-workflows/workflows/${id}?populate=stages`, { - body: data, + body: { data }, }); }; diff --git a/api-tests/core/admin/ee/review-workflows.test.api.js b/api-tests/core/admin/ee/review-workflows.test.api.js index d1ccb393dd..6ea39a6240 100644 --- a/api-tests/core/admin/ee/review-workflows.test.api.js +++ b/api-tests/core/admin/ee/review-workflows.test.api.js @@ -30,7 +30,7 @@ const model = { }, options: { reviewWorkflows: true, - } + }, }; describeOnCondition(edition === 'EE')('Review workflows', () => { @@ -180,8 +180,10 @@ describeOnCondition(edition === 'EE')('Review workflows', () => { test('It should create a workflow without stages', async () => { const res = await requests.admin.post('/admin/review-workflows/workflows', { body: { - name: 'testWorkflow', - stages: [], + data: { + name: 'testWorkflow', + stages: [], + }, }, }); @@ -196,8 +198,10 @@ describeOnCondition(edition === 'EE')('Review workflows', () => { test('It should create a workflow with stages', async () => { const res = await requests.admin.post('/admin/review-workflows/workflows?populate=stages', { body: { - name: 'createdWorkflow', - stages: [{ name: 'Stage 1' }, { name: 'Stage 2' }], + data: { + name: 'createdWorkflow', + stages: [{ name: 'Stage 1' }, { name: 'Stage 2' }], + }, }, }); @@ -220,7 +224,7 @@ describeOnCondition(edition === 'EE')('Review workflows', () => { test('It should update a workflow', async () => { const res = await requests.admin.put( `/admin/review-workflows/workflows/${createdWorkflow.id}`, - { body: { name: 'updatedWorkflow' } } + { body: { data: { name: 'updatedWorkflow' } } } ); if (hasRW) { @@ -237,11 +241,13 @@ describeOnCondition(edition === 'EE')('Review workflows', () => { `/admin/review-workflows/workflows/${createdWorkflow.id}?populate=stages`, { body: { - name: 'updatedWorkflow', - stages: [ - { id: createdWorkflow.stages[0].id, name: 'Stage 1_Updated' }, - { name: 'Stage 2' }, - ], + data: { + name: 'updatedWorkflow', + stages: [ + { id: createdWorkflow.stages[0].id, name: 'Stage 1_Updated' }, + { name: 'Stage 2' }, + ], + }, }, } ); @@ -265,7 +271,7 @@ describeOnCondition(edition === 'EE')('Review workflows', () => { describe('Delete workflow', () => { test('It should delete a workflow', async () => { const createdRes = await requests.admin.post('/admin/review-workflows/workflows', { - body: { name: 'testWorkflow', stages: [{ name: 'Stage 1' }] }, + body: { data: { name: 'testWorkflow', stages: [{ name: 'Stage 1' }] } }, }); const res = await requests.admin.delete( @@ -387,10 +393,12 @@ describeOnCondition(edition === 'EE')('Review workflows', () => { `/admin/review-workflows/workflows/${testWorkflow.id}?populate=*`, { body: { - stages: [ - defaultStage, - { id: secondStage.id, name: secondStage.name, color: '#000000' }, - ], + data: { + stages: [ + defaultStage, + { id: secondStage.id, name: secondStage.name, color: '#000000' }, + ], + }, }, } ); @@ -414,7 +422,7 @@ describeOnCondition(edition === 'EE')('Review workflows', () => { test('It should be available for every connected users (admin)', async () => { const workflowRes = await requests.admin.put( `/admin/review-workflows/workflows/${testWorkflow.id}?populate=*`, - { body: { stages: stagesUpdateData } } + { body: { data: { stages: stagesUpdateData } } } ); if (hasRW) { @@ -435,7 +443,7 @@ describeOnCondition(edition === 'EE')('Review workflows', () => { test('It should throw an error if trying to delete all stages in a workflow', async () => { const workflowRes = await requests.admin.put( `/admin/review-workflows/workflows/${testWorkflow.id}?populate=*`, - { body: { stages: [] } } + { body: { data: { stages: [] } } } ); if (hasRW) { @@ -450,7 +458,7 @@ describeOnCondition(edition === 'EE')('Review workflows', () => { test('It should throw an error if trying to create more than 200 stages', async () => { const stagesRes = await requests.admin.put( `/admin/review-workflows/workflows/${testWorkflow.id}?populate=*`, - { body: { stages: Array(201).fill({ name: 'new stage' }) } } + { body: { data: { stages: Array(201).fill({ name: 'new stage' }) } } } ); if (hasRW) { @@ -468,7 +476,7 @@ describeOnCondition(edition === 'EE')('Review workflows', () => { // Update workflow to unassign content type await requests.admin.put( `/admin/review-workflows/workflows/${testWorkflow.id}?populate=*`, - { body: { contentTypes: [productUID] } } + { body: { data: { contentTypes: [productUID] } } } ); }); @@ -510,7 +518,7 @@ describeOnCondition(edition === 'EE')('Review workflows', () => { // Update workflow to unassign content type await requests.admin.put( `/admin/review-workflows/workflows/${testWorkflow.id}?populate=*`, - { body: { contentTypes: [] } } + { body: { data: { contentTypes: [] } } } ); }); test('Should not update the entity', async () => { @@ -535,7 +543,7 @@ describeOnCondition(edition === 'EE')('Review workflows', () => { beforeAll(async () => { // Update workflow to unassign content type await requests.admin.put(`/admin/review-workflows/workflows/${testWorkflow.id}?populate=*`, { - body: { contentTypes: [productUID] }, + body: { data: { contentTypes: [productUID] } }, }); }); @@ -552,7 +560,7 @@ describeOnCondition(edition === 'EE')('Review workflows', () => { // Delete last stage stage of the default workflow await requests.admin.put(`/admin/review-workflows/workflows/${testWorkflow.id}?populate=*`, { - body: { stages: [defaultStage] }, + body: { data: { stages: [defaultStage] } }, }); // Expect the content in these stages to be moved to the nearest available stage diff --git a/packages/core/admin/ee/server/controllers/workflows/index.js b/packages/core/admin/ee/server/controllers/workflows/index.js index a430b20dab..50ef2ff6fd 100644 --- a/packages/core/admin/ee/server/controllers/workflows/index.js +++ b/packages/core/admin/ee/server/controllers/workflows/index.js @@ -16,7 +16,7 @@ module.exports = { const { body } = ctx.request; const { populate } = ctx.query; - const workflowBody = await validateWorkflowCreate(body); + const workflowBody = await validateWorkflowCreate(body.data); const workflowService = getService('workflows'); const data = await workflowService.create({ data: workflowBody, populate }); @@ -36,7 +36,7 @@ module.exports = { const { populate } = ctx.query; const workflowService = getService('workflows'); - const workflowBody = await validateWorkflowUpdate(body); + const workflowBody = await validateWorkflowUpdate(body.data); const workflow = await workflowService.findById(id, { populate: ['stages'] }); if (!workflow) {