@@ -1097,7 +1097,7 @@ const waitForRoomEvent = async (
10971097 } ) ;
10981098 } ) ;
10991099
1100- it . failing ( 'should accept the invitation by the Rocket.Chat user' , async ( ) => {
1100+ it ( 'should accept the invitation by the Rocket.Chat user' , async ( ) => {
11011101 const response = await acceptRoomInvite ( rcRoom . _id , rcUserConfig2 ) ;
11021102 expect ( response . success ) . toBe ( true ) ;
11031103 } ) ;
@@ -1204,22 +1204,7 @@ const waitForRoomEvent = async (
12041204 } ) ;
12051205
12061206 beforeAll ( async ( ) => {
1207- // Create non-federated DM between rcUser1 and rcUser2
1208- const nonFedDmResponse = await rcUser1 . config . request
1209- . post ( api ( 'dm.create' ) )
1210- . set ( rcUser1 . config . credentials )
1211- . send ( {
1212- username : rcUser2 . username ,
1213- } )
1214- . expect ( 200 ) ;
1215-
1216- expect ( nonFedDmResponse . body ) . toHaveProperty ( 'success' , true ) ;
1217-
1218- const roomInfoNonFed = await getRoomInfo ( nonFedDmResponse . body . room . _id , rcUser1 . config ) ;
1219-
1220- rcRoomNonFed = roomInfoNonFed . room as IRoomNativeFederated ;
1221-
1222- // Create federated DM between rcUser1 and rcUser2 and the Synapse user
1207+ // First create a federated DM between rcUser1 and rcUser2 and the Synapse user, so this is the oldest room
12231208 const fedDmResponse = await rcUser1 . config . request
12241209 . post ( api ( 'dm.create' ) )
12251210 . set ( rcUser1 . config . credentials )
@@ -1260,6 +1245,21 @@ const waitForRoomEvent = async (
12601245 // After acceptance, should display the Synapse user's ID
12611246 expect ( sub ) . toHaveProperty ( 'fname' , `${ federationConfig . hs1 . adminMatrixUserId } , ${ rcUser1 . fullName } ` ) ;
12621247 } ) ;
1248+
1249+ // Then create non-federated DM between rcUser1 and rcUser2 which should be returned on duplication
1250+ const nonFedDmResponse = await rcUser1 . config . request
1251+ . post ( api ( 'dm.create' ) )
1252+ . set ( rcUser1 . config . credentials )
1253+ . send ( {
1254+ username : rcUser2 . username ,
1255+ } )
1256+ . expect ( 200 ) ;
1257+
1258+ expect ( nonFedDmResponse . body ) . toHaveProperty ( 'success' , true ) ;
1259+
1260+ const roomInfoNonFed = await getRoomInfo ( nonFedDmResponse . body . room . _id , rcUser1 . config ) ;
1261+
1262+ rcRoomNonFed = roomInfoNonFed . room as IRoomNativeFederated ;
12631263 } ) ;
12641264
12651265 it ( 'should have two DMs with same users' , async ( ) => {
@@ -1322,9 +1322,6 @@ const waitForRoomEvent = async (
13221322
13231323 expect ( response . body ) . toHaveProperty ( 'success' , true ) ;
13241324
1325- // expect(response.body).toHaveProperty('room._id', rcRoom._id);
1326-
1327- // TODO this is currently wrong, the correct value should be rcRoom._id
13281325 expect ( response . body ) . toHaveProperty ( 'room._id' , rcRoomNonFed . _id ) ;
13291326 } ) ;
13301327 } ) ;
@@ -1435,7 +1432,7 @@ const waitForRoomEvent = async (
14351432 } ) ;
14361433 } ) ;
14371434
1438- it . failing ( 'should create a federated DM between rcUser1 and rcUser2 and the Synapse user' , async ( ) => {
1435+ it ( 'should create a federated DM between rcUser1 and rcUser2 and the Synapse user' , async ( ) => {
14391436 const fedDmResponse = await rcUser1 . config . request
14401437 . post ( api ( 'dm.create' ) )
14411438 . set ( rcUser1 . config . credentials )
@@ -1486,13 +1483,21 @@ const waitForRoomEvent = async (
14861483 { delayMs : 100 } ,
14871484 ) ;
14881485
1489- // TODO accept not working
14901486 const response = await acceptRoomInvite ( rcRoom . _id , rcUser2 . config ) ;
14911487 expect ( response . success ) . toBe ( true ) ;
1488+
1489+ await retry (
1490+ 'wait for the join to be processed' ,
1491+ async ( ) => {
1492+ const sub = await getSubscriptionByRoomId ( rcRoom . _id , rcUser2 . config . credentials , rcUser2 . config . request ) ;
1493+
1494+ expect ( sub ) . not . toHaveProperty ( 'status' ) ;
1495+ } ,
1496+ { delayMs : 100 } ,
1497+ ) ;
14921498 } ) ;
14931499
1494- // TODO this is failing because we cannot accept the invite properly on the line above
1495- it . failing ( 'should have two DMs with same users' , async ( ) => {
1500+ it ( 'should have a single DM with same users before one leaves' , async ( ) => {
14961501 const roomsResponse = await rcUser1 . config . request . get ( api ( 'rooms.get' ) ) . set ( rcUser1 . config . credentials ) . expect ( 200 ) ;
14971502
14981503 const dmRooms = roomsResponse . body . update . filter (
@@ -1506,7 +1511,9 @@ const waitForRoomEvent = async (
15061511
15071512 // at this time there should be only one DM with only two users (the non-federated one)
15081513 expect ( dmRooms . length ) . toBe ( 1 ) ;
1514+ } ) ;
15091515
1516+ it ( 'should leave the federated DM with three users' , async ( ) => {
15101517 // now the rc user leaves the federated DM
15111518 const response = await rcUser2 . config . request
15121519 . post ( api ( 'rooms.leave' ) )
@@ -1518,19 +1525,21 @@ const waitForRoomEvent = async (
15181525
15191526 expect ( response . body ) . toHaveProperty ( 'success' , true ) ;
15201527
1521- await retry (
1522- 'wait for the leave to be processed' ,
1523- async ( ) => {
1524- expect ( hs1Room1 . getMyMembership ( ) ) . toBe ( 'leave' ) ;
1528+ // Verify room is no longer accessible to RC users
1529+ await retry ( 'waiting for room cleanup' , async ( ) => {
1530+ const roomsResponse = await rcUser2 . config . request . get ( api ( 'rooms.get' ) ) . set ( rcUser2 . config . credentials ) . expect ( 200 ) ;
15251531
1526- const sub = await getSubscriptionByRoomId ( rcRoom . _id , rcUser1 . config . credentials , rcUser1 . config . request ) ;
1532+ expect ( roomsResponse . body ) . toHaveProperty ( 'update' ) ;
1533+ expect ( roomsResponse . body . update ) . toBeInstanceOf ( Array ) ;
15271534
1528- // After leave, should display only the RC user's full name
1529- expect ( sub ) . toHaveProperty ( 'fname' , rcUser2 . fullName ) ;
1530- } ,
1531- { delayMs : 100 } ,
1532- ) ;
1535+ const room = roomsResponse . body . update ?. find ( ( r : IRoom ) => r . _id === rcRoom . _id ) ;
1536+
1537+ // Room should not be in active rooms list
1538+ expect ( room ) . toBeUndefined ( ) ;
1539+ } ) ;
1540+ } ) ;
15331541
1542+ it ( 'should have two DMs with same users' , async ( ) => {
15341543 // now there should be two DMs with the same users
15351544 const roomsResponseAfterLeave = await rcUser1 . config . request
15361545 . get ( api ( 'rooms.get' ) )
@@ -1560,9 +1569,6 @@ const waitForRoomEvent = async (
15601569
15611570 expect ( response . body ) . toHaveProperty ( 'success' , true ) ;
15621571
1563- // expect(response.body).toHaveProperty('room._id', rcRoom._id);
1564-
1565- // TODO this is currently wrong, the correct value should be rcRoom._id
15661572 expect ( response . body ) . toHaveProperty ( 'room._id' , rcRoom1on1 . _id ) ;
15671573 } ) ;
15681574 } ) ;
0 commit comments