fix: flaky test

This commit is contained in:
Marc-Roig 2023-04-25 10:22:35 +02:00
parent e386aff3d5
commit c55bc192b2

View File

@ -54,6 +54,15 @@ describeOnCondition(edition === 'EE')('Review workflows', () => {
return body; 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 findAll = async (uid) => {
const { body } = await requests.admin({ const { body } = await requests.admin({
method: 'GET', method: 'GET',
@ -492,40 +501,26 @@ describeOnCondition(edition === 'EE')('Review workflows', () => {
describe('Deleting a stage when content already exists', () => { 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 () => { 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 products = await findAll(productUID);
const res = await requests.admin.get(`/admin/review-workflows/workflows/1/stages`);
const defaultStages = res.body.data;
const productsBefore = await findAll(productUID); // Move the first half of the entries to the last stage,
const entriesMovedToEnd = productsBefore.results // and the second half to the first stage
.filter((entry) => entry.id % 2 === 0) await mapAsync(products.results, async (entity) =>
.map((entry) => entry.id); updateEntry(productUID, entity.id, {
[ENTITY_STAGE_ATTRIBUTE]: entity.id % 2 ? defaultStage.id : secondStage.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 },
},
}
)
); );
// Delete the first and last stage stage of the default workflow // Delete last stage stage of the default workflow
await requests.admin.put(`/admin/review-workflows/workflows/1/stages`, { await requests.admin.put(`/admin/review-workflows/workflows/${testWorkflow.id}/stages`, {
body: { data: defaultStages.slice(1, defaultStages.length - 1) }, body: { data: [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
const productsAfter = await findAll(productUID); const productsAfter = await findAll(productUID);
await mapAsync(productsAfter.results, async (entry) => { for (const entry of productsAfter.results) {
if (entriesMovedToEnd.includes(entry.id)) { expect(entry[ENTITY_STAGE_ATTRIBUTE].name).toEqual(defaultStage.name);
expect(await entry[ENTITY_STAGE_ATTRIBUTE].name).toEqual(defaultStages[2].name); }
return;
}
expect(await entry[ENTITY_STAGE_ATTRIBUTE].name).toEqual(defaultStages[1].name);
});
}); });
}); });
}); });