import { ConnectionStatus } from '@wireapp/api-client/src/connection' ; import { USER_EVENT , UserConnectionEvent } from '@wireapp/api-client/src/event' ; import { UserConnectionData } from '@wireapp/api-client/src/user/data' ; import { PayloadBundleSource , PayloadBundleState , PayloadBundleType } from '../conversation' ; import { UserConnectionMessage } from '../conversation/message/UserMessage' ; import { UserMapper } from './UserMapper' ; describe ( 'UserMapper' , ( ) => { describe ( '"mapUserEvent"' , ( ) => { it ( 'maps "user.connection" events' , ( ) => { const selfUserId = '95dbbc18-5e22-41dc-acce-0d9d983c1a60' ; const event = { connection : { conversation : '19dbbc18-5e22-41dc-acce-0d9d983c1a60' , from : '39b7f597-dfd1-4dff-86f5-fe1b79cb70a0' , last_update : '2018-07-06T09:38:52.286Z' , message : ' ' , status : ConnectionStatus . SENT , to : 'e023c681-7e51-43dd-a5d8-0f821e70a9c0' , } , type : USER_EVENT . CONNECTION , user : { name : 'Someone' , } , } ; const incomingEvent = UserMapper . mapUserEvent ( event , selfUserId , PayloadBundleSource . WEBSOCKET ) as UserConnectionMessage ; expect ( incomingEvent . content ) . toEqual ( { connection : event . connection , user : event . user } as UserConnectionData ) ; expect ( incomingEvent . conversation ) . toBe ( event . connection . conversation ) ; expect ( incomingEvent . from ) . toBe ( event . connection . from ) ; expect ( typeof incomingEvent . id ) . toBe ( 'string' ) ; expect ( incomingEvent . messageTimer ) . toBe ( 0 ) ; expect ( incomingEvent . state ) . toBe ( PayloadBundleState . INCOMING ) ; expect ( incomingEvent . timestamp ) . toBe ( new Date ( event . connection . last_update ) . getTime ( ) ) ; expect ( incomingEvent . type ) . toBe ( PayloadBundleType . CONNECTION_REQUEST ) ; } ) ; } ) ; } ) ;