diff --git a/packages/component-invite/src/routes/collectionsInvitations/patch.js b/packages/component-invite/src/routes/collectionsInvitations/patch.js index dcfde76b44eb1915df3db8f7aa1a6caabeec257b..5aa66887efe8b9c02f087b2a5f0e68ac11515753 100644 --- a/packages/component-invite/src/routes/collectionsInvitations/patch.js +++ b/packages/component-invite/src/routes/collectionsInvitations/patch.js @@ -41,11 +41,11 @@ module.exports = models => async (req, res) => { invitation.timestamp = Date.now() invitation.hasAnswer = true const eic = await userHelper.getEditorInChief(models.User) + let toEmail = eic.email + if (invitation.role === 'reviewer') + toEmail = collection.handlingEditor.email if (isAccepted === true) { invitation.isAccepted = true - let toEmail = eic.email - if (invitation.role === 'reviewer') - toEmail = collection.handlingEditor.email await collection.save() try { await mailService.setupAgreeEmail( @@ -75,9 +75,9 @@ module.exports = models => async (req, res) => { } try { await mailService.setupDeclineEmail( - eic.email, + toEmail, user, - 'handling-editor-declined', + 'decline', collection.customId, reason, ) diff --git a/packages/component-invite/src/tests/collectionsInvitations/get.test.js b/packages/component-invite/src/tests/collectionsInvitations/get.test.js index 7d64dcf8bfb2344606bbfb1bbbb7410194549662..b92e412bfcfa68fabe24fce66e7b292fa603da5a 100644 --- a/packages/component-invite/src/tests/collectionsInvitations/get.test.js +++ b/packages/component-invite/src/tests/collectionsInvitations/get.test.js @@ -79,7 +79,7 @@ describe('Get collection invitations route handler', () => { const { collection } = testFixtures.collections const req = httpMocks.createRequest() req.query = { - role: 'reviewer', + role: 'author', userId: handlingEditor.id, } delete collection.invitations diff --git a/packages/component-invite/src/tests/collectionsInvitations/patch.test.js b/packages/component-invite/src/tests/collectionsInvitations/patch.test.js index a9f7a62580c14905388b94a556216304b02fea53..2f1600567b0612eae80f9765cc9131c857f5c7aa 100644 --- a/packages/component-invite/src/tests/collectionsInvitations/patch.test.js +++ b/packages/component-invite/src/tests/collectionsInvitations/patch.test.js @@ -50,7 +50,7 @@ describe('Patch collections invitations route handler', () => { req.user = reviewer.id req.params.collectionId = collection.id const reviewerInv = collection.invitations.find( - inv => inv.role === 'reviewer', + inv => inv.role === 'reviewer' && inv.hasAnswer === false, ) req.params.invitationId = reviewerInv.id const res = httpMocks.createResponse() @@ -75,6 +75,24 @@ describe('Patch collections invitations route handler', () => { expect(res.statusCode).toBe(200) }) + it('should return success when the reviewer declines work on a collection', async () => { + const { reviewer } = testFixtures.users + const { collection } = testFixtures.collections + body.isAccepted = false + const req = httpMocks.createRequest({ + body, + }) + req.user = reviewer.id + req.params.collectionId = collection.id + const inv = collection.invitations.find( + inv => inv.role === 'reviewer' && inv.hasAnswer === false, + ) + req.params.invitationId = inv.id + const res = httpMocks.createResponse() + await require(patchPath)(models)(req, res) + + expect(res.statusCode).toBe(200) + }) it('should return an error params are missing', async () => { const { handlingEditor } = testFixtures.users const { collection } = testFixtures.collections diff --git a/packages/component-invite/src/tests/fixtures/teamIDs.js b/packages/component-invite/src/tests/fixtures/teamIDs.js index 0f525dd4ad024be6346c8c11b6f60f8d287dadf6..607fd6661b1e7c9848bf13257a0d198f230fab00 100644 --- a/packages/component-invite/src/tests/fixtures/teamIDs.js +++ b/packages/component-invite/src/tests/fixtures/teamIDs.js @@ -2,7 +2,9 @@ const Chance = require('chance') const chance = new Chance() const heID = chance.guid() +const revId = chance.guid() module.exports = { heTeamID: heID, + revTeamID: revId, } diff --git a/packages/component-invite/src/tests/fixtures/teams.js b/packages/component-invite/src/tests/fixtures/teams.js index ad1baa82683d19143946c592885dd643982b0c87..7e4611da3489cceb1308e9ffaf072a85866f4ca2 100644 --- a/packages/component-invite/src/tests/fixtures/teams.js +++ b/packages/component-invite/src/tests/fixtures/teams.js @@ -1,9 +1,9 @@ const users = require('./users') const collections = require('./collections') -const { heTeamID } = require('./teamIDs') +const { heTeamID, revTeamID } = require('./teamIDs') const { collection } = collections -const { handlingEditor } = users +const { handlingEditor, reviewer } = users const teams = { heTeam: { teamType: { @@ -21,5 +21,21 @@ const teams = { updateProperties: jest.fn(() => teams.heTeam), id: heTeamID, }, + revTeam: { + teamType: { + name: 'reviewer', + permissions: 'reviewer', + }, + group: 'reviewer', + name: 'reviewer', + object: { + type: 'collection', + id: collection.id, + }, + members: [reviewer.id], + save: jest.fn(() => teams.revTeam), + updateProperties: jest.fn(() => teams.revTeam), + id: revTeamID, + }, } module.exports = teams diff --git a/packages/component-invite/src/tests/fixtures/users.js b/packages/component-invite/src/tests/fixtures/users.js index c474cfc7ad10a44ef6d65e7d1b4665d42ce074d9..5df78f7e0b082fcba48c707baff1ae69d5606a1f 100644 --- a/packages/component-invite/src/tests/fixtures/users.js +++ b/packages/component-invite/src/tests/fixtures/users.js @@ -1,4 +1,4 @@ -const { heTeamID } = require('./teamIDs') +const { heTeamID, revTeamID } = require('./teamIDs') const { handlingEditor, user, admin, author, reviewer } = require('./userData') const Chance = require('chance') @@ -86,6 +86,7 @@ const users = { title: 'Mr', save: jest.fn(() => users.reviewer), isConfirmed: true, + teams: [revTeamID], }, }