@@ -2273,6 +2273,92 @@ describe('V2 Wallets:', function () {
22732273 encryptStub . firstCall . args [ 0 ] . should . have . property ( 'password' , 'newPassphrase' ) ;
22742274 encryptStub . firstCall . args [ 0 ] . should . have . property ( 'input' , originalPrivKey ) ;
22752275 } ) ;
2276+
2277+ it ( 'should handle rejected promises and add them to walletShareUpdateErrors' , async ( ) => {
2278+ const walletPassphrase = 'bitgo1234' ;
2279+
2280+ // Mock listSharesV2 to return two shares
2281+ sinon . stub ( Wallets . prototype , 'listSharesV2' ) . resolves ( {
2282+ incoming : [
2283+ {
2284+ id : 'share1' ,
2285+ coin : 'tsol' ,
2286+ walletLabel : 'testing' ,
2287+ fromUser : 'dummyFromUser' ,
2288+ toUser : 'dummyToUser' ,
2289+ wallet : 'wallet1' ,
2290+ permissions : [ 'spend' ] ,
2291+ state : 'active' ,
2292+ } ,
2293+ {
2294+ id : 'share2' ,
2295+ coin : 'tsol' ,
2296+ walletLabel : 'testing2' ,
2297+ fromUser : 'dummyFromUser' ,
2298+ toUser : 'dummyToUser' ,
2299+ wallet : 'wallet2' ,
2300+ permissions : [ 'spend' ] ,
2301+ state : 'active' ,
2302+ } ,
2303+ {
2304+ id : 'share3' ,
2305+ coin : 'tsol' ,
2306+ walletLabel : 'testing3' ,
2307+ fromUser : 'dummyFromUser' ,
2308+ toUser : 'dummyToUser' ,
2309+ wallet : 'wallet3' ,
2310+ permissions : [ 'spend' ] ,
2311+ state : 'active' ,
2312+ } ,
2313+ ] ,
2314+ outgoing : [ ] ,
2315+ } ) ;
2316+
2317+ // Stub processAcceptShare to throw an error for share2
2318+ // Using 'as any' to bypass TypeScript's private method restriction
2319+ const processAcceptShareStub = sinon . stub ( Wallets . prototype as any , 'processAcceptShare' ) ;
2320+ processAcceptShareStub
2321+ . withArgs ( 'share1' , sinon . match . any , sinon . match . any , sinon . match . any , sinon . match . any )
2322+ . resolves ( [ { walletShareId : 'share1' , status : 'accept' } ] ) ;
2323+ processAcceptShareStub
2324+ . withArgs ( 'share2' , sinon . match . any , sinon . match . any , sinon . match . any , sinon . match . any )
2325+ . rejects ( new Error ( 'Failed to process share2' ) ) ;
2326+ processAcceptShareStub
2327+ . withArgs ( 'share3' , sinon . match . any , sinon . match . any , sinon . match . any , sinon . match . any )
2328+ . resolves ( [ { walletShareId : 'share3' , status : 'accept' } ] ) ;
2329+
2330+ // Mock bulkUpdateWalletShareRequest to return a response
2331+ const bulkUpdateStub = sinon . stub ( Wallets . prototype , 'bulkUpdateWalletShareRequest' ) . resolves ( {
2332+ acceptedWalletShares : [ 'share1' , 'share3' ] ,
2333+ rejectedWalletShares : [ ] ,
2334+ walletShareUpdateErrors : [ ] , // Empty array that should be populated
2335+ } ) ;
2336+
2337+ const result = await wallets . bulkUpdateWalletShare ( {
2338+ shares : [
2339+ { walletShareId : 'share1' , status : 'accept' } ,
2340+ { walletShareId : 'share2' , status : 'accept' } ,
2341+ { walletShareId : 'share3' , status : 'accept' } ,
2342+ ] ,
2343+ userLoginPassword : walletPassphrase ,
2344+ } ) ;
2345+
2346+ // Verify bulkUpdateWalletShareRequest was called with only the successful share
2347+ bulkUpdateStub . calledOnce . should . be . true ( ) ;
2348+ const updateParams = bulkUpdateStub . firstCall . args [ 0 ] ;
2349+ updateParams . should . have . lengthOf ( 2 ) ;
2350+ updateParams [ 0 ] . walletShareId . should . equal ( 'share1' ) ;
2351+ updateParams [ 0 ] . status . should . equal ( 'accept' ) ;
2352+ updateParams [ 1 ] . walletShareId . should . equal ( 'share3' ) ;
2353+ updateParams [ 1 ] . status . should . equal ( 'accept' ) ;
2354+
2355+ // Verify the result contains the error information
2356+ result . should . have . property ( 'walletShareUpdateErrors' ) ;
2357+ result . walletShareUpdateErrors . should . be . an . Array ( ) ;
2358+ result . walletShareUpdateErrors . should . have . lengthOf ( 1 ) ;
2359+ result . walletShareUpdateErrors [ 0 ] . should . have . property ( 'walletShareId' , 'share2' ) ;
2360+ result . walletShareUpdateErrors [ 0 ] . should . have . property ( 'reason' , 'Failed to process share2' ) ;
2361+ } ) ;
22762362 } ) ;
22772363 } ) ;
22782364
0 commit comments