From 24dd0bc93c6ef4c2df33a6c8f2e82f715899bb8d Mon Sep 17 00:00:00 2001 From: Anca Ursachi <anca.ursachi@thinslices.com> Date: Thu, 6 Dec 2018 14:17:20 +0200 Subject: [PATCH] fix(post(fragmentInvitations)): HE is able to resend invitation to reviewer. --- .../src/routes/fragmentsInvitations/post.js | 25 +++++---- .../tests/fragmentsInvitations/post.test.js | 56 +++++++++++++++++++ 2 files changed, 69 insertions(+), 12 deletions(-) diff --git a/packages/component-invite/src/routes/fragmentsInvitations/post.js b/packages/component-invite/src/routes/fragmentsInvitations/post.js index 0e45b83fa..df347226e 100644 --- a/packages/component-invite/src/routes/fragmentsInvitations/post.js +++ b/packages/component-invite/src/routes/fragmentsInvitations/post.js @@ -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, }) diff --git a/packages/component-invite/src/tests/fragmentsInvitations/post.test.js b/packages/component-invite/src/tests/fragmentsInvitations/post.test.js index 0683f0aaf..cf4b990bb 100644 --- a/packages/component-invite/src/tests/fragmentsInvitations/post.test.js +++ b/packages/component-invite/src/tests/fragmentsInvitations/post.test.js @@ -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 -- GitLab