chore: Prevent transaction error (#39279)

pull/39180/merge
Guilherme Gazzo 7 days ago committed by GitHub
parent 0d00b05d77
commit d9bceb4655
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 6
      apps/meteor/app/livechat/server/lib/closeRoom.ts
  2. 5
      apps/meteor/tests/end-to-end/api/livechat/00-rooms.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');
}

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

Loading…
Cancel
Save