mirror of
https://github.com/strapi/strapi.git
synced 2025-11-01 18:33:55 +00:00
fix(ee): entity service decorator tests
This commit is contained in:
parent
0bba0878f4
commit
ed5fe3766d
@ -1,6 +1,7 @@
|
||||
'use strict';
|
||||
|
||||
const { omit } = require('lodash/fp');
|
||||
const { WORKFLOW_UPDATE_STAGE } = require('../../../constants/webhookEvents');
|
||||
const { decorator } = require('../entity-service-decorator')();
|
||||
|
||||
jest.mock('../../../utils');
|
||||
@ -80,6 +81,8 @@ describe('Entity service decorator', () => {
|
||||
});
|
||||
|
||||
describe('Update', () => {
|
||||
const uid = 'test-model';
|
||||
|
||||
test('Calls original update for non review workflow content types', async () => {
|
||||
const entry = {
|
||||
id: 1,
|
||||
@ -105,15 +108,23 @@ describe('Entity service decorator', () => {
|
||||
|
||||
const defaultService = {
|
||||
update: jest.fn(() => Promise.resolve(entry)),
|
||||
findOne: jest.fn(() => {
|
||||
return { strapi_reviewWorkflows_stage: { id: 2 } };
|
||||
}),
|
||||
emitEvent: jest.fn(),
|
||||
};
|
||||
|
||||
const service = decorator(defaultService);
|
||||
|
||||
const id = 1;
|
||||
const input = { data: { title: 'title ', strapi_reviewWorkflows_stage: 1 } };
|
||||
await service.update('test-model', id, input);
|
||||
await service.update(uid, id, input);
|
||||
|
||||
expect(defaultService.update).toHaveBeenCalledWith('test-model', id, {
|
||||
expect(defaultService.emitEvent).toHaveBeenCalledWith(uid, WORKFLOW_UPDATE_STAGE, {
|
||||
id,
|
||||
});
|
||||
|
||||
expect(defaultService.update).toHaveBeenCalledWith(uid, id, {
|
||||
...input,
|
||||
data: {
|
||||
...input.data,
|
||||
@ -135,9 +146,9 @@ describe('Entity service decorator', () => {
|
||||
|
||||
const id = 1;
|
||||
const input = { data: { title: 'title ', strapi_reviewWorkflows_stage: null } };
|
||||
await service.update('test-model', id, input);
|
||||
await service.update(uid, id, input);
|
||||
|
||||
expect(defaultService.update).toHaveBeenCalledWith('test-model', id, {
|
||||
expect(defaultService.update).toHaveBeenCalledWith(uid, id, {
|
||||
...input,
|
||||
data: {
|
||||
...omit('strapi_reviewWorkflows_stage', input.data),
|
||||
|
||||
@ -44,15 +44,16 @@ const decorator = (service) => ({
|
||||
const data = { ...opts.data };
|
||||
if (isNull(data[ENTITY_STAGE_ATTRIBUTE])) {
|
||||
delete data[ENTITY_STAGE_ATTRIBUTE];
|
||||
return service.update.call(this, uid, entityId, { ...opts, data });
|
||||
}
|
||||
|
||||
const updatedEntity = await service.update.call(this, uid, entityId, { ...opts, data });
|
||||
|
||||
const entity = await service.findOne.call(this, uid, entityId, {
|
||||
populate: [ENTITY_STAGE_ATTRIBUTE],
|
||||
});
|
||||
const previousStageId = entity?.[ENTITY_STAGE_ATTRIBUTE]?.id ?? null;
|
||||
|
||||
const updatedEntity = await service.update.call(this, uid, entityId, { ...opts, data });
|
||||
|
||||
if (previousStageId && previousStageId !== data[ENTITY_STAGE_ATTRIBUTE]) {
|
||||
await service.emitEvent.call(this, uid, WORKFLOW_UPDATE_STAGE, updatedEntity);
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user