import { compositeContractsFinishCatcher , compositeContractsWorker } from '../compositeContracts' ; import { takeEvery , put , spawn } from 'redux-saga/effects' ; import * as transaction from 'modules/transaction' ; jest . mock ( 'uuid' , ( ) => ( { v4 : ( ) => '' } ) ) ; describe ( 'composite contracts signing saga' , ( ) => { it ( 'compositeContractsWorker, < 5 contracts, compositeResult = success' , ( ) => { const action = { type : transaction . actions . runCompositeContracts . started , payload : [ { data : [ '1' , 2 , 'test' ] , name : 'MainCondition' , meta : { } } ] , } ; const compositeResult = { success : { } } ; const iterator = compositeContractsWorker ( action ) ; iterator . next ( ) ; iterator . next ( 'generatedKey' ) ; iterator . next ( ) ; iterator . next ( ) ; iterator . next ( ) ; iterator . next ( ) ; expect ( iterator . next ( compositeResult ) . value ) . toEqual ( undefined ) ; } ) ; it ( 'compositeContractsWorker, > 5 contracts, compositeResult = success' , ( ) => { const action = { type : transaction . actions . runCompositeContracts . started , payload : [ { data : [ '1' , 2 , 'test' , '1' , 2 , 'test' ] , name : 'MainCondition' , meta : { } } ] , } ; const compositeResult = { success : { } } ; const iterator = compositeContractsWorker ( action ) ; iterator . next ( ) ; iterator . next ( 'generatedKey' ) ; iterator . next ( ) ; iterator . next ( ) ; iterator . next ( ) ; iterator . next ( ) ; iterator . next ( ) ; iterator . next ( ) ; iterator . next ( compositeResult ) ; iterator . next ( compositeResult ) ; expect ( iterator . next ( compositeResult ) . value ) . toEqual ( undefined ) ; } ) ; it ( 'compositeContractsWorker, < 5 contracts, compositeResult = failed' , ( ) => { const action = { type : transaction . actions . runCompositeContracts . started , payload : [ { data : [ '1' , ] , name : 'MainCondition' , meta : { } } ] , } ; const compositeResult = { failed : { } } ; const iterator = compositeContractsWorker ( action ) ; iterator . next ( ) ; iterator . next ( 'generatedKey' ) ; iterator . next ( ) ; iterator . next ( ) ; expect ( iterator . next ( compositeResult ) . value ) . toEqual ( put ( transaction . actions . runCompositeContracts . failed ( { params : { name : 'finished' , data : '' } , error : 'Composite contract run failed.' } ) ) ) ; } ) ; } ) ;