@@ -147,35 +147,56 @@ describe("createRoom", () => {
147
147
} ) ;
148
148
149
149
describe ( "canEncryptToAllUsers" , ( ) => {
150
- const trueUser = new Map ( [
151
- [
152
- "@goodUser:localhost" ,
153
- new Map ( [
154
- [ "DEV1" , { } as unknown as DeviceInfo ] ,
155
- [ "DEV2" , { } as unknown as DeviceInfo ] ,
156
- ] ) ,
157
- ] ,
158
- ] ) ;
150
+ const user1Id = "@user1:example.com" ;
151
+ const user2Id = "@user2:example.com" ;
159
152
160
- const falseUser = {
161
- "@badUser:localhost" : { } ,
162
- } ;
153
+ const devices = new Map ( [
154
+ [ "DEV1" , { } as unknown as DeviceInfo ] ,
155
+ [ "DEV2" , { } as unknown as DeviceInfo ] ,
156
+ ] ) ;
163
157
164
158
let client : Mocked < MatrixClient > ;
165
- beforeEach ( ( ) => {
166
- stubClient ( ) ;
167
- client = mocked ( MatrixClientPeg . get ( ) ) ;
159
+
160
+ beforeAll ( ( ) => {
161
+ client = mocked ( stubClient ( ) ) ;
168
162
} ) ;
169
163
170
- it ( "returns true if all devices have crypto " , async ( ) => {
171
- client . downloadKeys . mockResolvedValue ( trueUser ) ;
172
- const response = await canEncryptToAllUsers ( client , [ "@goodUser:localhost" ] ) ;
173
- expect ( response ) . toBe ( true ) ;
164
+ it ( "should return false if download keys does not return any user " , async ( ) => {
165
+ client . downloadKeys . mockResolvedValue ( new Map ( ) ) ;
166
+ const result = await canEncryptToAllUsers ( client , [ user1Id , user2Id ] ) ;
167
+ expect ( result ) . toBe ( false ) ;
174
168
} ) ;
175
169
176
- it ( "returns false if not all users have crypto" , async ( ) => {
177
- client . downloadKeys . mockResolvedValue ( { ...trueUser , ...falseUser } ) ;
178
- const response = await canEncryptToAllUsers ( client , [ "@goodUser:localhost" , "@badUser:localhost" ] ) ;
179
- expect ( response ) . toBe ( false ) ;
170
+ it ( "should return false if none of the users has a device" , async ( ) => {
171
+ client . downloadKeys . mockResolvedValue (
172
+ new Map ( [
173
+ [ user1Id , new Map ( ) ] ,
174
+ [ user2Id , new Map ( ) ] ,
175
+ ] ) ,
176
+ ) ;
177
+ const result = await canEncryptToAllUsers ( client , [ user1Id , user2Id ] ) ;
178
+ expect ( result ) . toBe ( false ) ;
179
+ } ) ;
180
+
181
+ it ( "should return false if some of the users don't have a device" , async ( ) => {
182
+ client . downloadKeys . mockResolvedValue (
183
+ new Map ( [
184
+ [ user1Id , new Map ( ) ] ,
185
+ [ user2Id , devices ] ,
186
+ ] ) ,
187
+ ) ;
188
+ const result = await canEncryptToAllUsers ( client , [ user1Id , user2Id ] ) ;
189
+ expect ( result ) . toBe ( false ) ;
190
+ } ) ;
191
+
192
+ it ( "should return true if all users have a device" , async ( ) => {
193
+ client . downloadKeys . mockResolvedValue (
194
+ new Map ( [
195
+ [ user1Id , devices ] ,
196
+ [ user2Id , devices ] ,
197
+ ] ) ,
198
+ ) ;
199
+ const result = await canEncryptToAllUsers ( client , [ user1Id , user2Id ] ) ;
200
+ expect ( result ) . toBe ( true ) ;
180
201
} ) ;
181
202
} ) ;
0 commit comments