[server-pro] tests: make project invite tests more reliable (#23732)

* [web] wait for sending project invite notification, send email detached

Errors from sending the notification or email are still logged only.
Wait up-to ~one second for notification to be sent (API timeout is 1s).

* [server-pro] tests: wait for invite action to complete

GitOrigin-RevId: e6998e6134b5267c91b47785d616a46e9651b996
This commit is contained in:
Jakob Ackermann
2025-02-20 15:02:59 +00:00
committed by Copybot
parent 2e72aa8a47
commit 0be79e846c
4 changed files with 35 additions and 27 deletions

View File

@@ -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')

View File

@@ -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.')
})
}

View File

@@ -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'])

View File

@@ -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
})
})
})