From 9be3f27b6185c7a94b2ccd7f1815c88b7cd2c0c0 Mon Sep 17 00:00:00 2001 From: Jamie Howard Date: Wed, 29 Mar 2023 15:33:10 +0100 Subject: [PATCH] test(ee): API test for moving entities to nearest available stage --- .../server/tests/review-workflows.test.api.js | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/packages/core/admin/ee/server/tests/review-workflows.test.api.js b/packages/core/admin/ee/server/tests/review-workflows.test.api.js index ff7fcda880..bab063d6c4 100644 --- a/packages/core/admin/ee/server/tests/review-workflows.test.api.js +++ b/packages/core/admin/ee/server/tests/review-workflows.test.api.js @@ -51,6 +51,14 @@ describeOnCondition(edition === 'EE')('Review workflows', () => { return body; }; + const findAll = async (uid) => { + const { body } = await requests.admin({ + method: 'GET', + url: `/content-manager/collection-types/${uid}`, + }); + return body; + }; + const updateContentType = async (uid, data) => { const result = await requests.admin({ method: 'PUT', @@ -457,4 +465,44 @@ describeOnCondition(edition === 'EE')('Review workflows', () => { expect(await adminResponse[ENTITY_STAGE_ATTRIBUTE].name).toEqual(defaultStages[0].name); }); }); + + describe('Deleting a stage when content already exists', () => { + test('When content exists in a review stage and this stage is deleted, the content should be moved to the nearest available stage', async () => { + // Get the default workflow stages + const res = await requests.admin.get(`/admin/review-workflows/workflows/1/stages`); + const defaultStages = res.body.data; + + // Get all products and move ~30% of them to the last stage of the workflow + const entriesMovedToEnd = []; + const productsBefore = await findAll(productUID); + productsBefore.results.forEach(async (entry) => { + if (Math.random() < 0.3) { + await requests.admin.put( + `/admin/content-manager/collection-types/${productUID}/${entry.id}/stage`, + { + body: { + data: { id: defaultStages.at(-1).id }, + }, + } + ); + entriesMovedToEnd.push(entry.id); + } + }); + + // Delete the first and last stage stage of the default workflow + await requests.admin.put(`/admin/review-workflows/workflows/1/stages`, { + body: { data: defaultStages.slice(1, defaultStages.length - 1) }, + }); + + // Expect the content in these stages to be moved to the nearest available stage + const productsAfter = await findAll(productUID); + productsAfter.results.forEach(async (entry) => { + if (entriesMovedToEnd.includes(entry.id)) { + expect(await entry[ENTITY_STAGE_ATTRIBUTE].name).toEqual(defaultStages[2].name); + return; + } + expect(await entry[ENTITY_STAGE_ATTRIBUTE].name).toEqual(defaultStages[1].name); + }); + }); + }); });