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

test(component-helper-service): Add tests for submitting a he recommendation...

test(component-helper-service): Add tests for submitting a he recommendation on minor/major or first
parent 7ff1ecab
No related branches found
No related tags found
3 merge requests!162Sprint 23 Features,!161Deploy S23 features and fixes,!159Hin 1153 status after review
...@@ -490,17 +490,9 @@ fragments.noInvitesFragment = { ...@@ -490,17 +490,9 @@ fragments.noInvitesFragment = {
invites: [], invites: [],
id: chance.guid(), id: chance.guid(),
} }
fragments.noInvitesFragment = {
...fragments.fragment1,
recommendations: [],
invites: [],
id: chance.guid(),
}
fragments.noInvitesFragment1 = { fragments.noInvitesFragment1 = {
...fragments.fragment, ...fragments.fragment,
recommendations: [], recommendations: [],
invites: [],
id: chance.guid(), id: chance.guid(),
} }
fragments.minorRevisionWithoutReview = { fragments.minorRevisionWithoutReview = {
......
...@@ -145,7 +145,7 @@ class Fragment { ...@@ -145,7 +145,7 @@ class Fragment {
hasReviewReport() { hasReviewReport() {
const { fragment: { recommendations = [] } } = this const { fragment: { recommendations = [] } } = this
return recommendations.find( return recommendations.some(
rec => rec.recommendationType === 'review' && rec.submittedOn, 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)
})
})
})
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