mirror of
https://github.com/strapi/strapi.git
synced 2025-11-01 18:33:55 +00:00
fix: flaky test
This commit is contained in:
parent
e386aff3d5
commit
c55bc192b2
@ -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);
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user