From aefb4288ecf7d550df1b74e725bbb6dc245f45d2 Mon Sep 17 00:00:00 2001 From: Marc-Roig Date: Tue, 16 May 2023 14:26:28 +0200 Subject: [PATCH] fix: rw assigned content type filtering test --- ...review-workflows-content-types.test.api.js | 55 ++++++++++--------- .../admin/ee/review-workflows.test.api.js | 8 --- 2 files changed, 29 insertions(+), 34 deletions(-) diff --git a/api-tests/core/admin/ee/review-workflows-content-types.test.api.js b/api-tests/core/admin/ee/review-workflows-content-types.test.api.js index dfd2abe7a3..ad7229984e 100644 --- a/api-tests/core/admin/ee/review-workflows-content-types.test.api.js +++ b/api-tests/core/admin/ee/review-workflows-content-types.test.api.js @@ -1,12 +1,11 @@ 'use strict'; const { createStrapiInstance } = require('api-tests/strapi'); -const { createAuthRequest, createRequest } = require('api-tests/request'); +const { createAuthRequest } = require('api-tests/request'); const { createTestBuilder } = require('api-tests/builder'); const { describeOnCondition } = require('api-tests/utils'); const { - STAGE_MODEL_UID, WORKFLOW_MODEL_UID, ENTITY_STAGE_ATTRIBUTE, } = require('../../../../packages/core/admin/ee/server/constants/workflows'); @@ -99,12 +98,10 @@ describeOnCondition(edition === 'EE')('Review workflows', () => { await builder.cleanup(); }); - beforeEach(async () => {}); - describe('Create workflow', () => { let workflow1, workflow2; - describe('Basic', () => { + describe('Create workflow and assign content type', () => { test('Can create and assign a content type', async () => { const res = await createWorkflow({ contentTypes: [productUID] }); @@ -123,8 +120,8 @@ describeOnCondition(edition === 'EE')('Review workflows', () => { }); }); - describe('Steal content type', () => { - test('Can create stealing content type from another', async () => { + describe('Create workflow and steal content type from another workflow', () => { + test('Can create workflow stealing content type from another', async () => { const res = await createWorkflow({ contentTypes: [productUID], stages: [{ name: 'Review' }], @@ -256,6 +253,26 @@ describeOnCondition(edition === 'EE')('Review workflows', () => { }); }); + describe('Creating an entity in a review workflow content type', () => { + let workflow; + test('when content type is assigned to workflow, new entries should be added to the first stage of the default workflow', async () => { + // Create a workflow with product content type + workflow = await createWorkflow({ contentTypes: [productUID] }).then((res) => res.body.data); + + const entry = await createEntry(productUID, { name: 'Product' }); + expect(await entry[ENTITY_STAGE_ATTRIBUTE].id).toEqual(workflow.stages[0].id); + }); + + // Depends on the previous test + test('when content type is not assigned to workflow, new entries should have a null stage', async () => { + // Unassign product content type from default workflow + await updateWorkflow(workflow.id, { contentTypes: [] }); + + const entry = await createEntry(productUID, { name: 'Product' }); + expect(await entry[ENTITY_STAGE_ATTRIBUTE]).toBeNull(); + }); + }); + describe('Get workflows', () => { let workflow1, workflow2; @@ -284,26 +301,12 @@ describeOnCondition(edition === 'EE')('Review workflows', () => { expect(workflows).toHaveLength(1); expect(workflows[0]).toMatchObject({ id: workflow2.id }); - }); - }); - describe('Creating an entity in a review workflow content type', () => { - let workflow; - - test('when content type is assigned to workflow, new entries should be added to the first stage of the default workflow', async () => { - // Create a workflow with product content type - await createWorkflow({ contentTypes: [productUID] }); - - const entry = await createEntry(productUID, { name: 'Product' }); - expect(await entry[ENTITY_STAGE_ATTRIBUTE].name).toEqual(defaultStages[0].name); - }); - - test('when content type is not assigned to workflow, new entries should have a null stage', async () => { - // Unassign product content type from default workflow - await updateWorkflow(workflow.id, { contentTypes: [] }); - - const entry = await createEntry(productUID, { name: 'Product' }); - expect(await entry[ENTITY_STAGE_ATTRIBUTE]).toBeNull(); + // To avoid breaking other tests + await strapi.db.query(WORKFLOW_MODEL_UID).update({ + where: { id: workflow1.id }, + data: { contentTypes: [] }, + }); }); }); }); 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 d698990dea..125e3ca3cc 100644 --- a/api-tests/core/admin/ee/review-workflows.test.api.js +++ b/api-tests/core/admin/ee/review-workflows.test.api.js @@ -13,8 +13,6 @@ const { ENTITY_STAGE_ATTRIBUTE, } = require('../../../../packages/core/admin/ee/server/constants/workflows'); -const defaultStages = require('../../../../packages/core/admin/ee/server/constants/default-stages.json'); - const edition = process.env.STRAPI_DISABLE_EE === 'true' ? 'CE' : 'EE'; const productUID = 'api::product.product'; @@ -82,12 +80,6 @@ describeOnCondition(edition === 'EE')('Review workflows', () => { expect(result.statusCode).toBe(201); }; - const restart = async () => { - await strapi.destroy(); - strapi = await createStrapiInstance(); - requests.admin = await createAuthRequest({ strapi }); - }; - beforeAll(async () => { await builder.addContentTypes([model]).build(); // eslint-disable-next-line node/no-extraneous-require