@@ -192,13 +192,20 @@ describe('ConstructPendingApprovalTx codec tests', function () {
192192 } ) ;
193193
194194 describe ( 'ConstructPendingApprovalTxResponse' , function ( ) {
195- it ( 'should validate response with required tx field' , function ( ) {
195+ it ( 'should validate response with only required tx field' , function ( ) {
196196 const validResponse = {
197197 tx : '0100000001c7dad3d9607a23c45a6c1c5ad7bce02acff71a0f21eb4a72a59d0c0e19402d0f0000000000ffffffff0180a21900000000001976a914c918e1b36f2c72b1aaef94dbb7f578a4b68b542788ac00000000' ,
198198 } ;
199199
200200 const decoded = assertDecode ( ConstructPendingApprovalTxResponse , validResponse ) ;
201201 assert . strictEqual ( decoded . tx , validResponse . tx ) ;
202+ assert . strictEqual ( decoded . fee , undefined ) ;
203+ assert . strictEqual ( decoded . feeRate , undefined ) ;
204+ assert . strictEqual ( decoded . instant , undefined ) ;
205+ assert . strictEqual ( decoded . bitgoFee , undefined ) ;
206+ assert . strictEqual ( decoded . travelInfos , undefined ) ;
207+ assert . strictEqual ( decoded . estimatedSize , undefined ) ;
208+ assert . strictEqual ( decoded . unspents , undefined ) ;
202209 } ) ;
203210
204211 it ( 'should validate response with all fields' , function ( ) {
@@ -244,7 +251,7 @@ describe('ConstructPendingApprovalTx codec tests', function () {
244251 } ) ;
245252 } ) ;
246253
247- it ( 'should reject response with non-number fee' , function ( ) {
254+ it ( 'should reject response with non-number fee (optional field, but must be number if provided) ' , function ( ) {
248255 const invalidResponse = {
249256 tx : '0100000001c7dad3d9607a23c45a6c1c5ad7bce02acff71a0f21eb4a72a59d0c0e19402d0f0000000000ffffffff0180a21900000000001976a914c918e1b36f2c72b1aaef94dbb7f578a4b68b542788ac00000000' ,
250257 fee : '10000' , // string instead of number
@@ -255,7 +262,7 @@ describe('ConstructPendingApprovalTx codec tests', function () {
255262 } ) ;
256263 } ) ;
257264
258- it ( 'should reject response with non-number feeRate' , function ( ) {
265+ it ( 'should reject response with non-number feeRate (optional field, but must be number if provided) ' , function ( ) {
259266 const invalidResponse = {
260267 tx : '0100000001c7dad3d9607a23c45a6c1c5ad7bce02acff71a0f21eb4a72a59d0c0e19402d0f0000000000ffffffff0180a21900000000001976a914c918e1b36f2c72b1aaef94dbb7f578a4b68b542788ac00000000' ,
261268 feeRate : '20000' , // string instead of number
@@ -266,7 +273,7 @@ describe('ConstructPendingApprovalTx codec tests', function () {
266273 } ) ;
267274 } ) ;
268275
269- it ( 'should reject response with non-boolean instant' , function ( ) {
276+ it ( 'should reject response with non-boolean instant (optional field, but must be boolean if provided) ' , function ( ) {
270277 const invalidResponse = {
271278 tx : '0100000001c7dad3d9607a23c45a6c1c5ad7bce02acff71a0f21eb4a72a59d0c0e19402d0f0000000000ffffffff0180a21900000000001976a914c918e1b36f2c72b1aaef94dbb7f578a4b68b542788ac00000000' ,
272279 instant : 'false' , // string instead of boolean
@@ -276,7 +283,8 @@ describe('ConstructPendingApprovalTx codec tests', function () {
276283 assertDecode ( ConstructPendingApprovalTxResponse , invalidResponse ) ;
277284 } ) ;
278285 } ) ;
279- it ( 'should reject response with non-number estimatedSize' , function ( ) {
286+
287+ it ( 'should reject response with non-number estimatedSize (optional field, but must be number if provided)' , function ( ) {
280288 const invalidResponse = {
281289 tx : '0100000001c7dad3d9607a23c45a6c1c5ad7bce02acff71a0f21eb4a72a59d0c0e19402d0f0000000000ffffffff0180a21900000000001976a914c918e1b36f2c72b1aaef94dbb7f578a4b68b542788ac00000000' ,
282290 estimatedSize : '256' , // string instead of number
@@ -386,6 +394,8 @@ describe('ConstructPendingApprovalTx codec tests', function () {
386394 fee : 10000 ,
387395 feeRate : 20000 ,
388396 instant : false ,
397+ estimatedSize : 256 ,
398+ unspents : [ { id : 'unspent1' , value : 1000000 } ] ,
389399 } ;
390400
391401 afterEach ( function ( ) {
@@ -523,6 +533,46 @@ describe('ConstructPendingApprovalTx codec tests', function () {
523533 assert . strictEqual ( decodedResponse . fee , 15000 ) ;
524534 } ) ;
525535
536+ it ( 'should successfully construct a pending approval transaction with minimal response (only tx)' , async function ( ) {
537+ const requestBody = {
538+ walletPassphrase : 'mySecurePassphrase' ,
539+ } ;
540+
541+ const minimalMockResponse = {
542+ tx : '0100000001c7dad3d9607a23c45a6c1c5ad7bce02acff71a0f21eb4a72a59d0c0e19402d0f0000000000ffffffff0180a21900000000001976a914c918e1b36f2c72b1aaef94dbb7f578a4b68b542788ac00000000' ,
543+ } ;
544+
545+ const mockPendingApproval = {
546+ constructApprovalTx : sinon . stub ( ) . resolves ( minimalMockResponse ) ,
547+ } ;
548+
549+ const mockPendingApprovals = {
550+ get : sinon . stub ( ) . resolves ( mockPendingApproval ) ,
551+ } ;
552+
553+ sinon . stub ( BitGo . prototype , 'pendingApprovals' ) . returns ( mockPendingApprovals as any ) ;
554+
555+ const result = await agent
556+ . put ( '/api/v1/pendingapprovals/test-approval-id-123/constructTx' )
557+ . set ( 'Authorization' , 'Bearer test_access_token_12345' )
558+ . set ( 'Content-Type' , 'application/json' )
559+ . send ( requestBody ) ;
560+
561+ assert . strictEqual ( result . status , 200 ) ;
562+ result . body . should . have . property ( 'tx' ) ;
563+ assert . strictEqual ( result . body . tx , minimalMockResponse . tx ) ;
564+
565+ const decodedResponse = assertDecode ( ConstructPendingApprovalTxResponse , result . body ) ;
566+ assert . strictEqual ( decodedResponse . tx , minimalMockResponse . tx ) ;
567+ assert . strictEqual ( decodedResponse . fee , undefined ) ;
568+ assert . strictEqual ( decodedResponse . feeRate , undefined ) ;
569+ assert . strictEqual ( decodedResponse . instant , undefined ) ;
570+ assert . strictEqual ( decodedResponse . bitgoFee , undefined ) ;
571+ assert . strictEqual ( decodedResponse . travelInfos , undefined ) ;
572+ assert . strictEqual ( decodedResponse . estimatedSize , undefined ) ;
573+ assert . strictEqual ( decodedResponse . unspents , undefined ) ;
574+ } ) ;
575+
526576 it ( 'should successfully construct a pending approval transaction with all optional response fields' , async function ( ) {
527577 const requestBody = {
528578 walletPassphrase : 'mySecurePassphrase' ,
@@ -866,7 +916,7 @@ describe('ConstructPendingApprovalTx codec tests', function () {
866916 } ) ;
867917 } ) ;
868918
869- it ( 'should reject response with wrong type for fee' , async function ( ) {
919+ it ( 'should reject response with wrong type for fee (optional but must be number if provided) ' , async function ( ) {
870920 const requestBody = {
871921 walletPassphrase : 'mySecurePassphrase' ,
872922 } ;
0 commit comments