@@ -770,4 +770,48 @@ describe('POST /api/:coin/wallet/:walletId/sendmany', () => {
770770 sinon . assert . calledOnce ( verifyStub ) ;
771771 signNock . done ( ) ;
772772 } ) ;
773+
774+ it ( 'should throw an error when neither the pubkey nor the commonKeychain is provided' , async ( ) => {
775+ const walletGetNock = nock ( bitgoApiUrl )
776+ . get ( `/api/v2/${ coin } /wallet/${ walletId } ` )
777+ . matchHeader ( 'any' , ( ) => true )
778+ . reply ( 200 , {
779+ id : walletId ,
780+ type : 'advanced' ,
781+ keys : [ 'user-key-id' , 'backup-key-id' , 'bitgo-key-id' ] ,
782+ } ) ;
783+
784+ // Mock keychain get request
785+ const keychainGetNock = nock ( bitgoApiUrl )
786+ . get ( `/api/v2/${ coin } /key/user-key-id` )
787+ . matchHeader ( 'any' , ( ) => true )
788+ . reply ( 200 , {
789+ id : 'user-key-id' ,
790+ pub : 'xpub_user' ,
791+ } ) ;
792+
793+ const response = await agent
794+ . post ( `/api/${ coin } /wallet/${ walletId } /sendMany` )
795+ . set ( 'Authorization' , `Bearer ${ accessToken } ` )
796+ . send ( {
797+ recipients : [
798+ {
799+ address : 'tb1qtest1' ,
800+ amount : '100000' ,
801+ } ,
802+ ] ,
803+ source : 'user' ,
804+ } ) ;
805+
806+ console . log ( response . body ) ;
807+ response . status . should . equal ( 400 ) ;
808+ response . body . should . have . property ( 'error' ) ;
809+ response . body . error . should . equal ( 'BadRequestError' ) ;
810+ response . body . details . should . equal (
811+ 'Either pubkey or commonKeychain must be provided for user signing' ,
812+ ) ;
813+
814+ walletGetNock . done ( ) ;
815+ keychainGetNock . done ( ) ;
816+ } ) ;
773817} ) ;
0 commit comments