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

fix(submittedReviewers): submitted reviewers will not receive bad email

parent 79225893
No related branches found
No related tags found
2 merge requests!136Sprint 22 features (updates),!126Hin 1046
const get = require('lodash/get') const { get, remove } = require('lodash')
const User = require('./User') const User = require('./User')
class Fragment { class Fragment {
...@@ -92,15 +92,14 @@ class Fragment { ...@@ -92,15 +92,14 @@ class Fragment {
getInvitations({ isAccepted = true, role = 'reviewer', type }) { getInvitations({ isAccepted = true, role = 'reviewer', type }) {
const { fragment: { invitations = [], recommendations = [] } } = this const { fragment: { invitations = [], recommendations = [] } } = this
const 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,
) )
: invitations.filter(inv => inv.role === role && !inv.hasAnswer) : invitations.filter(inv => inv.role === role && !inv.hasAnswer)
if (type === 'submitted') { if (type === 'submitted') {
filteredInvitations = filteredInvitations.filter(inv => return filteredInvitations.filter(inv =>
recommendations.find( recommendations.find(
rec => rec =>
rec.recommendationType === 'review' && rec.recommendationType === 'review' &&
...@@ -109,12 +108,11 @@ class Fragment { ...@@ -109,12 +108,11 @@ class Fragment {
), ),
) )
} else if (type === 'accepted') { } else if (type === 'accepted') {
filteredInvitations = filteredInvitations.filter(inv => recommendations.forEach(rec => {
recommendations.find( if (rec.recommendationType === 'review' && rec.submittedOn) {
rec => remove(filteredInvitations, inv => inv.userId === rec.userId)
rec.recommendationType === 'review' && inv.userId !== rec.userId, }
), })
)
} }
return filteredInvitations return filteredInvitations
......
...@@ -9,10 +9,117 @@ const chance = new Chance() ...@@ -9,10 +9,117 @@ const chance = new Chance()
const { fixtures } = fixturesService const { fixtures } = fixturesService
const { Fragment } = require('../Helper') const { Fragment } = require('../Helper')
const acceptedReviewerId = chance.guid()
const submittedReviewerId1 = chance.guid()
const submittedReviewerId2 = chance.guid()
const fragment = {
invitations: [
{
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: submittedReviewerId1,
invitedOn: chance.timestamp(),
respondedOn: chance.timestamp(),
type: 'invitation',
},
{
id: chance.guid(),
role: 'reviewer',
hasAnswer: true,
isAccepted: true,
userId: submittedReviewerId2,
invitedOn: chance.timestamp(),
respondedOn: chance.timestamp(),
type: 'invitation',
},
],
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: submittedReviewerId1,
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: submittedReviewerId2,
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(),
},
],
}
describe('Fragment helper', () => { describe('Fragment helper', () => {
let testFixtures = {} let testFixtures = {}
let testFragment = {}
beforeEach(() => { beforeEach(() => {
testFixtures = cloneDeep(fixtures) testFixtures = cloneDeep(fixtures)
testFragment = cloneDeep(fragment)
}) })
describe('hasReviewReport', () => { describe('hasReviewReport', () => {
...@@ -32,35 +139,18 @@ describe('Fragment helper', () => { ...@@ -32,35 +139,18 @@ describe('Fragment helper', () => {
}) })
describe('getInvitations', () => { describe('getInvitations', () => {
it('should return accepted invitations if type is accepted', () => { it('should return accepted invitations if type is accepted and a review report has been started', () => {
const { fragment } = testFixtures.fragments const fragmentHelper = new Fragment({ fragment: testFragment })
const acceptedReviewerId = chance.guid()
const submittedReviewerId = chance.guid()
fragment.invitations.push( const acceptedInvitations = fragmentHelper.getInvitations({
{ isAccepted: true,
id: chance.guid(), type: 'accepted',
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( expect(acceptedInvitations).toHaveLength(1)
})
it('should return accepted invitations if type is accepted and no review report has been started', () => {
testFragment.recommendations = [
{ {
recommendation: 'publish', recommendation: 'publish',
recommendationType: 'review', recommendationType: 'review',
...@@ -78,7 +168,7 @@ describe('Fragment helper', () => { ...@@ -78,7 +168,7 @@ describe('Fragment helper', () => {
}, },
], ],
id: chance.guid(), id: chance.guid(),
userId: submittedReviewerId, userId: submittedReviewerId1,
createdOn: chance.timestamp(), createdOn: chance.timestamp(),
updatedOn: chance.timestamp(), updatedOn: chance.timestamp(),
submittedOn: chance.timestamp(), submittedOn: chance.timestamp(),
...@@ -100,21 +190,51 @@ describe('Fragment helper', () => { ...@@ -100,21 +190,51 @@ describe('Fragment helper', () => {
}, },
], ],
id: chance.guid(), id: chance.guid(),
userId: acceptedReviewerId, userId: submittedReviewerId2,
createdOn: chance.timestamp(), createdOn: chance.timestamp(),
updatedOn: chance.timestamp(), updatedOn: chance.timestamp(),
// submittedOn: chance.timestamp(), submittedOn: chance.timestamp(),
}, },
) ]
const fragmentHelper = new Fragment({ fragment }) const fragmentHelper = new Fragment({ fragment: testFragment })
const acceptedInvitations = fragmentHelper.getInvitations({ const acceptedInvitations = fragmentHelper.getInvitations({
isAccepted: true, isAccepted: true,
type: 'accepted', type: 'accepted',
}) })
console.log(acceptedInvitations) expect(acceptedInvitations).toHaveLength(1)
})
it('should return invitations of submitted reviewers if type is submitted', () => {
const fragmentHelper = new Fragment({ fragment: testFragment })
const submittedInvitations = fragmentHelper.getInvitations({
isAccepted: true,
type: 'submitted',
})
expect(submittedInvitations).toHaveLength(2)
})
it('should return invitations of pending reviewers if type is pending and isAccepted is false', () => {
testFragment.invitations.push({
id: chance.guid(),
role: 'reviewer',
hasAnswer: false,
isAccepted: false,
userId: chance.guid(),
invitedOn: chance.timestamp(),
respondedOn: chance.timestamp(),
type: 'invitation',
})
const fragmentHelper = new Fragment({ fragment: testFragment })
const pendingInvitations = fragmentHelper.getInvitations({
isAccepted: false,
type: 'pending',
})
expect(pendingInvitations).toHaveLength(1)
}) })
}) })
}) })
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