diff --git a/server-ce/test/create-and-compile-project.spec.ts b/server-ce/test/create-and-compile-project.spec.ts index a9924dbce8..149d505ab5 100644 --- a/server-ce/test/create-and-compile-project.spec.ts +++ b/server-ce/test/create-and-compile-project.spec.ts @@ -102,6 +102,7 @@ describe('Project creation and compilation', function () { cy.findByRole('dialog').within(() => { cy.get('input').type('collaborator@example.com,') cy.findByText('Invite').click({ force: true }) + cy.findByText('Invite not yet accepted.') }) cy.visit('/project') diff --git a/server-ce/test/helpers/project.ts b/server-ce/test/helpers/project.ts index 4af6edc3bb..ba1e7b1da2 100644 --- a/server-ce/test/helpers/project.ts +++ b/server-ce/test/helpers/project.ts @@ -38,6 +38,7 @@ function shareProjectByEmail( .parents('form') .within(() => cy.findByText('Can edit').parent().select(level)) cy.findByText('Invite').click({ force: true }) + cy.findByText('Invite not yet accepted.') }) } diff --git a/services/web/app/src/Features/Collaborators/CollaboratorsInviteHandler.mjs b/services/web/app/src/Features/Collaborators/CollaboratorsInviteHandler.mjs index 26c22bf03f..1409b6e43b 100644 --- a/services/web/app/src/Features/Collaborators/CollaboratorsInviteHandler.mjs +++ b/services/web/app/src/Features/Collaborators/CollaboratorsInviteHandler.mjs @@ -46,21 +46,28 @@ const CollaboratorsInviteHandler = { }, async _sendMessages(projectId, sendingUser, invite) { + const { email } = invite logger.debug( - { projectId, inviteId: invite._id }, + { projectId, email, inviteId: invite._id }, 'sending notification and email for invite' ) - await CollaboratorsEmailHandler.promises.notifyUserOfProjectInvite( - projectId, - invite.email, - invite, - sendingUser - ) - await CollaboratorsInviteHandler._trySendInviteNotification( - projectId, - sendingUser, - invite - ) + const notificationJob = + CollaboratorsInviteHandler._trySendInviteNotification( + projectId, + sendingUser, + invite + ).catch(err => { + logger.err( + { err, projectId, email }, + 'error sending notification for invite' + ) + }) + CollaboratorsEmailHandler.promises + .notifyUserOfProjectInvite(projectId, invite.email, invite, sendingUser) + .catch(err => { + logger.err({ err, projectId, email }, 'error sending email for invite') + }) + await notificationJob }, async inviteToProject(projectId, sendingUser, email, privileges) { @@ -80,12 +87,10 @@ const CollaboratorsInviteHandler = { invite = await invite.save() invite = invite.toObject() - // Send email and notification in background - CollaboratorsInviteHandler._sendMessages(projectId, sendingUser, { + // Send notification and email + await CollaboratorsInviteHandler._sendMessages(projectId, sendingUser, { ...invite, token, - }).catch(err => { - logger.err({ err, projectId, email }, 'error sending messages for invite') }) return _.pick(invite, ['_id', 'email', 'privileges']) diff --git a/services/web/test/unit/src/Collaborators/CollaboratorsInviteHandlerTests.mjs b/services/web/test/unit/src/Collaborators/CollaboratorsInviteHandlerTests.mjs index 1a20d28699..1b2caa7fc3 100644 --- a/services/web/test/unit/src/Collaborators/CollaboratorsInviteHandlerTests.mjs +++ b/services/web/test/unit/src/Collaborators/CollaboratorsInviteHandlerTests.mjs @@ -73,12 +73,18 @@ describe('CollaboratorsInviteHandler', function () { }, addEntryInBackground: sinon.stub(), } + this.logger = { + debug: sinon.stub(), + warn: sinon.stub(), + err: sinon.stub(), + } this.CollaboratorsInviteHandler = await esmock.strict(MODULE_PATH, { '@overleaf/settings': this.settings, '../../../../app/src/models/ProjectInvite.js': { ProjectInvite: this.ProjectInvite, }, + '@overleaf/logger': this.logger, '../../../../app/src/Features/Collaborators/CollaboratorsEmailHandler.mjs': this.CollaboratorsEmailHandler, '../../../../app/src/Features/Collaborators/CollaboratorsHandler.js': @@ -244,15 +250,9 @@ describe('CollaboratorsInviteHandler', function () { sinon.stub().rejects(new Error('woops')) }) - it('should produce an error', async function () { - await expect(this.call()).to.be.rejectedWith(Error) - }) - - it('should not call _trySendInviteNotification', async function () { - await expect(this.call()).to.be.rejected - this.CollaboratorsInviteHandler.promises._trySendInviteNotification.callCount.should.equal( - 0 - ) + it('should not produce an error', async function () { + await expect(this.call()).to.be.fulfilled + expect(this.logger.err).to.be.calledOnce }) }) @@ -262,8 +262,9 @@ describe('CollaboratorsInviteHandler', function () { sinon.stub().rejects(new Error('woops')) }) - it('should produce an error', async function () { - await expect(this.call()).to.be.rejectedWith(Error) + it('should not produce an error', async function () { + await expect(this.call()).to.be.fulfilled + expect(this.logger.err).to.be.calledOnce }) }) })