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

Merge branch 'HIN-1132' into 'develop'

Hin 1132

See merge request !154
parents bbce4b59 44b39508
No related branches found
No related tags found
3 merge requests!160Update staging with master features,!156Develop,!154Hin 1132
Showing with 243 additions and 55 deletions
......@@ -7,4 +7,5 @@ module.exports = {
collectionReviewCompletedID: chance.guid(),
collectionNoInvitesID: chance.guid(),
twoVersionsCollectionId: chance.guid(),
noEditorRecomedationCollectionID: chance.guid(),
}
const Chance = require('chance')
const { user, handlingEditor, answerHE } = require('./userData')
const {
user,
handlingEditor,
answerHE,
noRecommendationHE,
} = require('./userData')
const {
fragment,
fragment1,
reviewCompletedFragment,
noInvitesFragment,
noEditorRecomedationFragment,
} = require('./fragments')
const {
standardCollID,
collectionReviewCompletedID,
collectionNoInvitesID,
twoVersionsCollectionId,
noEditorRecomedationCollectionID,
} = require('./collectionIDs')
const chance = new Chance()
......@@ -214,6 +221,48 @@ const collections = {
save: jest.fn(() => collections.collection),
customId: chance.natural({ min: 999999, max: 9999999 }),
},
noEditorRecomedationCollection: {
id: noEditorRecomedationCollectionID,
title: chance.sentence(),
type: 'collection',
fragments: [noEditorRecomedationFragment.id],
owners: [user.id],
save: jest.fn(() => collections.noEditorRecomedationCollection),
invitations: [
{
id: chance.guid(),
role: 'handlingEditor',
hasAnswer: true,
isAccepted: true,
userId: noRecommendationHE.id,
invitedOn: chance.timestamp(),
respondedOn: null,
},
{
id: chance.guid(),
role: 'handlingEditor',
hasAnswer: false,
isAccepted: false,
userId: answerHE.id,
invitedOn: chance.timestamp(),
respondedOn: chance.timestamp(),
},
],
handlingEditor: {
id: handlingEditor.id,
hasAnswer: true,
isAccepted: true,
email: handlingEditor.email,
invitedOn: chance.timestamp(),
respondedOn: chance.timestamp(),
name: `${handlingEditor.firstName} ${handlingEditor.lastName}`,
},
customId: chance.natural({ min: 999999, max: 9999999 }),
technicalChecks: {
token: chance.guid(),
},
status: 'reviewCompleted',
},
}
module.exports = collections
......@@ -8,11 +8,13 @@ const {
admin,
inactiveReviewer,
reviewer1,
newReviewer,
} = require('./userData')
const {
standardCollID,
collectionReviewCompletedID,
collectionNoInvitesID,
noEditorRecomedationCollectionID,
} = require('./collectionIDs')
const { user } = require('./userData')
......@@ -118,27 +120,6 @@ const fragments = {
createdOn: chance.timestamp(),
updatedOn: chance.timestamp(),
},
{
recommendation: 'reject',
recommendationType: 'review',
comments: [
{
content: 'This is not submitted yet',
public: true,
files: [
{
id: chance.guid(),
name: 'file.pdf',
size: chance.natural(),
},
],
},
],
id: chance.guid(),
userId: reviewer.id,
createdOn: chance.timestamp(),
updatedOn: chance.timestamp(),
},
],
authors: [
{
......@@ -448,6 +429,61 @@ const fragments = {
type: 'fragment',
},
},
noEditorRecomedationFragment: {
id: chance.guid(),
collectionId: noEditorRecomedationCollectionID,
metadata: {
title: chance.sentence(),
abstract: chance.paragraph(),
},
recommendations: [
{
recommendation: 'publish',
recommendationType: 'review',
comments: [
{
content: chance.paragraph(),
public: chance.bool(),
files: [
{
id: chance.guid(),
name: 'file.pdf',
size: chance.natural(),
},
],
},
],
id: chance.guid(),
userId: newReviewer.id,
createdOn: chance.timestamp(),
updatedOn: chance.timestamp(),
submittedOn: chance.timestamp(),
},
],
authors: [
{
email: chance.email(),
id: submittingAuthor.id,
isSubmitting: true,
isCorresponding: false,
},
],
invitations: [
{
id: chance.guid(),
role: 'reviewer',
hasAnswer: true,
isAccepted: true,
userId: newReviewer.id,
invitedOn: chance.timestamp(),
respondedOn: chance.timestamp(),
type: 'invitation',
},
],
save: jest.fn(() => fragments.fragment),
owners: [user.id],
type: 'fragment',
},
}
fragments.noInvitesFragment = {
......
......@@ -8,4 +8,6 @@ module.exports = {
authorTeamID: chance.guid(),
revRecommendationTeamID: chance.guid(),
rev1TeamID: chance.guid(),
heNoRecommendationTeamID: chance.guid(),
revNoEditorRecommendationTeamID: chance.guid(),
}
......@@ -8,11 +8,18 @@ const {
authorTeamID,
revRecommendationTeamID,
rev1TeamID,
heNoRecommendationTeamID,
revNoEditorRecommendationTeamID,
} = require('./teamIDs')
const { submittingAuthor } = require('./userData')
const { collection } = collections
const { fragment, reviewCompletedFragment, fragment1 } = fragments
const { collection, noEditorRecomedationCollection } = collections
const {
fragment,
reviewCompletedFragment,
fragment1,
noEditorRecomedationFragment,
} = fragments
const {
handlingEditor,
reviewer,
......@@ -20,6 +27,8 @@ const {
answerReviewer,
recReviewer,
reviewer1,
newReviewer,
noRecommendationHE,
} = users
const teams = {
heTeam: {
......@@ -39,6 +48,23 @@ const teams = {
updateProperties: jest.fn(() => teams.heTeam),
id: heTeamID,
},
heNoRecommendationTeam: {
teamType: {
name: 'handlingEditor',
permissions: 'handlingEditor',
},
group: 'handlingEditor',
name: 'HandlingEditor',
object: {
type: 'collection',
id: noEditorRecomedationCollection.id,
},
members: [noRecommendationHE.id],
save: jest.fn(() => teams.heNoRecommendationTeam),
delete: jest.fn(),
updateProperties: jest.fn(() => teams.heNoRecommendationTeam),
id: heNoRecommendationTeamID,
},
revTeam: {
teamType: {
name: 'reviewer',
......@@ -106,5 +132,21 @@ const teams = {
updateProperties: jest.fn(() => teams.authorTeam),
id: authorTeamID,
},
revNoEditorRecommendationTeam: {
teamType: {
name: 'reviewer',
permissions: 'reviewer',
},
group: 'reviewer',
name: 'reviewer',
object: {
type: 'fragment',
id: noEditorRecomedationFragment.id,
},
members: [newReviewer.id],
save: jest.fn(() => teams.revNoEditorRecommendationTeam),
updateProperties: jest.fn(() => teams.revNoEditorRecommendationTeam),
id: revNoEditorRecommendationTeamID,
},
}
module.exports = teams
......@@ -10,11 +10,13 @@ const generateUserData = () => ({
module.exports = {
handlingEditor: generateUserData(),
noRecommendationHE: generateUserData(),
user: generateUserData(),
admin: generateUserData(),
author: generateUserData(),
reviewer: generateUserData(),
reviewer1: generateUserData(),
newReviewer: generateUserData(),
answerReviewer: generateUserData(),
submittingAuthor: generateUserData(),
recReviewer: generateUserData(),
......
......@@ -8,6 +8,8 @@ const {
authorTeamID,
revRecommendationTeamID,
rev1TeamID,
heNoRecommendationTeamID,
revNoEditorRecommendationTeamID,
} = require('./teamIDs')
const keys = Object.keys(usersData)
......@@ -17,21 +19,37 @@ users = keys.reduce((obj, item) => {
const isHE = item === 'answerHE' || item === 'handlingEditor'
let teams = []
if (isHE) {
teams = [heTeamID]
}
if (item === 'author') {
teams = [authorTeamID]
}
if (['reviewer', 'inactiveReviewer', 'answerReviewer'].includes(item)) {
teams.push(revTeamID)
}
if (['reviewer', 'answerReviewer', 'recReviewer'].includes(item)) {
teams.push(revRecommendationTeamID)
}
if (item === 'reviewer1') {
teams = [rev1TeamID]
switch (item) {
case 'answerHE':
teams = [heTeamID]
break
case 'handlingEditor':
teams = [heTeamID]
break
case 'noRecommendationHE':
teams = [heNoRecommendationTeamID]
break
case 'author':
teams = [authorTeamID]
break
case 'reviewer1':
teams = [rev1TeamID]
break
case 'newReviewer':
teams = [revNoEditorRecommendationTeamID]
break
case 'reviewer':
case 'answerReviewer':
teams = [revTeamID, revRecommendationTeamID]
break
case 'inactiveReviewer':
teams.push(revTeamID)
break
case 'recReviewer':
teams.push(revRecommendationTeamID)
break
default:
teams = []
}
obj[item] = {
......
......@@ -41,6 +41,10 @@ module.exports = models => async (req, res) => {
})
}
const currentUserRecommendation = get(fragment, 'recommendations', []).filter(
r => r.userId === req.user,
)
const authsome = authsomeHelper.getAuthsome(models)
const target = {
fragment,
......@@ -71,6 +75,20 @@ module.exports = models => async (req, res) => {
.json({ error: 'Cannot write a review on an older version.' })
}
if (
last(collection.fragments) === fragmentId &&
!isEmpty(currentUserRecommendation)
) {
if (recommendationType === recommendations.type.review) {
return 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 (
recommendation === recommendations.publish &&
recommendationType === recommendations.type.editor &&
......
......@@ -81,25 +81,24 @@ describe('Post fragments recommendations route handler', () => {
expect(data.userId).toEqual(reviewer.id)
})
it('should return success when creating a recommendation as a HE', async () => {
const { handlingEditor } = testFixtures.users
const { collection } = testFixtures.collections
const { fragment } = testFixtures.fragments
const { noRecommendationHE } = testFixtures.users
const { noEditorRecomedationCollection } = testFixtures.collections
const { noEditorRecomedationFragment } = testFixtures.fragments
const res = await requests.sendRequest({
body,
userId: handlingEditor.id,
userId: noRecommendationHE.id,
models,
route,
path,
params: {
collectionId: collection.id,
fragmentId: fragment.id,
collectionId: noEditorRecomedationCollection.id,
fragmentId: noEditorRecomedationFragment.id,
},
})
expect(res.statusCode).toBe(200)
const data = JSON.parse(res._getData())
expect(data.userId).toEqual(handlingEditor.id)
expect(data.userId).toEqual(noRecommendationHE.id)
})
it('should return an error when the fragmentId does not match the collectionId', async () => {
const { reviewer } = testFixtures.users
......@@ -163,28 +162,28 @@ describe('Post fragments recommendations route handler', () => {
expect(data.error).toEqual('Unauthorized.')
})
it('should return success when a HE recommends to reject', async () => {
const { handlingEditor } = testFixtures.users
const { collection } = testFixtures.collections
const { fragment } = testFixtures.fragments
const { noRecommendationHE } = testFixtures.users
const { noEditorRecomedationCollection } = testFixtures.collections
const { noEditorRecomedationFragment } = testFixtures.fragments
body.recommendation = 'reject'
body.recommendationType = 'editorRecommendation'
const res = await requests.sendRequest({
body,
userId: handlingEditor.id,
userId: noRecommendationHE.id,
models,
route,
path,
params: {
collectionId: collection.id,
fragmentId: fragment.id,
collectionId: noEditorRecomedationCollection.id,
fragmentId: noEditorRecomedationFragment.id,
},
})
expect(res.statusCode).toBe(200)
const data = JSON.parse(res._getData())
expect(data.userId).toEqual(handlingEditor.id)
expect(data.userId).toEqual(noRecommendationHE.id)
expect(data.recommendation).toBe('reject')
})
it('should return an error when the user is inactive', async () => {
......@@ -357,7 +356,6 @@ describe('Post fragments recommendations route handler', () => {
'Cannot publish without at least one reviewer report.',
)
})
it('should return an error when a HE makes a recommendation on an older version of a manuscript', async () => {
const { handlingEditor } = testFixtures.users
const { twoVersionsCollection } = testFixtures.collections
......@@ -407,6 +405,28 @@ describe('Post fragments recommendations route handler', () => {
expect(data.error).toEqual('Cannot write a review on an older version.')
})
it('should return an error when a reviewer writes another review on the current version of a manuscript', async () => {
const { newReviewer } = testFixtures.users
const { noEditorRecomedationCollection } = testFixtures.collections
const { noEditorRecomedationFragment } = testFixtures.fragments
body.recommendationType = 'review'
const res = await requests.sendRequest({
body,
userId: newReviewer.id,
models,
route,
path,
params: {
collectionId: noEditorRecomedationCollection.id,
fragmentId: noEditorRecomedationFragment.id,
},
})
expect(res.statusCode).toBe(400)
const data = JSON.parse(res._getData())
expect(data.error).toEqual('Cannot write another review on this version.')
})
it('should return an error when an EiC makes a decision on an older version of a manuscript', async () => {
const { editorInChief } = testFixtures.users
......
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