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

fix(fragmentHelper): write unit tests for getReviewers

parent 290bb6fc
No related branches found
No related tags found
2 merge requests!136Sprint 22 features (updates),!126Hin 1046
...@@ -92,6 +92,7 @@ class Fragment { ...@@ -92,6 +92,7 @@ class Fragment {
getInvitations({ isAccepted = true, role = 'reviewer', type }) { getInvitations({ isAccepted = true, role = 'reviewer', type }) {
const { fragment: { invitations = [], recommendations = [] } } = this const { fragment: { invitations = [], recommendations = [] } } = this
let filteredInvitations = isAccepted let filteredInvitations = isAccepted
? invitations.filter( ? invitations.filter(
inv => inv.role === role && inv.hasAnswer && inv.isAccepted, inv => inv.role === role && inv.hasAnswer && inv.isAccepted,
......
...@@ -3,7 +3,9 @@ process.env.SUPPRESS_NO_CONFIG_WARNING = true ...@@ -3,7 +3,9 @@ process.env.SUPPRESS_NO_CONFIG_WARNING = true
const { cloneDeep } = require('lodash') const { cloneDeep } = require('lodash')
const fixturesService = require('pubsweet-component-fixture-service') const fixturesService = require('pubsweet-component-fixture-service')
const Chance = require('chance')
const chance = new Chance()
const { fixtures } = fixturesService const { fixtures } = fixturesService
const { Fragment } = require('../Helper') const { Fragment } = require('../Helper')
...@@ -13,17 +15,106 @@ describe('Fragment helper', () => { ...@@ -13,17 +15,106 @@ describe('Fragment helper', () => {
testFixtures = cloneDeep(fixtures) testFixtures = cloneDeep(fixtures)
}) })
it('hasReviewReport - should return true if the fragment has a review report', () => { describe('hasReviewReport', () => {
const { fragment } = testFixtures.fragments it('should return true if the fragment has a review report', () => {
const fragmentHelper = new Fragment({ fragment }) const { fragment } = testFixtures.fragments
const fragmentHelper = new Fragment({ fragment })
expect(fragmentHelper.hasReviewReport()).toBeTruthy() expect(fragmentHelper.hasReviewReport()).toBeTruthy()
})
it('should return false if the fragment does not have a review report', () => {
const { fragment } = testFixtures.fragments
fragment.recommendations = []
const fragmentHelper = new Fragment({ fragment })
expect(fragmentHelper.hasReviewReport()).toBeFalsy()
})
}) })
it('hasReviewReport - should return false if the fragment does not have a review report', () => {
const { fragment } = testFixtures.fragments
fragment.recommendations = []
const fragmentHelper = new Fragment({ fragment })
expect(fragmentHelper.hasReviewReport()).toBeFalsy() describe('getInvitations', () => {
it('should return accepted invitations if type is accepted', () => {
const { fragment } = testFixtures.fragments
const acceptedReviewerId = chance.guid()
const submittedReviewerId = chance.guid()
fragment.invitations.push(
{
id: chance.guid(),
role: 'reviewer',
hasAnswer: true,
isAccepted: true,
userId: acceptedReviewerId,
invitedOn: chance.timestamp(),
respondedOn: chance.timestamp(),
type: 'invitation',
},
{
id: chance.guid(),
role: 'reviewer',
hasAnswer: true,
isAccepted: true,
userId: submittedReviewerId,
invitedOn: chance.timestamp(),
respondedOn: chance.timestamp(),
type: 'invitation',
},
)
fragment.recommendations.push(
{
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: submittedReviewerId,
createdOn: chance.timestamp(),
updatedOn: chance.timestamp(),
submittedOn: chance.timestamp(),
},
{
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: acceptedReviewerId,
createdOn: chance.timestamp(),
updatedOn: chance.timestamp(),
// submittedOn: chance.timestamp(),
},
)
const fragmentHelper = new Fragment({ fragment })
const acceptedInvitations = fragmentHelper.getInvitations({
isAccepted: true,
type: 'accepted',
})
console.log(acceptedInvitations)
})
}) })
}) })
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