@@ -1823,4 +1823,71 @@ describe('Wallet Prototype Methods', function () {
18231823 } ) ;
18241824 } ) ;
18251825 } ) ;
1826+
1827+ describe ( 'getBitGoFee' , function ( ) {
1828+ let bgUrl : string ;
1829+ let wallet : any ;
1830+
1831+ before ( function ( ) {
1832+ nock . pendingMocks ( ) . should . be . empty ( ) ;
1833+ const prodBitgo = new BitGoAPI ( { env : 'prod' , clientConstants : { constants : { } } } ) ;
1834+ bgUrl = common . Environments [ prodBitgo . getEnv ( ) ] . uri ;
1835+ wallet = new Wallet ( prodBitgo , {
1836+ id : '2NCoSfHH6Ls4CdTS5QahgC9k7x9RfXeSwY4' ,
1837+ private : { keychains : [ userKeypair , backupKeypair , bitgoKey ] } ,
1838+ } ) ;
1839+ } ) ;
1840+
1841+ afterEach ( function ( ) {
1842+ nock . cleanAll ( ) ;
1843+ } ) ;
1844+
1845+ it ( 'sends amount and instant without recipients when recipients array is empty' , async function ( ) {
1846+ const scope = nock ( bgUrl )
1847+ . get ( `/api/v1/wallet/${ wallet . id ( ) } /billing/fee` )
1848+ . query ( { amount : '100000' , instant : 'false' } )
1849+ . reply ( 200 , { fee : 1000 } ) ;
1850+
1851+ const result = await wallet . getBitGoFee ( { amount : 100000 , instant : false } ) ;
1852+ result . fee . should . equal ( 1000 ) ;
1853+ scope . isDone ( ) . should . be . true ( ) ;
1854+ } ) ;
1855+
1856+ it ( 'sends recipients[] query params when recipients are provided' , async function ( ) {
1857+ const addr1 = '3J98t1WpEZ73CNmQviecrnyiWrnqRhWNLy' ;
1858+ const addr2 = '3FZbgi29cpjq2GjdwV8eyHuJJnkLtktZc5' ;
1859+
1860+ const scope = nock ( bgUrl )
1861+ . get ( `/api/v1/wallet/${ wallet . id ( ) } /billing/fee` )
1862+ . query ( ( query ) => {
1863+ const recipientsParam = query [ 'recipients[]' ] ;
1864+ const recipientsList = Array . isArray ( recipientsParam ) ? recipientsParam : [ recipientsParam ] ;
1865+ return query . amount === '100000' && recipientsList . includes ( addr1 ) && recipientsList . includes ( addr2 ) ;
1866+ } )
1867+ . reply ( 200 , { fee : 0 } ) ;
1868+
1869+ const result = await wallet . getBitGoFee ( { amount : 100000 , recipients : [ addr1 , addr2 ] } ) ;
1870+ result . fee . should . equal ( 0 ) ;
1871+ scope . isDone ( ) . should . be . true ( ) ;
1872+ } ) ;
1873+
1874+ it ( 'omits recipients[] when recipients array is empty' , async function ( ) {
1875+ const scope = nock ( bgUrl )
1876+ . get ( `/api/v1/wallet/${ wallet . id ( ) } /billing/fee` )
1877+ . query ( ( query ) => query . amount === '200000' && ! ( 'recipients[]' in query ) )
1878+ . reply ( 200 , { fee : 500 } ) ;
1879+
1880+ const result = await wallet . getBitGoFee ( { amount : 200000 , recipients : [ ] } ) ;
1881+ result . fee . should . equal ( 500 ) ;
1882+ scope . isDone ( ) . should . be . true ( ) ;
1883+ } ) ;
1884+
1885+ it ( 'throws when amount is not a number' , function ( ) {
1886+ ( ( ) => wallet . getBitGoFee ( { amount : 'bad' } ) ) . should . throw ( 'invalid amount argument' ) ;
1887+ } ) ;
1888+
1889+ it ( 'throws when instant is not a boolean' , function ( ) {
1890+ ( ( ) => wallet . getBitGoFee ( { amount : 100 , instant : 'yes' } ) ) . should . throw ( 'invalid instant argument' ) ;
1891+ } ) ;
1892+ } ) ;
18261893} ) ;
0 commit comments