Skip to content
Snippets Groups Projects
Commit df51ff51 authored by Tania Fecheta's avatar Tania Fecheta
Browse files

Merge branch 'develop' of gitlab.coko.foundation:xpub/xpub-faraday into...

Merge branch 'develop' of gitlab.coko.foundation:xpub/xpub-faraday into HIN-1152-he-rec-after-eic-decision
parents 6a580894 c50c6aa1
No related branches found
No related tags found
3 merge requests!176Sprint 24,!171Sprint 24,!157fix(fragmentRecommendation): allow HE to make another recommendation on the same…
......@@ -532,17 +532,9 @@ fragments.noInvitesFragment = {
invites: [],
id: chance.guid(),
}
fragments.noInvitesFragment = {
...fragments.fragment1,
recommendations: [],
invites: [],
id: chance.guid(),
}
fragments.noInvitesFragment1 = {
...fragments.fragment,
recommendations: [],
invites: [],
id: chance.guid(),
}
fragments.minorRevisionWithoutReview = {
......
......@@ -10,6 +10,7 @@ class Collection {
async updateStatusByRecommendation({
recommendation,
isHandlingEditor = false,
fragments,
}) {
let newStatus
if (isHandlingEditor) {
......@@ -19,7 +20,9 @@ class Collection {
}
} else {
if (recommendation === 'minor') {
newStatus = 'reviewCompleted'
newStatus = this.hasAtLeastOneReviewReport(fragments)
? 'reviewCompleted'
: 'heAssigned'
}
if (recommendation === 'major') {
......@@ -27,7 +30,7 @@ class Collection {
}
}
this.updateStatus({ newStatus })
return this.updateStatus({ newStatus })
}
async updateFinalStatusByRecommendation({ recommendation }) {
......@@ -89,18 +92,16 @@ class Collection {
async updateStatusOnRecommendation({ isEditorInChief, recommendation }) {
if (isEditorInChief) {
if (recommendation === 'return-to-handling-editor') {
this.updateStatus({ newStatus: 'reviewCompleted' })
} else {
this.updateFinalStatusByRecommendation({
recommendation,
})
return this.updateStatus({ newStatus: 'reviewCompleted' })
}
} else {
this.updateStatusByRecommendation({
return this.updateFinalStatusByRecommendation({
recommendation,
isHandlingEditor: true,
})
}
return this.updateStatusByRecommendation({
recommendation,
isHandlingEditor: true,
})
}
getHELastName() {
......@@ -137,6 +138,14 @@ class Collection {
return fragmentHelper.hasReviewReport()
}
}
async getAllFragments({ FragmentModel }) {
return Promise.all(
this.collection.fragments.map(async fragment =>
FragmentModel.find(fragment),
),
)
}
}
module.exports = Collection
......@@ -145,7 +145,7 @@ class Fragment {
hasReviewReport() {
const { fragment: { recommendations = [] } } = this
return recommendations.find(
return recommendations.some(
rec => rec.recommendationType === 'review' && rec.submittedOn,
)
}
......
process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
process.env.SUPPRESS_NO_CONFIG_WARNING = true
const { cloneDeep } = require('lodash')
const fixturesService = require('pubsweet-component-fixture-service')
const { fixtures, Model } = fixturesService
const { Collection, Fragment } = require('../Helper')
describe('Collection helper', () => {
let testFixtures = {}
let models
beforeEach(() => {
testFixtures = cloneDeep(fixtures)
models = Model.build(testFixtures)
})
describe('hasAtLeastOneReviewReport', () => {
it('should return true if collection has at least one report from reviewers.', async () => {
const { collection } = testFixtures.collections
const collectionHelper = new Collection({ collection })
const FragmentModel = models.Fragment
const fragments = await collectionHelper.getAllFragments({
FragmentModel,
})
const hasReviewReport = await collectionHelper.hasAtLeastOneReviewReport(
fragments,
)
expect(hasReviewReport).toBe(true)
})
it('should return false if collection has at least one report from reviewers.', async () => {
const { noInvitesFragment } = testFixtures.fragments
const { collection } = testFixtures.collections
collection.fragments = [noInvitesFragment.id]
const collectionHelper = new Collection({ collection })
const FragmentModel = models.Fragment
const fragments = await collectionHelper.getAllFragments({
FragmentModel,
})
const hasReviewReport = await collectionHelper.hasAtLeastOneReviewReport(
fragments,
)
expect(hasReviewReport).toBe(false)
})
})
describe('canHEMakeRecommendation', () => {
it('should return true when creating a recommendation as a HE when there is a single version with at least one review.', async () => {
const { collection } = testFixtures.collections
const { fragment } = testFixtures.fragments
const collectionHelper = new Collection({
collection,
})
const FragmentModel = models.Fragment
const fragments = await collectionHelper.getAllFragments({
FragmentModel,
})
const fragmentHelper = new Fragment({ fragment })
const canHEMakeRecommendation = await collectionHelper.canHEMakeRecommendation(
fragments,
fragmentHelper,
)
expect(canHEMakeRecommendation).toBe(true)
})
it('should return false when creating a recommendation with publish as a HE when there is a single version and there are no reviews.', async () => {
const { collection } = testFixtures.collections
const { fragment } = testFixtures.fragments
fragment.recommendations = undefined
const collectionHelper = new Collection({
collection,
})
const FragmentModel = models.Fragment
const fragments = await collectionHelper.getAllFragments({
FragmentModel,
})
const fragmentHelper = new Fragment({ fragment })
const canHEMakeRecommendation = await collectionHelper.canHEMakeRecommendation(
fragments,
fragmentHelper,
)
expect(canHEMakeRecommendation).toBe(false)
})
it('should return true when creating a recommendation as a HE after minor revision and we have at least one review on collection.', async () => {
const { collection } = testFixtures.collections
const {
minorRevisionWithReview,
noInvitesFragment1,
} = testFixtures.fragments
collection.fragments = [minorRevisionWithReview.id, noInvitesFragment1.id]
const collectionHelper = new Collection({
collection,
})
const FragmentModel = models.Fragment
const fragments = await collectionHelper.getAllFragments({
FragmentModel,
})
const fragmentHelper = new Fragment({ fragment: noInvitesFragment1 })
const canHEMakeRecommendation = await collectionHelper.canHEMakeRecommendation(
fragments,
fragmentHelper,
)
expect(canHEMakeRecommendation).toBe(true)
})
it('should return false when creating a recommendation as a HE after minor revision and there are no reviews.', async () => {
const { collection } = testFixtures.collections
const {
minorRevisionWithoutReview,
noInvitesFragment1,
} = testFixtures.fragments
collection.fragments = [
minorRevisionWithoutReview.id,
noInvitesFragment1.id,
]
const collectionHelper = new Collection({
collection,
})
const FragmentModel = models.Fragment
const fragments = await collectionHelper.getAllFragments({
FragmentModel,
})
const fragmentHelper = new Fragment({ noInvitesFragment1 })
const canHEMakeRecommendation = await collectionHelper.canHEMakeRecommendation(
fragments,
fragmentHelper,
)
expect(canHEMakeRecommendation).toBe(false)
})
it('should return true when creating a recommendation as a HE after major revision and there are least one review on fragment.', async () => {
const { collection } = testFixtures.collections
const {
majorRevisionWithReview,
reviewCompletedFragment,
} = testFixtures.fragments
reviewCompletedFragment.collectionId = collection.id
collection.fragments = [
majorRevisionWithReview.id,
reviewCompletedFragment.id,
]
const collectionHelper = new Collection({
collection,
})
const FragmentModel = models.Fragment
const fragments = await collectionHelper.getAllFragments({
FragmentModel,
})
const fragmentHelper = new Fragment({ fragment: reviewCompletedFragment })
const canHEMakeRecommendation = await collectionHelper.canHEMakeRecommendation(
fragments,
fragmentHelper,
)
expect(canHEMakeRecommendation).toBe(true)
})
it('should return false when creating a recommendation as a HE after major revision there are no reviews on fragment.', async () => {
const { collection } = testFixtures.collections
const {
majorRevisionWithReview,
noInvitesFragment1,
} = testFixtures.fragments
collection.fragments = [majorRevisionWithReview.id, noInvitesFragment1.id]
const collectionHelper = new Collection({
collection,
})
const FragmentModel = models.Fragment
const fragments = await collectionHelper.getAllFragments({
FragmentModel,
})
const fragmentHelper = new Fragment({ fragment: noInvitesFragment1 })
const canHEMakeRecommendation = await collectionHelper.canHEMakeRecommendation(
fragments,
fragmentHelper,
)
expect(canHEMakeRecommendation).toBe(false)
})
})
})
......@@ -4,6 +4,7 @@ const {
services,
Collection,
Invitation,
Fragment,
authsome: authsomeHelper,
} = require('pubsweet-component-helper-service')
......@@ -116,7 +117,12 @@ module.exports = models => async (req, res) => {
})
}
if (collection.status === 'heAssigned') {
const fragmentHelper = new Fragment({ fragment })
if (
collection.status === 'heAssigned' ||
(collection.status === 'reviewCompleted' &&
!fragmentHelper.hasReviewReport())
) {
collectionHelper.updateStatus({ newStatus: 'reviewersInvited' })
}
......
......@@ -103,8 +103,13 @@ module.exports = models => async (req, res) => {
await authorsTeam.save()
}
collectionHelper.updateStatusByRecommendation({
const fragments = await collectionHelper.getAllFragments({
FragmentModel: models.Fragment,
})
await collectionHelper.updateStatusByRecommendation({
recommendation: heRecommendation.recommendation,
fragments,
})
newFragment.submitted = Date.now()
......
/* eslint-disable no-return-await */
const uuid = require('uuid')
const { pick, get, set, has, isEmpty, last } = require('lodash')
const config = require('config')
......@@ -45,11 +44,9 @@ module.exports = models => async (req, res) => {
const collectionHelper = new Collection({ collection })
try {
fragments = await Promise.all(
collection.fragments.map(
async fragment => await models.Fragment.find(fragment),
),
)
fragments = await collectionHelper.getAllFragments({
FragmentModel: models.Fragment,
})
} catch (e) {
const notFoundError = await services.handleNotFoundError(e, 'Item')
fragments = []
......@@ -149,7 +146,7 @@ module.exports = models => async (req, res) => {
newRecommendation.comments = comments || undefined
if (recommendationType === 'editorRecommendation') {
collectionHelper.updateStatusOnRecommendation({
await collectionHelper.updateStatusOnRecommendation({
isEditorInChief,
recommendation,
})
......
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