diff --git a/packages/component-invite/src/controllers/assignCollectionRole.js b/packages/component-invite/src/controllers/assignCollectionRole.js index cd855f6221ce59106910c090011d0eb1148f0882..febc1a39305c6c4a5f182437bf75e8a3053cb287 100644 --- a/packages/component-invite/src/controllers/assignCollectionRole.js +++ b/packages/component-invite/src/controllers/assignCollectionRole.js @@ -76,10 +76,16 @@ module.exports = async ( ) await collHelper.addAssignedPeople(collection, user, role) } else { - const matchingInvitation = inviteHelper.getMatchingInvitation( - user.invitations, - collectionId, - role, + // const matchingInvitation = inviteHelper.getMatchingInvitation( + // user.invitations, + // collectionId, + // role, + // ) + const matchingInvitation = user.invitations.find( + invitation => + invitation.collectionId === collectionId && + invitation.role === role && + invitation.hasAnswer === false, ) if (matchingInvitation === undefined) { user = await inviteHelper.setupInvitation( diff --git a/packages/component-invite/src/tests/fixtures/users.js b/packages/component-invite/src/tests/fixtures/users.js index c1542563fd1b62c510a94705386cb06be944c341..b2df443684be78b5c88a92fcde5bdd2fefd03a9a 100644 --- a/packages/component-invite/src/tests/fixtures/users.js +++ b/packages/component-invite/src/tests/fixtures/users.js @@ -111,7 +111,7 @@ const users = { }, ], teams: [heTeamID], - save: jest.fn(() => users.handlingEditor), + save: jest.fn(() => users.invitedHandlingEditor), editorInChief: false, }, } diff --git a/packages/component-invite/src/tests/postInvite.test.js b/packages/component-invite/src/tests/postInvite.test.js index 509b355392e6b2f645b8d805a3aa92947f2328bf..76720c1e3049a0c42d2bc3456437bbe421098c11 100644 --- a/packages/component-invite/src/tests/postInvite.test.js +++ b/packages/component-invite/src/tests/postInvite.test.js @@ -219,6 +219,26 @@ describe('Post invite route handler', () => { const data = JSON.parse(res._getData()) expect(data.email).toEqual(body.email) expect(data.invitations[0].collectionId).toEqual(req.params.collectionId) - expect(data.invitations).toHaveLength(1) + }) + it('should return success when the EiC invites the a HE after he declined an invitation', async () => { + const body = { + email: invitedHandlingEditor.email, + role: 'handlingEditor', + } + const req = httpMocks.createRequest({ + body, + }) + req.user = editorInChief.id + req.params.collectionId = standardCollection.id + const initialSize = invitedHandlingEditor.invitations.length + const res = httpMocks.createResponse() + await require(postInvitePath)(models)(req, res) + + expect(res.statusCode).toBe(200) + const data = JSON.parse(res._getData()) + expect(data.email).toEqual(body.email) + expect(invitedHandlingEditor.invitations.length).toBeGreaterThan( + initialSize, + ) }) })