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 d76f174816..3c7f131052 100644 --- a/api-tests/core/admin/ee/review-workflows.test.api.js +++ b/api-tests/core/admin/ee/review-workflows.test.api.js @@ -11,6 +11,7 @@ const { STAGE_MODEL_UID, WORKFLOW_MODEL_UID, ENTITY_STAGE_ATTRIBUTE, + ENTITY_ASSIGNEE_ATTRIBUTE, } = require('../../../../packages/core/admin/ee/server/constants/workflows'); const defaultStages = require('../../../../packages/core/admin/ee/server/constants/default-stages.json'); @@ -552,4 +553,78 @@ describeOnCondition(edition === 'EE')('Review workflows', () => { } }); }); + + describe('Update assignee on an entity', () => { + describe('Review Workflow is enabled', () => { + beforeAll(async () => { + await updateContentType(productUID, { + components: [], + contentType: { ...model, reviewWorkflows: true }, + }); + await restart(); + }); + + test('Should update the assignee on an entity', async () => { + const entry = await createEntry(productUID, { name: 'Product' }); + const user = requests.admin.getLoggedUser(); + + const response = await requests.admin({ + method: 'PUT', + url: `/admin/content-manager/collection-types/${productUID}/${entry.id}/assignee`, + body: { + data: { id: user.id }, + }, + }); + + expect(response.status).toEqual(200); + const assignee = response.body.data[ENTITY_ASSIGNEE_ATTRIBUTE]; + expect(assignee.id).toEqual(user.id); + expect(assignee).not.toHaveProperty('password'); + }); + + test('Should throw an error if user does not exist', async () => { + const entry = await createEntry(productUID, { name: 'Product' }); + + const response = await requests.admin({ + method: 'PUT', + url: `/admin/content-manager/collection-types/${productUID}/${entry.id}/assignee`, + body: { + data: { id: 1234 }, + }, + }); + + expect(response.status).toEqual(400); + expect(response.body.error).toBeDefined(); + expect(response.body.error.name).toEqual('ApplicationError'); + expect(response.body.error.message).toEqual('Selected user does not exist'); + }); + }); + + describe('Review Workflow is disabled', () => { + beforeAll(async () => { + await updateContentType(productUID, { + components: [], + contentType: { ...model, reviewWorkflows: false }, + }); + await restart(); + }); + + test('Should not update the entity', async () => { + const entry = await createEntry(productUID, { name: 'Product' }); + const user = requests.admin.getLoggedUser(); + + const response = await requests.admin({ + method: 'PUT', + url: `/admin/content-manager/collection-types/${productUID}/${entry.id}/assignee`, + body: { + data: { id: user.id }, + }, + }); + + expect(response.status).toEqual(400); + expect(response.body.error).toBeDefined(); + expect(response.body.error.name).toBe('ApplicationError'); + }); + }); + }); });