@@ -21,6 +21,7 @@ import {RECEIPT_MODE} from '@wireapp/api-client/lib/conversation/data';
21
21
import { amplify } from 'amplify' ;
22
22
import { StatusCodes as HTTP_STATUS } from 'http-status-codes' ;
23
23
24
+ import { Availability } from '@wireapp/protocol-messaging' ;
24
25
import { WebAppEvents } from '@wireapp/webapp-events' ;
25
26
26
27
import { entities } from 'test/api/payloads' ;
@@ -207,7 +208,6 @@ describe('UserRepository', () => {
207
208
208
209
describe ( 'loadUsers' , ( ) => {
209
210
const localUsers = [ generateAPIUser ( ) , generateAPIUser ( ) , generateAPIUser ( ) ] ;
210
- //const connections = [new ConnectionEntity()];
211
211
beforeEach ( async ( ) => {
212
212
jest . resetAllMocks ( ) ;
213
213
userState . users . removeAll ( ) ;
@@ -220,7 +220,7 @@ describe('UserRepository', () => {
220
220
const userIds = users . map ( user => user . qualified_id ! ) ;
221
221
const fetchUserSpy = jest . spyOn ( userRepository [ 'userService' ] , 'getUsers' ) . mockResolvedValue ( { found : newUsers } ) ;
222
222
223
- await userRepository . loadUsers ( new User ( ) , [ ] , [ ] , userIds ) ;
223
+ await userRepository . loadUsers ( new User ( 'self' ) , [ ] , [ ] , userIds ) ;
224
224
225
225
expect ( userState . users ( ) ) . toHaveLength ( users . length + 1 ) ;
226
226
expect ( fetchUserSpy ) . toHaveBeenCalledWith ( newUsers . map ( user => user . qualified_id ! ) ) ;
@@ -230,12 +230,33 @@ describe('UserRepository', () => {
230
230
const userIds = localUsers . map ( user => user . qualified_id ! ) ;
231
231
const fetchUserSpy = jest . spyOn ( userRepository [ 'userService' ] , 'getUsers' ) . mockResolvedValue ( { found : [ ] } ) ;
232
232
233
- await userRepository . loadUsers ( new User ( ) , [ ] , [ ] , userIds ) ;
233
+ await userRepository . loadUsers ( new User ( 'self' ) , [ ] , [ ] , userIds ) ;
234
234
235
235
expect ( userState . users ( ) ) . toHaveLength ( localUsers . length + 1 ) ;
236
236
expect ( fetchUserSpy ) . not . toHaveBeenCalled ( ) ;
237
237
} ) ;
238
238
239
+ it ( 'loads users that are partially stored in the DB and maps availability' , async ( ) => {
240
+ const userIds = localUsers . map ( user => user . qualified_id ! ) ;
241
+ const partialUsers = [
242
+ { id : userIds [ 0 ] . id , availability : Availability . Type . AVAILABLE } ,
243
+ { id : userIds [ 1 ] . id , availability : Availability . Type . BUSY } ,
244
+ ] ;
245
+
246
+ jest . spyOn ( userRepository [ 'userService' ] , 'loadUserFromDb' ) . mockResolvedValue ( partialUsers as any ) ;
247
+ const fetchUserSpy = jest
248
+ . spyOn ( userRepository [ 'userService' ] , 'getUsers' )
249
+ . mockResolvedValue ( { found : localUsers } ) ;
250
+
251
+ await userRepository . loadUsers ( new User ( 'self' ) , [ ] , [ ] , userIds ) ;
252
+
253
+ expect ( userState . users ( ) ) . toHaveLength ( localUsers . length + 1 ) ;
254
+ expect ( fetchUserSpy ) . toHaveBeenCalledWith ( userIds ) ;
255
+
256
+ const userWithAvailability = userState . users ( ) . filter ( user => user . availability ( ) !== Availability . Type . NONE ) ;
257
+ expect ( userWithAvailability ) . toHaveLength ( partialUsers . length ) ;
258
+ } ) ;
259
+
239
260
it ( 'deletes users that are not needed' , async ( ) => {
240
261
const newUsers = [ generateAPIUser ( ) , generateAPIUser ( ) ] ;
241
262
const userIds = newUsers . map ( user => user . qualified_id ! ) ;
0 commit comments