From 0f4c20852080443c2212a402480bf548aaa151e2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20de=20Juvigny?= Date: Thu, 1 Aug 2024 16:11:21 +0200 Subject: [PATCH] Revert "chore: delete api tests for deleted review workflows route" This reverts commit 2b4e5ebd4101eb6e15ae45791ae0ff56e0208e6f. --- ...review-workflows-content-types.test.api.ts | 4 +- .../review-workflows.test.api.ts | 66 +++++++++++++++++-- 2 files changed, 64 insertions(+), 6 deletions(-) diff --git a/tests/api/core/review-workflows/review-workflows-content-types.test.api.ts b/tests/api/core/review-workflows/review-workflows-content-types.test.api.ts index e452acb912..d3f2d90a19 100644 --- a/tests/api/core/review-workflows/review-workflows-content-types.test.api.ts +++ b/tests/api/core/review-workflows/review-workflows-content-types.test.api.ts @@ -72,8 +72,8 @@ describeOnCondition(edition === 'EE')('Review workflows - Content Types', () => }; const getWorkflow = async (id) => { - const { body } = await requests.admin.get(`/review-workflows/workflows?populate=*`); - return body.data.find((workflow) => workflow.id === id); + const { body } = await requests.admin.get(`/review-workflows/workflows/${id}?populate=*`); + return body.data; }; const getWorkflows = async (filters) => { diff --git a/tests/api/core/review-workflows/review-workflows.test.api.ts b/tests/api/core/review-workflows/review-workflows.test.api.ts index 5055639631..b8dcbe76a7 100644 --- a/tests/api/core/review-workflows/review-workflows.test.api.ts +++ b/tests/api/core/review-workflows/review-workflows.test.api.ts @@ -170,6 +170,32 @@ describeOnCondition(edition === 'EE')('Review workflows', () => { }); }); + describe('Get one workflow', () => { + test("It shouldn't be available for public", async () => { + const res = await requests.public.get(`/review-workflows/workflows/${testWorkflow.id}`); + + if (hasRW) { + expect(res.status).toBe(401); + } else { + expect(res.status).toBe(404); + expect(res.body.data).toBeUndefined(); + } + }); + test('It should be available for every connected users (admin)', async () => { + const res = await requests.admin.get(`/review-workflows/workflows/${testWorkflow.id}`); + + if (hasRW) { + expect(res.status).toBe(200); + expect(res.body.data).toBeInstanceOf(Object); + expect(res.body.data).toEqual(testWorkflow); + expect(typeof res.body.meta.workflowCount).toBe('number'); + } else { + expect(res.status).toBe(404); + expect(res.body.data).toBeUndefined(); + } + }); + }); + describe('Create workflow', () => { test('It should create a workflow without stages', async () => { const res = await requests.admin.post('/review-workflows/workflows', { @@ -283,6 +309,36 @@ describeOnCondition(edition === 'EE')('Review workflows', () => { }); }); + describe('Get workflow stages', () => { + test("It shouldn't be available for public", async () => { + const res = await requests.public.get( + `/review-workflows/workflows/${testWorkflow.id}?populate=stages` + ); + + if (hasRW) { + expect(res.status).toBe(401); + } else { + expect(res.status).toBe(404); + expect(res.body.data).toBeUndefined(); + } + }); + test('It should be available for every connected users (admin)', async () => { + const res = await requests.admin.get( + `/review-workflows/workflows/${testWorkflow.id}?populate=stages` + ); + + if (hasRW) { + expect(res.status).toBe(200); + expect(res.body.data).toBeInstanceOf(Object); + expect(res.body.data.stages).toBeInstanceOf(Array); + expect(res.body.data.stages).toHaveLength(2); + } else { + expect(res.status).toBe(404); + expect(Array.isArray(res.body)).toBeFalsy(); + } + }); + }); + describe('Get stages', () => { test("It shouldn't be available for public", async () => { const res = await requests.public.get( @@ -370,13 +426,15 @@ describeOnCondition(edition === 'EE')('Review workflows', () => { expect(workflowRes.body.data.stages[1].color).toBe('#000000'); }); test("It shouldn't be available for public", async () => { - const workflowsRes = await requests.public.get(`/review-workflows/workflows?populate=*`); + const workflowRes = await requests.public.get( + `/review-workflows/workflows/${testWorkflow.id}?populate=*` + ); if (hasRW) { - expect(workflowsRes.status).toBe(401); + expect(workflowRes.status).toBe(401); } else { - expect(workflowsRes.status).toBe(404); - expect(workflowsRes.body.data).toBeUndefined(); + expect(workflowRes.status).toBe(404); + expect(workflowRes.body.data).toBeUndefined(); } }); test('It should be available for every connected users (admin)', async () => {