diff --git a/packages/component-fixture-manager/src/fixtures/fragments.js b/packages/component-fixture-manager/src/fixtures/fragments.js index 85465027c31f377649ccd1d533626e03f895cfd2..0478b2aa9c53fa0174cb337c15c79e5d44b5bc3d 100644 --- a/packages/component-fixture-manager/src/fixtures/fragments.js +++ b/packages/component-fixture-manager/src/fixtures/fragments.js @@ -459,6 +459,48 @@ const fragments = { updatedOn: chance.timestamp(), submittedOn: chance.timestamp(), }, + { + recommendation: 'publish', + recommendationType: 'editorRecommendation', + comments: [ + { + content: chance.paragraph(), + public: true, + files: [ + { + id: chance.guid(), + name: 'file.pdf', + size: chance.natural(), + }, + ], + }, + ], + id: chance.guid(), + userId: handlingEditor.id, + createdOn: 1542361074012, + updatedOn: chance.timestamp(), + }, + { + recommendation: 'return-to-handling-editor', + recommendationType: 'editorRecommendation', + comments: [ + { + content: chance.paragraph(), + public: true, + files: [ + { + id: chance.guid(), + name: 'file.pdf', + size: chance.natural(), + }, + ], + }, + ], + id: chance.guid(), + userId: handlingEditor.id, + createdOn: 1542361115749, + updatedOn: chance.timestamp(), + }, ], authors: [ { diff --git a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/post.js b/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/post.js index 60cbb6a90175cce2ff1ec2a224c9f7da35197721..1c24847aecf8afc5ad66fe6c5a8be0045fec83c5 100644 --- a/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/post.js +++ b/packages/component-manuscript-manager/src/routes/fragmentsRecommendations/post.js @@ -45,6 +45,9 @@ module.exports = models => async (req, res) => { r => r.userId === req.user, ) + const returnToHERecommendations = get(fragment, 'recommendations', []).filter( + r => r.recommendation === 'return-to-handling-editor', + ) const authsome = authsomeHelper.getAuthsome(models) const target = { fragment, @@ -84,9 +87,15 @@ module.exports = models => async (req, res) => { .status(400) .json({ error: 'Cannot write another review on this version.' }) } - return res - .status(400) - .json({ error: 'Cannot make another recommendation on this version.' }) + if ( + recommendationType === recommendations.type.editor && + last(returnToHERecommendations).createdOn < + last(currentUserRecommendation).createdOn + ) { + return res + .status(400) + .json({ error: 'Cannot make another recommendation on this version.' }) + } } if ( diff --git a/packages/component-manuscript-manager/src/tests/fragmentsRecommendations/post.test.js b/packages/component-manuscript-manager/src/tests/fragmentsRecommendations/post.test.js index 9f67766c989813e767b6d32299d1d9f5b9e4d85e..fa1cf243d4793e33a5dcb004499ebb11b1d2d472 100644 --- a/packages/component-manuscript-manager/src/tests/fragmentsRecommendations/post.test.js +++ b/packages/component-manuscript-manager/src/tests/fragmentsRecommendations/post.test.js @@ -428,6 +428,27 @@ describe('Post fragments recommendations route handler', () => { expect(data.error).toEqual('Cannot write another review on this version.') }) + it('should return success when creating another recommendation as a HE on the same version when EiC returned manuscript to He ', async () => { + const { noRecommendationHE } = testFixtures.users + const { noEditorRecomedationCollection } = testFixtures.collections + const { noEditorRecomedationFragment } = testFixtures.fragments + + const res = await requests.sendRequest({ + body, + userId: noRecommendationHE.id, + models, + route, + path, + params: { + collectionId: noEditorRecomedationCollection.id, + fragmentId: noEditorRecomedationFragment.id, + }, + }) + expect(res.statusCode).toBe(200) + const data = JSON.parse(res._getData()) + expect(data.userId).toEqual(noRecommendationHE.id) + }) + it('should return an error when an EiC makes a decision on an older version of a manuscript', async () => { const { editorInChief } = testFixtures.users const { twoVersionsCollection } = testFixtures.collections