fix(ee): api test

This commit is contained in:
Jamie Howard 2023-04-18 09:26:13 +01:00
parent d07a862ec4
commit e78576d03f

View File

@ -1,5 +1,7 @@
'use strict';
const { mapAsync } = require('@strapi/utils');
const { createStrapiInstance } = require('api-tests/strapi');
const { createAuthRequest, createRequest } = require('api-tests/request');
const { createTestBuilder } = require('api-tests/builder');
@ -489,22 +491,21 @@ describeOnCondition(edition === 'EE')('Review workflows', () => {
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.slice(-1)[0].id },
},
}
);
entriesMovedToEnd.push(entry.id);
}
});
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 },
},
}
)
);
// Delete the first and last stage stage of the default workflow
await requests.admin.put(`/admin/review-workflows/workflows/1/stages`, {
@ -513,7 +514,7 @@ describeOnCondition(edition === 'EE')('Review workflows', () => {
// Expect the content in these stages to be moved to the nearest available stage
const productsAfter = await findAll(productUID);
productsAfter.results.forEach(async (entry) => {
await mapAsync(productsAfter.results, async (entry) => {
if (entriesMovedToEnd.includes(entry.id)) {
expect(await entry[ENTITY_STAGE_ATTRIBUTE].name).toEqual(defaultStages[2].name);
return;