mirror of
https://github.com/strapi/strapi.git
synced 2025-09-26 08:52:26 +00:00
test(review-workflows): API test for RW down migration
This commit is contained in:
parent
1a77c49380
commit
ccf36d4436
@ -29,7 +29,7 @@ describe('disableReviewWorkFlows', () => {
|
|||||||
disableReviewWorkFlows({ oldContentTypes, contentTypes });
|
disableReviewWorkFlows({ oldContentTypes, contentTypes });
|
||||||
|
|
||||||
expect(whereInSpy).toHaveBeenCalledTimes(1);
|
expect(whereInSpy).toHaveBeenCalledTimes(1);
|
||||||
expect(whereInSpy).toHaveBeenCalledWith('id', ['U1', 'U3']);
|
expect(whereInSpy).toHaveBeenCalledWith('related_type', ['U1', 'U3']);
|
||||||
expect(delSpy).toHaveBeenCalledTimes(1);
|
expect(delSpy).toHaveBeenCalledTimes(1);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -14,7 +14,7 @@ const hasRWEnabled = (contentType) => contentType?.options?.reviewWorkflows || f
|
|||||||
const disableReviewWorkFlows = async ({ oldContentTypes, contentTypes }) => {
|
const disableReviewWorkFlows = async ({ oldContentTypes, contentTypes }) => {
|
||||||
const uidsToRemove = [];
|
const uidsToRemove = [];
|
||||||
for (const uid in contentTypes) {
|
for (const uid in contentTypes) {
|
||||||
if (!oldContentTypes[uid]) {
|
if (!oldContentTypes || !oldContentTypes[uid]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -34,7 +34,7 @@ const disableReviewWorkFlows = async ({ oldContentTypes, contentTypes }) => {
|
|||||||
|
|
||||||
await strapi.db
|
await strapi.db
|
||||||
.connection('strapi_workflows_stages_related_morphs')
|
.connection('strapi_workflows_stages_related_morphs')
|
||||||
.whereIn('id', uidsToRemove)
|
.whereIn('related_type', uidsToRemove)
|
||||||
.del();
|
.del();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -316,8 +316,8 @@ describeOnCondition(edition === 'EE')('Review workflows', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Enable review workflows on a content type', () => {
|
describe('Enabling/Disabling review workflows on a content type', () => {
|
||||||
test('When enabled entries in the content type should be added to the first stage of a workflow', async () => {
|
test('when disabled entries in the content type should be removed from any workflow stage', async () => {
|
||||||
await createEntry(productUID, { name: 'Product' });
|
await createEntry(productUID, { name: 'Product' });
|
||||||
await createEntry(productUID, { name: 'Product 1' });
|
await createEntry(productUID, { name: 'Product 1' });
|
||||||
await createEntry(productUID, { name: 'Product 2' });
|
await createEntry(productUID, { name: 'Product 2' });
|
||||||
@ -326,7 +326,12 @@ describeOnCondition(edition === 'EE')('Review workflows', () => {
|
|||||||
components: [],
|
components: [],
|
||||||
contentType: { ...model, reviewWorkflows: true },
|
contentType: { ...model, reviewWorkflows: true },
|
||||||
});
|
});
|
||||||
|
await restart();
|
||||||
|
|
||||||
|
await updateContentType(productUID, {
|
||||||
|
components: [],
|
||||||
|
contentType: { ...model, reviewWorkflows: false },
|
||||||
|
});
|
||||||
await restart();
|
await restart();
|
||||||
|
|
||||||
const res = await requests.admin({
|
const res = await requests.admin({
|
||||||
@ -334,7 +339,7 @@ describeOnCondition(edition === 'EE')('Review workflows', () => {
|
|||||||
url: `/content-type-builder/content-types/api::product.product`,
|
url: `/content-type-builder/content-types/api::product.product`,
|
||||||
});
|
});
|
||||||
|
|
||||||
expect(res.body.data.schema.reviewWorkflows).toBeTruthy();
|
expect(res.body.data.schema.reviewWorkflows).toBeFalsy();
|
||||||
|
|
||||||
const connection = strapi.db.getConnection();
|
const connection = strapi.db.getConnection();
|
||||||
const RWMorphTableResults = await connection
|
const RWMorphTableResults = await connection
|
||||||
@ -342,12 +347,7 @@ describeOnCondition(edition === 'EE')('Review workflows', () => {
|
|||||||
.from('strapi_workflows_stages_related_morphs')
|
.from('strapi_workflows_stages_related_morphs')
|
||||||
.where('related_type', productUID);
|
.where('related_type', productUID);
|
||||||
|
|
||||||
expect(RWMorphTableResults.length).toEqual(3);
|
expect(RWMorphTableResults.length).toEqual(0);
|
||||||
for (let i = 0; i < RWMorphTableResults.length; i += 1) {
|
|
||||||
const entry = RWMorphTableResults[i];
|
|
||||||
expect(entry.related_id).toEqual(i + 1);
|
|
||||||
expect(entry.order).toEqual(1);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user