Skip to content
Snippets Groups Projects
Commit 31396ef0 authored by Anca Ursachi's avatar Anca Ursachi
Browse files

test(manuscript-manager): Add tests for submitting a he recommendation on...

test(manuscript-manager): Add tests for submitting a he recommendation on first version or after min
parent 9dd5bf40
No related branches found
No related tags found
3 merge requests!162Sprint 23 Features,!161Deploy S23 features and fixes,!155Hin 1130
...@@ -413,14 +413,13 @@ const fragments = { ...@@ -413,14 +413,13 @@ const fragments = {
isCorresponding: false, isCorresponding: false,
}, },
], ],
owners: [user.id],
type: 'fragment',
}, },
}, },
} }
fragments.noInvitesFragment = { fragments.noInvitesFragment = {
...fragments.fragment1, ...fragments.fragment1,
recommendations: [],
invites: [], invites: [],
id: chance.guid(), id: chance.guid(),
} }
......
...@@ -8,4 +8,5 @@ module.exports = { ...@@ -8,4 +8,5 @@ module.exports = {
authorTeamID: chance.guid(), authorTeamID: chance.guid(),
revRecommendationTeamID: chance.guid(), revRecommendationTeamID: chance.guid(),
rev1TeamID: chance.guid(), rev1TeamID: chance.guid(),
heTeamMinorRevisionCollectionTeamID: chance.guid(),
} }
...@@ -8,10 +8,11 @@ const { ...@@ -8,10 +8,11 @@ const {
authorTeamID, authorTeamID,
revRecommendationTeamID, revRecommendationTeamID,
rev1TeamID, rev1TeamID,
heTeamMinorRevisionCollectionTeamID,
} = require('./teamIDs') } = require('./teamIDs')
const { submittingAuthor } = require('./userData') const { submittingAuthor } = require('./userData')
const { collection } = collections const { collection, collection2 } = collections
const { fragment, reviewCompletedFragment, fragment1 } = fragments const { fragment, reviewCompletedFragment, fragment1 } = fragments
const { const {
handlingEditor, handlingEditor,
...@@ -39,6 +40,23 @@ const teams = { ...@@ -39,6 +40,23 @@ const teams = {
updateProperties: jest.fn(() => teams.heTeam), updateProperties: jest.fn(() => teams.heTeam),
id: heTeamID, id: heTeamID,
}, },
heTeamMinorRevisionCollection: {
teamType: {
name: 'handlingEditor',
permissions: 'handlingEditor',
},
group: 'handlingEditor',
name: 'HandlingEditor',
object: {
type: 'collection',
id: collection2.id,
},
members: [handlingEditor.id],
save: jest.fn(() => teams.heTeam),
delete: jest.fn(),
updateProperties: jest.fn(() => teams.heTeam),
id: heTeamMinorRevisionCollectionTeamID,
},
revTeam: { revTeam: {
teamType: { teamType: {
name: 'reviewer', name: 'reviewer',
......
...@@ -8,6 +8,7 @@ const { ...@@ -8,6 +8,7 @@ const {
authorTeamID, authorTeamID,
revRecommendationTeamID, revRecommendationTeamID,
rev1TeamID, rev1TeamID,
heTeamMinorRevisionCollectionTeamID,
} = require('./teamIDs') } = require('./teamIDs')
const keys = Object.keys(usersData) const keys = Object.keys(usersData)
...@@ -18,7 +19,7 @@ users = keys.reduce((obj, item) => { ...@@ -18,7 +19,7 @@ users = keys.reduce((obj, item) => {
let teams = [] let teams = []
if (isHE) { if (isHE) {
teams = [heTeamID] teams = [heTeamID, heTeamMinorRevisionCollectionTeamID]
} }
if (item === 'author') { if (item === 'author') {
teams = [authorTeamID] teams = [authorTeamID]
......
/* eslint-disable no-return-await */ /* eslint-disable no-return-await */
const uuid = require('uuid') const uuid = require('uuid')
const { pick, get, set, has, isEmpty, last } = require('lodash') const { pick, get, set, has, isEmpty, last, findLast } = require('lodash')
const config = require('config') const config = require('config')
const { v4 } = require('uuid') const { v4 } = require('uuid')
...@@ -100,14 +100,6 @@ module.exports = models => async (req, res) => { ...@@ -100,14 +100,6 @@ module.exports = models => async (req, res) => {
.status(400) .status(400)
.json({ error: 'Cannot write a review on an older version.' }) .json({ error: 'Cannot write a review on an older version.' })
} }
const lastRecommendationByHE = last(
get(fragments[fragments.length - 2], 'recommendations', []) ||
[].find(
recommendation =>
recommendation.recommendationType === 'editorRecommendation',
),
)
if ( if (
recommendation === recommendations.publish && recommendation === recommendations.publish &&
recommendationType === recommendations.type.editor && recommendationType === recommendations.type.editor &&
...@@ -115,24 +107,38 @@ module.exports = models => async (req, res) => { ...@@ -115,24 +107,38 @@ module.exports = models => async (req, res) => {
collection.handlingEditor.id === req.user collection.handlingEditor.id === req.user
) { ) {
const fragmentHelper = new Fragment({ fragment }) const fragmentHelper = new Fragment({ fragment })
const canHeMakeRecommendationAfterMajor = if (!canHEMakeRecommendation(fragmentHelper)) {
fragmentHelper.hasReviewReport() &&
lastRecommendationByHE.recommendation === 'major'
const collectionHasReview = fragments.find(fragment =>
new Fragment({ fragment }).hasReviewReport(),
)
const canHeMakeRecommendationAfterMinor =
collectionHasReview && lastRecommendationByHE.recommendation !== 'major'
if (
!(canHeMakeRecommendationAfterMajor || canHeMakeRecommendationAfterMinor)
) {
return res.status(400).json({ return res.status(400).json({
error: 'Cannot publish without at least one reviewer report.', error: 'Cannot publish without at least one reviewer report.',
}) })
} }
} }
function canHEMakeRecommendation(fragmentHelper) {
if (collection.fragments.length === 1) {
return fragmentHelper.hasReviewReport()
}
const previousVersionRecommendations = get(
fragments[fragments.length - 2],
'recommendations',
[],
)
const lastRecommendationByHE = findLast(
previousVersionRecommendations,
recommendation =>
recommendation.userId === collection.handlingEditor.id &&
recommendation.recommendationType === 'editorRecommendation',
)
if (lastRecommendationByHE.recommendation === 'minor') {
return fragments.find(fragment =>
new Fragment({ fragment }).hasReviewReport(),
)
} else if (lastRecommendationByHE.recommendation === 'major') {
return fragmentHelper.hasReviewReport()
}
}
fragment.recommendations = fragment.recommendations || [] fragment.recommendations = fragment.recommendations || []
const newRecommendation = { const newRecommendation = {
id: uuid.v4(), id: uuid.v4(),
......
...@@ -28,7 +28,7 @@ const reqBody = { ...@@ -28,7 +28,7 @@ const reqBody = {
], ],
}, },
], ],
recommendationType: 'review', recommendationType: 'editorRecommendation',
} }
const path = '../routes/fragmentsRecommendations/post' const path = '../routes/fragmentsRecommendations/post'
...@@ -80,7 +80,7 @@ describe('Post fragments recommendations route handler', () => { ...@@ -80,7 +80,7 @@ describe('Post fragments recommendations route handler', () => {
const data = JSON.parse(res._getData()) const data = JSON.parse(res._getData())
expect(data.userId).toEqual(reviewer.id) expect(data.userId).toEqual(reviewer.id)
}) })
it('should return success when creating a recommendation as a HE', async () => { it('should return success when creating a recommendation as a HE when there is a single version with at least one review.', async () => {
const { handlingEditor } = testFixtures.users const { handlingEditor } = testFixtures.users
const { collection } = testFixtures.collections const { collection } = testFixtures.collections
const { fragment } = testFixtures.fragments const { fragment } = testFixtures.fragments
...@@ -101,6 +101,55 @@ describe('Post fragments recommendations route handler', () => { ...@@ -101,6 +101,55 @@ describe('Post fragments recommendations route handler', () => {
const data = JSON.parse(res._getData()) const data = JSON.parse(res._getData())
expect(data.userId).toEqual(handlingEditor.id) expect(data.userId).toEqual(handlingEditor.id)
}) })
it('should return an error when creating a recommendation with publish as a HE when there is a single version and there are no reviews.', async () => {
const { handlingEditor } = testFixtures.users
const { collection } = testFixtures.collections
const { fragment } = testFixtures.fragments
fragment.recommendations = []
const res = await requests.sendRequest({
body,
userId: handlingEditor.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 publish without at least one reviewer report.',
)
})
it('should return success when creating a recommendation as a HE after minor revision and we have at least one review on collection.', async () => {
const { handlingEditor } = testFixtures.users
const { collection2 } = testFixtures.collections
const { noInvitesFragment } = testFixtures.fragments
const res = await requests.sendRequest({
body,
userId: handlingEditor.id,
models,
route,
path,
params: {
collectionId: collection2.id,
fragmentId: noInvitesFragment.id,
},
})
expect(res.statusCode).toBe(200)
const data = JSON.parse(res._getData())
expect(data.userId).toEqual(handlingEditor.id)
})
it('should return an error when the fragmentId does not match the collectionId', async () => { it('should return an error when the fragmentId does not match the collectionId', async () => {
const { reviewer } = testFixtures.users const { reviewer } = testFixtures.users
const { collection } = testFixtures.collections const { collection } = testFixtures.collections
......
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