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 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 },
});
};

View File

@ -30,7 +30,7 @@ const model = {
},
options: {
reviewWorkflows: true,
}
},
};
describeOnCondition(edition === 'EE')('Review workflows', () => {
@ -180,9 +180,11 @@ 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: {
data: {
name: 'testWorkflow',
stages: [],
},
},
});
if (hasRW) {
@ -196,9 +198,11 @@ 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: {
data: {
name: 'createdWorkflow',
stages: [{ name: 'Stage 1' }, { name: 'Stage 2' }],
},
},
});
if (hasRW) {
@ -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,12 +241,14 @@ describeOnCondition(edition === 'EE')('Review workflows', () => {
`/admin/review-workflows/workflows/${createdWorkflow.id}?populate=stages`,
{
body: {
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,11 +393,13 @@ describeOnCondition(edition === 'EE')('Review workflows', () => {
`/admin/review-workflows/workflows/${testWorkflow.id}?populate=*`,
{
body: {
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

View File

@ -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) {