11import * as sinon from 'sinon' ;
22import should from 'should' ;
3- import * as express from 'express' ;
4- import { handleUpdateLightningWalletCoinSpecific } from '../../../src/lightning/lightningWalletRoutes' ;
53import { BitGo } from 'bitgo' ;
6- import { ApiResponseError } from '../../../src/errors ' ;
4+ import { ExpressApiRouteRequest } from '../../../src/typedRoutes/api ' ;
75
86describe ( 'Lightning Wallet Routes' , ( ) => {
97 let bitgo ;
108 const coin = 'tlnbtc' ;
119
12- const mockRequestObject = ( params : { body ?: any ; params ?: any ; query ?: any ; bitgo ?: any } ) => {
13- const req : Partial < express . Request > = { } ;
14- req . body = params . body || { } ;
15- req . params = params . params || { } ;
16- req . query = params . query || { } ;
17- req . bitgo = params . bitgo ;
18- return req as express . Request ;
19- } ;
20-
2110 beforeEach ( ( ) => {
2211 const walletStub = { } ;
2312 const coinStub = {
@@ -53,11 +42,16 @@ describe('Lightning Wallet Routes', () => {
5342 } ,
5443 } ) ;
5544
56- const req = mockRequestObject ( {
45+ const req = {
5746 params : { id : 'testWalletId' , coin } ,
5847 body : inputParams ,
48+ decoded : {
49+ id : 'testWalletId' ,
50+ coin,
51+ ...inputParams ,
52+ } ,
5953 bitgo,
60- } ) ;
54+ } as unknown as ExpressApiRouteRequest < 'express.wallet.update' , 'put' > ;
6155
6256 const result = await lightningRoutes . handleUpdateLightningWalletCoinSpecific ( req ) ;
6357
@@ -70,45 +64,5 @@ describe('Lightning Wallet Routes', () => {
7064 should ( secondArg ) . have . property ( 'signerHost' , 'signer.example.com' ) ;
7165 should ( secondArg ) . have . property ( 'passphrase' , 'wallet-password-123' ) ;
7266 } ) ;
73-
74- it ( 'should throw error when passphrase is missing' , async ( ) => {
75- const invalidParams = {
76- signerMacaroon : 'encrypted-data' ,
77- signerHost : 'signer.example.com' ,
78- } ;
79-
80- const req = mockRequestObject ( {
81- params : { id : 'testWalletId' , coin } ,
82- body : invalidParams ,
83- bitgo,
84- } ) ;
85-
86- await should ( handleUpdateLightningWalletCoinSpecific ( req ) )
87- . be . rejectedWith ( ApiResponseError )
88- . then ( ( error ) => {
89- should ( error . status ) . equal ( 400 ) ;
90- should ( error . message ) . equal ( 'Invalid request body to update lightning wallet coin specific' ) ;
91- } ) ;
92- } ) ;
93-
94- it ( 'should handle invalid request body' , async ( ) => {
95- const invalidParams = {
96- signerHost : 12345 , // invalid type
97- passphrase : 'valid-pass' ,
98- } ;
99-
100- const req = mockRequestObject ( {
101- params : { id : 'testWalletId' , coin } ,
102- body : invalidParams ,
103- bitgo,
104- } ) ;
105-
106- await should ( handleUpdateLightningWalletCoinSpecific ( req ) )
107- . be . rejectedWith ( ApiResponseError )
108- . then ( ( error ) => {
109- should ( error . status ) . equal ( 400 ) ;
110- should ( error . message ) . equal ( 'Invalid request body to update lightning wallet coin specific' ) ;
111- } ) ;
112- } ) ;
11367 } ) ;
11468} ) ;
0 commit comments