mirror of
https://github.com/strapi/strapi.git
synced 2025-09-22 14:59:07 +00:00
fix(ee): retrieve stage name and ID from updated entity
This commit is contained in:
parent
2ca802bcbd
commit
5985781a9a
@ -2,7 +2,7 @@
|
||||
|
||||
const { omit } = require('lodash/fp');
|
||||
const { WORKFLOW_UPDATE_STAGE } = require('../../../constants/webhookEvents');
|
||||
const { STAGE_MODEL_UID } = require('../../../constants/workflows');
|
||||
const { ENTITY_STAGE_ATTRIBUTE } = require('../../../constants/workflows');
|
||||
const { decorator } = require('../entity-service-decorator')();
|
||||
|
||||
jest.mock('../../../utils');
|
||||
@ -109,22 +109,23 @@ describe('Entity service decorator', () => {
|
||||
const stageToId = 3;
|
||||
|
||||
const defaultService = {
|
||||
update: jest.fn(() => Promise.resolve({ id: entityId })),
|
||||
update: jest.fn(() =>
|
||||
Promise.resolve({
|
||||
id: entityId,
|
||||
[ENTITY_STAGE_ATTRIBUTE]: {
|
||||
id: stageToId,
|
||||
name: `Stage ${stageToId}`,
|
||||
workflow: { id: workflowId },
|
||||
},
|
||||
})
|
||||
),
|
||||
};
|
||||
|
||||
const emit = jest.fn();
|
||||
global.strapi = {
|
||||
...global.strapi,
|
||||
entityService: {
|
||||
findOne: jest.fn((uid, id) => {
|
||||
if (uid === STAGE_MODEL_UID) {
|
||||
return {
|
||||
id,
|
||||
name: `Stage ${id}`,
|
||||
workflow: { id: workflowId },
|
||||
};
|
||||
}
|
||||
|
||||
findOne: jest.fn(() => {
|
||||
return {
|
||||
strapi_reviewWorkflows_stage: {
|
||||
id: stageFromId,
|
||||
|
@ -1,7 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const { isNil, isNull } = require('lodash/fp');
|
||||
const { ENTITY_STAGE_ATTRIBUTE, STAGE_MODEL_UID } = require('../../constants/workflows');
|
||||
const { ENTITY_STAGE_ATTRIBUTE } = require('../../constants/workflows');
|
||||
const { WORKFLOW_UPDATE_STAGE } = require('../../constants/webhookEvents');
|
||||
const { hasReviewWorkflow, getDefaultWorkflow } = require('../../utils/review-workflows');
|
||||
|
||||
@ -66,15 +66,11 @@ const decorator = (service) => ({
|
||||
return service.update.call(this, uid, entityId, { ...opts, data });
|
||||
}
|
||||
|
||||
const newStage = await strapi.entityService.findOne(
|
||||
STAGE_MODEL_UID,
|
||||
data[ENTITY_STAGE_ATTRIBUTE]
|
||||
);
|
||||
const previousStage = await getEntityStage(uid, entityId);
|
||||
|
||||
const updatedEntity = await service.update.call(this, uid, entityId, { ...opts, data });
|
||||
|
||||
if (previousStage?.id && previousStage.id !== newStage.id) {
|
||||
if (previousStage?.id && previousStage.id !== updatedEntity[ENTITY_STAGE_ATTRIBUTE].id) {
|
||||
const model = strapi.getModel(uid);
|
||||
|
||||
strapi.eventHub.emit(WORKFLOW_UPDATE_STAGE, {
|
||||
@ -91,8 +87,8 @@ const decorator = (service) => ({
|
||||
name: previousStage.name,
|
||||
},
|
||||
to: {
|
||||
id: newStage.id,
|
||||
name: newStage.name,
|
||||
id: updatedEntity[ENTITY_STAGE_ATTRIBUTE].id,
|
||||
name: updatedEntity[ENTITY_STAGE_ATTRIBUTE].name,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
Loading…
x
Reference in New Issue
Block a user