fix: review workflow assignee tests

This commit is contained in:
Marc-Roig 2023-07-19 17:16:34 +02:00
commit adc01fcb9f
No known key found for this signature in database
GPG Key ID: FB4E2C43A0BEE249

View File

@ -118,7 +118,7 @@ describeOnCondition(edition === 'EE')('Review workflows', () => {
where: { id: testWorkflow.id },
data: {
uid: 'workflow',
stages: [defaultStage.id, secondStage.id],
stages: { set: [defaultStage.id, secondStage.id] },
},
});
defaultStage = await strapi.query(STAGE_MODEL_UID).update({
@ -129,10 +129,6 @@ describeOnCondition(edition === 'EE')('Review workflows', () => {
where: { id: secondStage.id },
data: { name: 'Stage 2' },
});
await updateContentType(productUID, {
components: [],
contentType: model,
});
});
describe('Get workflows', () => {
@ -500,6 +496,78 @@ describeOnCondition(edition === 'EE')('Review workflows', () => {
});
});
describe('Update assignee on an entity', () => {
describe('Review Workflow is enabled', () => {
beforeAll(async () => {
// Assign Product to workflow so workflow is active on this CT
await requests.admin.put(
`/admin/review-workflows/workflows/${testWorkflow.id}?populate=*`,
{ body: { data: { contentTypes: [productUID] } } }
);
});
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 () => {
// Unassign Product to workflow so workflow is inactive on this CT
await requests.admin.put(
`/admin/review-workflows/workflows/${testWorkflow.id}?populate=*`,
{ body: { data: { contentTypes: [] } } }
);
});
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');
});
});
});
describe('Update a stage on an entity', () => {
describe('Review Workflow is enabled', () => {
beforeAll(async () => {
@ -600,78 +668,4 @@ 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');
});
});
});
});