@@ -236,6 +236,58 @@ describe('POST /api/:coin/wallet/:walletId/consolidateunspents', () => {
236236 sinon . assert . calledOnce ( consolidateUnspentsStub ) ;
237237 } ) ;
238238
239+ it ( 'should fail when consolidateUnspents returns array with more than one element' , async ( ) => {
240+ const walletGetNock = nock ( bitgoApiUrl )
241+ . get ( `/api/v2/${ coin } /wallet/${ walletId } ` )
242+ . matchHeader ( 'authorization' , `Bearer ${ accessToken } ` )
243+ . reply ( 200 , mockWalletData ) ;
244+
245+ const keychainGetNock = nock ( bitgoApiUrl )
246+ . get ( `/api/v2/${ coin } /key/user-key-id` )
247+ . matchHeader ( 'authorization' , `Bearer ${ accessToken } ` )
248+ . reply ( 200 , mockUserKeychain ) ;
249+
250+ const mockArrayResult = [
251+ {
252+ txid : 'first-tx-id' ,
253+ tx : '01000000000102first...' ,
254+ status : 'signed' ,
255+ } ,
256+ {
257+ txid : 'second-tx-id' ,
258+ tx : '01000000000102second...' ,
259+ status : 'signed' ,
260+ } ,
261+ ] ;
262+
263+ const consolidateUnspentsStub = sinon
264+ . stub ( Wallet . prototype , 'consolidateUnspents' )
265+ . resolves ( mockArrayResult ) ;
266+
267+ const requestPayload = {
268+ pubkey : mockUserKeychain . pub ,
269+ source : 'user' as const ,
270+ feeRate : 1000 ,
271+ } ;
272+
273+ const response = await agent
274+ . post ( `/api/${ coin } /wallet/${ walletId } /consolidateunspents` )
275+ . set ( 'Authorization' , `Bearer ${ accessToken } ` )
276+ . send ( requestPayload ) ;
277+
278+ response . status . should . equal ( 500 ) ;
279+ response . body . should . have . property ( 'error' , 'Internal Server Error' ) ;
280+ response . body . should . have . property ( 'name' , 'Error' ) ;
281+ response . body . should . have . property (
282+ 'details' ,
283+ 'Expected single consolidation result, but received 2 results' ,
284+ ) ;
285+
286+ walletGetNock . done ( ) ;
287+ keychainGetNock . done ( ) ;
288+ sinon . assert . calledOnce ( consolidateUnspentsStub ) ;
289+ } ) ;
290+
239291 it ( 'should succeed in consolidating unspents with all optional parameters' , async ( ) => {
240292 const walletGetNock = nock ( bitgoApiUrl )
241293 . get ( `/api/v2/${ coin } /wallet/${ walletId } ` )
0 commit comments