@@ -18,7 +18,7 @@ import { mocked } from "jest-mock";
1818import { MatrixClient , Room } from "matrix-js-sdk/src/matrix" ;
1919
2020import DMRoomMap from "../../../src/utils/DMRoomMap" ;
21- import { createTestClient , makeMembershipEvent } from "../../test-utils" ;
21+ import { createTestClient , makeMembershipEvent , mkThirdPartyInviteEvent } from "../../test-utils" ;
2222import { LocalRoom } from "../../../src/models/LocalRoom" ;
2323import { findDMForUser } from "../../../src/utils/dm/findDMForUser" ;
2424import { getFunctionalMembers } from "../../../src/utils/room/getFunctionalMembers" ;
@@ -32,13 +32,15 @@ describe("findDMForUser", () => {
3232 const userId2 = "@user2:example.com" ;
3333 const userId3 = "@user3:example.com" ;
3434 const botId = "@bot:example.com" ;
35+ const thirdPartyId = "party@example.com" ;
3536 let room1 : Room ;
3637 let room2 : LocalRoom ;
3738 let room3 : Room ;
3839 let room4 : Room ;
3940 let room5 : Room ;
4041 let room6 : Room ;
41- const room7Id = "!room7:example.com" ;
42+ let room7 : Room ;
43+ const unknownRoomId = "!unknown:example.com" ;
4244 let dmRoomMap : DMRoomMap ;
4345 let mockClient : MatrixClient ;
4446
@@ -89,6 +91,14 @@ describe("findDMForUser", () => {
8991 makeMembershipEvent ( room6 . roomId , userId3 , "join" ) ,
9092 ] ) ;
9193
94+ // room with pending third-party invite
95+ room7 = new Room ( "!room7:example.com" , mockClient , userId1 ) ;
96+ room7 . getMyMembership = ( ) => "join" ;
97+ room7 . currentState . setStateEvents ( [
98+ makeMembershipEvent ( room7 . roomId , userId1 , "join" ) ,
99+ mkThirdPartyInviteEvent ( thirdPartyId , "third-party" , room7 . roomId ) ,
100+ ] ) ;
101+
92102 mocked ( mockClient . getRoom ) . mockImplementation ( ( roomId : string ) => {
93103 return (
94104 {
@@ -98,6 +108,7 @@ describe("findDMForUser", () => {
98108 [ room4 . roomId ] : room4 ,
99109 [ room5 . roomId ] : room5 ,
100110 [ room6 . roomId ] : room6 ,
111+ [ room7 . roomId ] : room7 ,
101112 } [ roomId ] || null
102113 ) ;
103114 } ) ;
@@ -113,14 +124,15 @@ describe("findDMForUser", () => {
113124 room4 . roomId ,
114125 room5 . roomId ,
115126 room6 . roomId ,
116- room7Id , // this room does not exist in client
127+ room7 . roomId ,
128+ unknownRoomId , // this room does not exist in client
117129 ] ) ,
118130 ) ,
119131 } as unknown as DMRoomMap ;
120132 jest . spyOn ( DMRoomMap , "shared" ) . mockReturnValue ( dmRoomMap ) ;
121133 mocked ( dmRoomMap . getDMRoomsForUserId ) . mockImplementation ( ( userId : string ) => {
122134 if ( userId === userId1 ) {
123- return [ room1 . roomId , room2 . roomId , room3 . roomId , room4 . roomId , room5 . roomId , room7Id ] ;
135+ return [ room1 . roomId , room2 . roomId , room3 . roomId , room4 . roomId , room5 . roomId , unknownRoomId ] ;
124136 }
125137
126138 return [ ] ;
@@ -158,4 +170,8 @@ describe("findDMForUser", () => {
158170
159171 expect ( findDMForUser ( mockClient , userId3 ) ) . toBe ( room6 ) ;
160172 } ) ;
173+
174+ it ( "should find a room with a pending third-party invite" , ( ) => {
175+ expect ( findDMForUser ( mockClient , thirdPartyId ) ) . toBe ( room7 ) ;
176+ } ) ;
161177} ) ;
0 commit comments