update contract for POST PUT workflows body

This commit is contained in:
Marc-Roig 2023-05-22 11:09:08 +02:00
parent 88d5169528
commit b12a3678a0
No known key found for this signature in database
GPG Key ID: FB4E2C43A0BEE249
3 changed files with 35 additions and 27 deletions

View File

@ -44,13 +44,13 @@ describeOnCondition(edition === 'EE')('Review workflows', () => {
const createWorkflow = async (data) => { const createWorkflow = async (data) => {
const name = `${data.name}-${Math.random().toString(36)}`; const name = `${data.name}-${Math.random().toString(36)}`;
return requests.admin.post('/admin/review-workflows/workflows?populate=*', { return requests.admin.post('/admin/review-workflows/workflows?populate=*', {
body: { ...baseWorkflow, name, ...data }, body: { data: { ...baseWorkflow, name, ...data } },
}); });
}; };
const updateWorkflow = async (id, data) => { const updateWorkflow = async (id, data) => {
return requests.admin.put(`/admin/review-workflows/workflows/${id}?populate=stages`, { return requests.admin.put(`/admin/review-workflows/workflows/${id}?populate=stages`, {
body: data, body: { data },
}); });
}; };

View File

@ -30,7 +30,7 @@ const model = {
}, },
options: { options: {
reviewWorkflows: true, reviewWorkflows: true,
} },
}; };
describeOnCondition(edition === 'EE')('Review workflows', () => { describeOnCondition(edition === 'EE')('Review workflows', () => {
@ -180,8 +180,10 @@ describeOnCondition(edition === 'EE')('Review workflows', () => {
test('It should create a workflow without stages', async () => { test('It should create a workflow without stages', async () => {
const res = await requests.admin.post('/admin/review-workflows/workflows', { const res = await requests.admin.post('/admin/review-workflows/workflows', {
body: { body: {
name: 'testWorkflow', data: {
stages: [], name: 'testWorkflow',
stages: [],
},
}, },
}); });
@ -196,8 +198,10 @@ describeOnCondition(edition === 'EE')('Review workflows', () => {
test('It should create a workflow with stages', async () => { test('It should create a workflow with stages', async () => {
const res = await requests.admin.post('/admin/review-workflows/workflows?populate=stages', { const res = await requests.admin.post('/admin/review-workflows/workflows?populate=stages', {
body: { body: {
name: 'createdWorkflow', data: {
stages: [{ name: 'Stage 1' }, { name: 'Stage 2' }], 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 () => { test('It should update a workflow', async () => {
const res = await requests.admin.put( const res = await requests.admin.put(
`/admin/review-workflows/workflows/${createdWorkflow.id}`, `/admin/review-workflows/workflows/${createdWorkflow.id}`,
{ body: { name: 'updatedWorkflow' } } { body: { data: { name: 'updatedWorkflow' } } }
); );
if (hasRW) { if (hasRW) {
@ -237,11 +241,13 @@ describeOnCondition(edition === 'EE')('Review workflows', () => {
`/admin/review-workflows/workflows/${createdWorkflow.id}?populate=stages`, `/admin/review-workflows/workflows/${createdWorkflow.id}?populate=stages`,
{ {
body: { body: {
name: 'updatedWorkflow', data: {
stages: [ name: 'updatedWorkflow',
{ id: createdWorkflow.stages[0].id, name: 'Stage 1_Updated' }, stages: [
{ name: 'Stage 2' }, { id: createdWorkflow.stages[0].id, name: 'Stage 1_Updated' },
], { name: 'Stage 2' },
],
},
}, },
} }
); );
@ -265,7 +271,7 @@ describeOnCondition(edition === 'EE')('Review workflows', () => {
describe('Delete workflow', () => { describe('Delete workflow', () => {
test('It should delete a workflow', async () => { test('It should delete a workflow', async () => {
const createdRes = await requests.admin.post('/admin/review-workflows/workflows', { 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( const res = await requests.admin.delete(
@ -387,10 +393,12 @@ describeOnCondition(edition === 'EE')('Review workflows', () => {
`/admin/review-workflows/workflows/${testWorkflow.id}?populate=*`, `/admin/review-workflows/workflows/${testWorkflow.id}?populate=*`,
{ {
body: { body: {
stages: [ data: {
defaultStage, stages: [
{ id: secondStage.id, name: secondStage.name, color: '#000000' }, 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 () => { test('It should be available for every connected users (admin)', async () => {
const workflowRes = await requests.admin.put( const workflowRes = await requests.admin.put(
`/admin/review-workflows/workflows/${testWorkflow.id}?populate=*`, `/admin/review-workflows/workflows/${testWorkflow.id}?populate=*`,
{ body: { stages: stagesUpdateData } } { body: { data: { stages: stagesUpdateData } } }
); );
if (hasRW) { 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 () => { test('It should throw an error if trying to delete all stages in a workflow', async () => {
const workflowRes = await requests.admin.put( const workflowRes = await requests.admin.put(
`/admin/review-workflows/workflows/${testWorkflow.id}?populate=*`, `/admin/review-workflows/workflows/${testWorkflow.id}?populate=*`,
{ body: { stages: [] } } { body: { data: { stages: [] } } }
); );
if (hasRW) { 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 () => { test('It should throw an error if trying to create more than 200 stages', async () => {
const stagesRes = await requests.admin.put( const stagesRes = await requests.admin.put(
`/admin/review-workflows/workflows/${testWorkflow.id}?populate=*`, `/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) { if (hasRW) {
@ -468,7 +476,7 @@ describeOnCondition(edition === 'EE')('Review workflows', () => {
// Update workflow to unassign content type // Update workflow to unassign content type
await requests.admin.put( await requests.admin.put(
`/admin/review-workflows/workflows/${testWorkflow.id}?populate=*`, `/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 // Update workflow to unassign content type
await requests.admin.put( await requests.admin.put(
`/admin/review-workflows/workflows/${testWorkflow.id}?populate=*`, `/admin/review-workflows/workflows/${testWorkflow.id}?populate=*`,
{ body: { contentTypes: [] } } { body: { data: { contentTypes: [] } } }
); );
}); });
test('Should not update the entity', async () => { test('Should not update the entity', async () => {
@ -535,7 +543,7 @@ describeOnCondition(edition === 'EE')('Review workflows', () => {
beforeAll(async () => { beforeAll(async () => {
// Update workflow to unassign content type // Update workflow to unassign content type
await requests.admin.put(`/admin/review-workflows/workflows/${testWorkflow.id}?populate=*`, { 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 // Delete last stage stage of the default workflow
await requests.admin.put(`/admin/review-workflows/workflows/${testWorkflow.id}?populate=*`, { 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 // Expect the content in these stages to be moved to the nearest available stage

View File

@ -16,7 +16,7 @@ module.exports = {
const { body } = ctx.request; const { body } = ctx.request;
const { populate } = ctx.query; const { populate } = ctx.query;
const workflowBody = await validateWorkflowCreate(body); const workflowBody = await validateWorkflowCreate(body.data);
const workflowService = getService('workflows'); const workflowService = getService('workflows');
const data = await workflowService.create({ data: workflowBody, populate }); const data = await workflowService.create({ data: workflowBody, populate });
@ -36,7 +36,7 @@ module.exports = {
const { populate } = ctx.query; const { populate } = ctx.query;
const workflowService = getService('workflows'); const workflowService = getService('workflows');
const workflowBody = await validateWorkflowUpdate(body); const workflowBody = await validateWorkflowUpdate(body.data);
const workflow = await workflowService.findById(id, { populate: ['stages'] }); const workflow = await workflowService.findById(id, { populate: ['stages'] });
if (!workflow) { if (!workflow) {