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

fix(post(fragmentInvitations)): HE is able to resend invitation to reviewer.

parent d480b9d5
No related branches found
No related tags found
3 merge requests!196S25 - EiC submit revision,!189S25,!187fix(post(fragmentInvitations)): HE is able to resend invitation to reviewer.
......@@ -13,18 +13,8 @@ const emailInvitations = require('./emails/invitations')
const { last } = require('lodash')
module.exports = models => async (req, res) => {
const { email, role, firstName, lastName, affiliation, country } = req.body
if (
!services.checkForUndefinedParams(
email,
role,
firstName,
lastName,
affiliation,
country,
)
) {
const { email, role } = req.body
if (!services.checkForUndefinedParams(email, role)) {
res.status(400).json({ error: 'Missing parameters.' })
return
}
......@@ -112,6 +102,17 @@ module.exports = models => async (req, res) => {
await fragment.save()
resend = true
} else {
const { firstName, lastName, affiliation, country } = req.body
if (
!services.checkForUndefinedParams(
firstName,
lastName,
affiliation,
country,
)
) {
res.status(400).json({ error: 'Missing parameters.' })
}
invitation = await invitationHelper.createInvitation({
parentObject: fragment,
})
......
......@@ -52,6 +52,7 @@ describe('Post fragments invitations route handler', () => {
const data = JSON.parse(res._getData())
expect(data.error).toEqual('Missing parameters.')
})
it('should return success when a reviewer is invited', async () => {
const { user, editorInChief } = testFixtures.users
const { collection } = testFixtures.collections
......@@ -78,6 +79,61 @@ describe('Post fragments invitations route handler', () => {
const data = JSON.parse(res._getData())
expect(data.role).toEqual(body.role)
})
it('should return success when resending an invitation to an existing reviewer', async () => {
const { editorInChief, reviewer } = testFixtures.users
const { collection } = testFixtures.collections
const { fragment } = testFixtures.fragments
const body = {
email: reviewer.email,
role: 'reviewer',
isPublons: false,
}
const res = await requests.sendRequest({
body,
userId: editorInChief.id,
route,
models,
path,
params: {
collectionId: collection.id,
fragmentId: fragment.id,
},
})
expect(res.statusCode).toBe(200)
const data = JSON.parse(res._getData())
expect(data.role).toEqual(body.role)
})
it('should return an error when resending an invitation to reviewer and the params are missing.', async () => {
const { editorInChief, reviewer } = testFixtures.users
const { collection } = testFixtures.collections
const { fragment } = testFixtures.fragments
const body = {
email: reviewer.email,
}
const res = await requests.sendRequest({
body,
userId: editorInChief.id,
route,
models,
path,
params: {
collectionId: collection.id,
fragmentId: fragment.id,
},
})
expect(res.statusCode).toBe(400)
const data = JSON.parse(res._getData())
expect(data.error).toEqual('Missing parameters.')
})
it('should return an error when inviting his self', async () => {
const { editorInChief } = testFixtures.users
body.email = editorInChief.email
......
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