From c55bc192b23686392e59a519572aa8d7b0053afc Mon Sep 17 00:00:00 2001 From: Marc-Roig Date: Tue, 25 Apr 2023 10:22:35 +0200 Subject: [PATCH] fix: flaky test --- .../admin/ee/review-workflows.test.api.js | 49 +++++++++---------- 1 file changed, 22 insertions(+), 27 deletions(-) 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 c21cb4d975..bebe7958f1 100644 --- a/api-tests/core/admin/ee/review-workflows.test.api.js +++ b/api-tests/core/admin/ee/review-workflows.test.api.js @@ -54,6 +54,15 @@ describeOnCondition(edition === 'EE')('Review workflows', () => { return body; }; + const updateEntry = async (uid, id, data) => { + const { body } = await requests.admin({ + method: 'PUT', + url: `/content-manager/collection-types/${uid}/${id}`, + body: data, + }); + return body; + }; + const findAll = async (uid) => { const { body } = await requests.admin({ method: 'GET', @@ -492,40 +501,26 @@ describeOnCondition(edition === 'EE')('Review workflows', () => { 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; + const products = await findAll(productUID); - const productsBefore = await findAll(productUID); - const entriesMovedToEnd = productsBefore.results - .filter((entry) => entry.id % 2 === 0) - .map((entry) => entry.id); - - await mapAsync(entriesMovedToEnd, async (entityId) => - requests.admin.put( - `/admin/content-manager/collection-types/${productUID}/${entityId}/stage`, - { - body: { - data: { id: defaultStages.slice(-1)[0].id }, - }, - } - ) + // Move the first half of the entries to the last stage, + // and the second half to the first stage + await mapAsync(products.results, async (entity) => + updateEntry(productUID, entity.id, { + [ENTITY_STAGE_ATTRIBUTE]: entity.id % 2 ? defaultStage.id : secondStage.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) }, + // Delete last stage stage of the default workflow + await requests.admin.put(`/admin/review-workflows/workflows/${testWorkflow.id}/stages`, { + body: { data: [defaultStage] }, }); // Expect the content in these stages to be moved to the nearest available stage const productsAfter = await findAll(productUID); - await mapAsync(productsAfter.results, 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); - }); + for (const entry of productsAfter.results) { + expect(entry[ENTITY_STAGE_ATTRIBUTE].name).toEqual(defaultStage.name); + } }); }); });