import _ from 'lodash' ; import { teardownPeerSetup , setupPeerWallets , PeerSetupWithWallets , } from '../../../jest/with-peers-setup-teardown' ; import { TestMessageService } from '../../message-service/test-message-service' ; import { getWithPeersCreateChannelsArgs , waitForObjectiveProposals } from '../utils' ; jest . setTimeout ( 60000 ) ; let peerSetup ; beforeAll ( async ( ) => { peerSetup = await setupPeerWallets ( ) ; } ) ; afterAll ( async ( ) => { await teardownPeerSetup ( peerSetup ) ; } ) ; test ( 'approving a completed objective returns immediately' , async ( ) => { const { peerWallets } = peerSetup ; TestMessageService . setLatencyOptions ( peerWallets , { dropRate : 0 } ) ; const createResult = await peerWallets . a . createChannels ( [ getWithPeersCreateChannelsArgs ( peerSetup ) , ] ) ; const { objectiveId } = createResult [ 0 ] ; await waitForObjectiveProposals ( [ objectiveId ] , peerWallets . b ) ; const approveResult = await peerWallets . b . approveObjectives ( [ objectiveId ] ) ; await expect ( createResult ) . toBeObjectiveDoneType ( 'Success' ) ; await expect ( approveResult ) . toBeObjectiveDoneType ( 'Success' ) ; const secondApprove = await peerWallets . b . approveObjectives ( [ objectiveId ] ) ; await expect ( secondApprove ) . toBeObjectiveDoneType ( 'Success' ) ; } ) ; test ( 'can approve the objective multiple times' , async ( ) => { const { peerWallets } = peerSetup ; const result = await peerWallets . a . createChannels ( [ getWithPeersCreateChannelsArgs ( peerSetup ) ] ) ; const { objectiveId } = result [ 0 ] ; await waitForObjectiveProposals ( [ objectiveId ] , peerWallets . b ) ; TestMessageService . freeze ( peerWallets ) ; const firstResult = await peerWallets . b . approveObjectives ( [ objectiveId ] ) ; const secondResult = await peerWallets . b . approveObjectives ( [ objectiveId ] ) ; expect ( firstResult [ 0 ] . currentStatus ) . toBe ( 'approved' ) ; expect ( secondResult [ 0 ] . currentStatus ) . toBe ( 'approved' ) ; TestMessageService . unfreeze ( peerWallets ) ; await expect ( firstResult ) . toBeObjectiveDoneType ( 'Success' ) ; await expect ( secondResult ) . toBeObjectiveDoneType ( 'Success' ) ; } ) ;