diff --git a/apps/meteor/app/livechat/server/lib/closeRoom.ts b/apps/meteor/app/livechat/server/lib/closeRoom.ts index dbaa2ad5d4b..8ee99231ee6 100644 --- a/apps/meteor/app/livechat/server/lib/closeRoom.ts +++ b/apps/meteor/app/livechat/server/lib/closeRoom.ts @@ -42,7 +42,9 @@ export async function closeRoom(params: CloseRoomParams, attempts = 2): Promise< removedInquiryObj = removedInquiry; } catch (e) { logger.error({ err: e, msg: 'Failed to close room', afterAttempts: attempts }); - await session.abortTransaction(); + if (session.inTransaction()) { + await session.abortTransaction(); + } // Dont propagate transaction errors if (shouldRetryTransaction(e)) { if (attempts > 0) { @@ -186,7 +188,7 @@ async function doCloseRoom( } const updatedRoom = await LivechatRooms.closeRoomById(rid, closeData, { session }); - if (!params.forceClose && (!updatedRoom || updatedRoom.modifiedCount !== 1)) { + if (!params.forceClose && updatedRoom?.modifiedCount !== 1) { throw new Error('Error closing room'); } diff --git a/apps/meteor/tests/end-to-end/api/livechat/00-rooms.ts b/apps/meteor/tests/end-to-end/api/livechat/00-rooms.ts index 1f12a536b23..d606feac77a 100644 --- a/apps/meteor/tests/end-to-end/api/livechat/00-rooms.ts +++ b/apps/meteor/tests/end-to-end/api/livechat/00-rooms.ts @@ -145,6 +145,7 @@ describe('LIVECHAT - rooms', () => { }); (IS_EE ? it : it.skip)('should prevent create a room for visitor if an app throws an error', async () => { // this test relies on the app installed by the insertApp fixture + // TODO: this visitor should be created on before block and deleted on after block const visitor = await createVisitor(undefined, 'visitor prevent from app'); const { body } = await request.get(api('livechat/room')).query({ token: visitor.token }); @@ -152,6 +153,7 @@ describe('LIVECHAT - rooms', () => { await deleteVisitor(visitor.token); }); it('should create a room for visitor', async () => { + // TODO: this visitor should be created on before block and deleted on after block const visitor = await createVisitor(); const { body } = await request.get(api('livechat/room')).query({ token: visitor.token }); @@ -164,6 +166,7 @@ describe('LIVECHAT - rooms', () => { await deleteVisitor(visitor.token); }); it('should return an existing open room when visitor has one available', async () => { + // TODO: this visitor should be created on before block and deleted on after block const visitor = await createVisitor(); const { body } = await request.get(api('livechat/room')).query({ token: visitor.token }); @@ -182,6 +185,7 @@ describe('LIVECHAT - rooms', () => { await deleteVisitor(visitor.token); }); it('should return a room for the visitor when rid points to a valid open room', async () => { + // TODO: this visitor should be created on before block and deleted on after block const visitor = await createVisitor(); const room = await createLivechatRoom(visitor.token); const { body } = await request.get(api('livechat/room')).query({ token: visitor.token, rid: room._id }); @@ -194,6 +198,7 @@ describe('LIVECHAT - rooms', () => { await deleteVisitor(visitor.token); }); it('should properly read widget cookies', async () => { + // TODO: this visitor should be created on before block and deleted on after block const visitor = await createVisitor(); const { body } = await request .get(api('livechat/room'))