Skip to content
Snippets Groups Projects
Commit 224a6db2 authored by Sebastian Mihalache's avatar Sebastian Mihalache :hammer_pick:
Browse files

feat(eic-revision): add ability to request revision for EiC

parent 0a2a7583
No related branches found
No related tags found
3 merge requests!196S25 - EiC submit revision,!189S25,!177Hin 230 eic request revision
......@@ -329,12 +329,13 @@ describe('Fragment helper', () => {
updatedOn: chance.timestamp(),
},
]
const currentUserRecommendations = testFragment.recommendations.filter(
r => r.userId === handlingEditorId,
)
const fragmentHelper = new Fragment({ fragment: testFragment })
const latestUserRecommendation = fragmentHelper.getLatestUserRecommendation(
handlingEditorId,
)
const canHEMakeAnotherRecommendation = await fragmentHelper.canHEMakeAnotherRecommendation(
currentUserRecommendations,
latestUserRecommendation,
)
expect(canHEMakeAnotherRecommendation).toBe(true)
})
......@@ -362,12 +363,12 @@ describe('Fragment helper', () => {
updatedOn: chance.timestamp(),
},
]
const currentUserRecommendations = testFragment.recommendations.filter(
r => r.userId === handlingEditorId,
)
const fragmentHelper = new Fragment({ fragment: testFragment })
const latestUserRecommendation = fragmentHelper.getLatestUserRecommendation(
handlingEditorId,
)
const canHEMakeAnotherRecommendation = await fragmentHelper.canHEMakeAnotherRecommendation(
currentUserRecommendations,
latestUserRecommendation,
)
expect(canHEMakeAnotherRecommendation).toBe(false)
})
......
......@@ -18,6 +18,7 @@ const returnToHE = require('./strategies/eicReturnToHE')
const Notification = require('../../notifications/notification')
const createReview = require('./strategies/reviewerCreateReview')
const requestRevisionAsHE = require('./strategies/heRequestRevision')
const requestRevisionAsEiC = require('./strategies/eicRequestRevision')
module.exports = models => async (req, res) => {
const { recommendation, comments, recommendationType } = req.body
......@@ -110,6 +111,7 @@ module.exports = models => async (req, res) => {
eic: {
reject: rejectAsEiC,
publish: publishAsEiC,
revision: requestRevisionAsEiC,
'return-to-handling-editor': returnToHE,
},
}
......
module.exports = {
execute: async ({ fragmentHelper, collectionHelper, newRecommendation }) => {
if (collectionHelper.hasHandlingEditor()) {
throw new Error(
'Cannot make request a revision after a Handling Editor has been assigned.',
)
}
await fragmentHelper.addRevision()
await collectionHelper.updateStatus({ newStatus: 'revisionRequested' })
await fragmentHelper.addRecommendation(newRecommendation)
},
}
......@@ -640,4 +640,55 @@ describe('Post fragments recommendations route handler', () => {
'Cannot make a recommendation on an older version.',
)
})
it('should return success when an EiC requests a revision before the Handling Editor is assigned', async () => {
const { editorInChief } = testFixtures.users
const { collection } = testFixtures.collections
const { fragment } = testFixtures.fragments
body.recommendation = 'revision'
body.recommendationType = 'editorRecommendation'
delete collection.handlingEditor
const res = await requests.sendRequest({
body,
userId: editorInChief.id,
models,
route,
path,
params: {
collectionId: collection.id,
fragmentId: fragment.id,
},
})
expect(res.statusCode).toBe(200)
const data = JSON.parse(res._getData())
expect(data.userId).toEqual(editorInChief.id)
expect(collection.status).toEqual('revisionRequested')
expect(fragment).toHaveProperty('revision')
})
it('should return an error when an EiC requests a revision after a Handling Editor is assigned', async () => {
const { editorInChief } = testFixtures.users
const { collection } = testFixtures.collections
const { fragment } = testFixtures.fragments
body.recommendation = 'revision'
body.recommendationType = 'editorRecommendation'
const res = await requests.sendRequest({
body,
userId: editorInChief.id,
models,
route,
path,
params: {
collectionId: collection.id,
fragmentId: fragment.id,
},
})
expect(res.statusCode).toBe(400)
const data = JSON.parse(res._getData())
expect(data.error).toEqual(
'Cannot make request a revision after a Handling Editor has been assigned.',
)
})
})
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment