mirror of
https://github.com/strapi/strapi.git
synced 2025-10-22 21:43:53 +00:00
fix: rw assigned content type filtering test
This commit is contained in:
parent
5bd4a99280
commit
aefb4288ec
@ -1,12 +1,11 @@
|
|||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
const { createStrapiInstance } = require('api-tests/strapi');
|
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 { createTestBuilder } = require('api-tests/builder');
|
||||||
const { describeOnCondition } = require('api-tests/utils');
|
const { describeOnCondition } = require('api-tests/utils');
|
||||||
|
|
||||||
const {
|
const {
|
||||||
STAGE_MODEL_UID,
|
|
||||||
WORKFLOW_MODEL_UID,
|
WORKFLOW_MODEL_UID,
|
||||||
ENTITY_STAGE_ATTRIBUTE,
|
ENTITY_STAGE_ATTRIBUTE,
|
||||||
} = require('../../../../packages/core/admin/ee/server/constants/workflows');
|
} = require('../../../../packages/core/admin/ee/server/constants/workflows');
|
||||||
@ -99,12 +98,10 @@ describeOnCondition(edition === 'EE')('Review workflows', () => {
|
|||||||
await builder.cleanup();
|
await builder.cleanup();
|
||||||
});
|
});
|
||||||
|
|
||||||
beforeEach(async () => {});
|
|
||||||
|
|
||||||
describe('Create workflow', () => {
|
describe('Create workflow', () => {
|
||||||
let workflow1, workflow2;
|
let workflow1, workflow2;
|
||||||
|
|
||||||
describe('Basic', () => {
|
describe('Create workflow and assign content type', () => {
|
||||||
test('Can create and assign a content type', async () => {
|
test('Can create and assign a content type', async () => {
|
||||||
const res = await createWorkflow({ contentTypes: [productUID] });
|
const res = await createWorkflow({ contentTypes: [productUID] });
|
||||||
|
|
||||||
@ -123,8 +120,8 @@ describeOnCondition(edition === 'EE')('Review workflows', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Steal content type', () => {
|
describe('Create workflow and steal content type from another workflow', () => {
|
||||||
test('Can create stealing content type from another', async () => {
|
test('Can create workflow stealing content type from another', async () => {
|
||||||
const res = await createWorkflow({
|
const res = await createWorkflow({
|
||||||
contentTypes: [productUID],
|
contentTypes: [productUID],
|
||||||
stages: [{ name: 'Review' }],
|
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', () => {
|
describe('Get workflows', () => {
|
||||||
let workflow1, workflow2;
|
let workflow1, workflow2;
|
||||||
|
|
||||||
@ -284,26 +301,12 @@ describeOnCondition(edition === 'EE')('Review workflows', () => {
|
|||||||
|
|
||||||
expect(workflows).toHaveLength(1);
|
expect(workflows).toHaveLength(1);
|
||||||
expect(workflows[0]).toMatchObject({ id: workflow2.id });
|
expect(workflows[0]).toMatchObject({ id: workflow2.id });
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('Creating an entity in a review workflow content type', () => {
|
// To avoid breaking other tests
|
||||||
let workflow;
|
await strapi.db.query(WORKFLOW_MODEL_UID).update({
|
||||||
|
where: { id: workflow1.id },
|
||||||
test('when content type is assigned to workflow, new entries should be added to the first stage of the default workflow', async () => {
|
data: { contentTypes: [] },
|
||||||
// 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();
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -13,8 +13,6 @@ const {
|
|||||||
ENTITY_STAGE_ATTRIBUTE,
|
ENTITY_STAGE_ATTRIBUTE,
|
||||||
} = require('../../../../packages/core/admin/ee/server/constants/workflows');
|
} = 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 edition = process.env.STRAPI_DISABLE_EE === 'true' ? 'CE' : 'EE';
|
||||||
|
|
||||||
const productUID = 'api::product.product';
|
const productUID = 'api::product.product';
|
||||||
@ -82,12 +80,6 @@ describeOnCondition(edition === 'EE')('Review workflows', () => {
|
|||||||
expect(result.statusCode).toBe(201);
|
expect(result.statusCode).toBe(201);
|
||||||
};
|
};
|
||||||
|
|
||||||
const restart = async () => {
|
|
||||||
await strapi.destroy();
|
|
||||||
strapi = await createStrapiInstance();
|
|
||||||
requests.admin = await createAuthRequest({ strapi });
|
|
||||||
};
|
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
await builder.addContentTypes([model]).build();
|
await builder.addContentTypes([model]).build();
|
||||||
// eslint-disable-next-line node/no-extraneous-require
|
// eslint-disable-next-line node/no-extraneous-require
|
||||||
|
Loading…
x
Reference in New Issue
Block a user