import { sanitizeIncomingPeerInfo , sanitizeInitialPeerInfo } from '../../../src/utils' ; import { initPeerInfoList } from '../../utils/peers' ; describe ( 'utils/sanitize' , ( ) => { describe ( '#sanitizeIncomingPeerInfo' , ( ) => { describe ( 'when rawPeerInfo is valid' , ( ) => { it ( 'should return the peerInfo with peerId' , ( ) => { const samplePeers = initPeerInfoList ( ) ; const { ipAddress , port , sharedState , peerId } = samplePeers [ 0 ] ; const samplePeerWithoutInternalState = { ipAddress , port , sharedState , peerId , } ; const protocolPeerInfo = { ipAddress , port , ... sharedState , } ; expect ( sanitizeIncomingPeerInfo ( protocolPeerInfo ) ) . toEqual ( samplePeerWithoutInternalState ) ; } ) ; } ) ; } ) ; describe ( '#sanitizeInitialPeerInfo' , ( ) => { it ( 'should return only sanitized fields' , ( ) => { const samplePeers = initPeerInfoList ( ) ; const { peerId , ipAddress , port } = samplePeers [ 0 ] ; const protocolPeerInfo = { ... samplePeers [ 0 ] , } ; expect ( sanitizeInitialPeerInfo ( protocolPeerInfo ) ) . toEqual ( { peerId , ipAddress , port , } ) ; } ) ; it ( 'should remove' , ( ) => { const samplePeers = initPeerInfoList ( ) ; const { ipAddress , port , sharedState , peerId } = samplePeers [ 0 ] ; const samplePeerWithoutInternalState = { ipAddress , port , sharedState , peerId , } ; const protocolPeerInfo = { ipAddress , port , ... sharedState , } ; expect ( sanitizeIncomingPeerInfo ( protocolPeerInfo ) ) . toEqual ( samplePeerWithoutInternalState ) ; } ) ; } ) ; describe ( '#sanitizePeerLists' , ( ) => { it . todo ( 'should return an object with several peer lists' ) ; } ) ; } ) ;