@@ -63,21 +63,34 @@ describe('Payment Routes', () => {
6363 } )
6464
6565 await paymentRoutes . payment ( ctx )
66- expect ( ctx . response . body ) . toBe ( Result . APPROVED )
66+ expect ( ctx . response . body ) . toEqual ( { result : { code : Result . APPROVED } } )
6767 expect ( ctx . status ) . toBe ( 200 )
6868
6969 expect ( webhookWaitMap . get ( 'incoming-payment-url' ) ) . toBeUndefined ( )
7070 } )
7171
72- test ( 'returns cardService error code when thrown' , async ( ) => {
72+ test ( 'returns 200 with invalid_signature result when card service returns invalid signature' , async ( ) => {
73+ const ctx = createPaymentContext ( )
74+ mockPaymentService ( )
75+ jest
76+ . spyOn ( cardServiceClient , 'sendPayment' )
77+ . mockResolvedValueOnce ( Result . INVALID_SIGNATURE )
78+ await paymentRoutes . payment ( ctx )
79+ expect ( ctx . response . body ) . toEqual ( {
80+ result : { code : Result . INVALID_SIGNATURE }
81+ } )
82+ expect ( ctx . status ) . toBe ( 200 )
83+ } )
84+
85+ test ( 'returns 400 invalid_request body when an error is thrown' , async ( ) => {
7386 const ctx = createPaymentContext ( )
7487 mockPaymentService ( )
7588 jest
7689 . spyOn ( cardServiceClient , 'sendPayment' )
7790 . mockRejectedValue ( new CardServiceClientError ( 'Some error' , 404 ) )
7891 await paymentRoutes . payment ( ctx )
79- expect ( ctx . response . body ) . toBe ( 'Some error' )
80- expect ( ctx . status ) . toBe ( 404 )
92+ expect ( ctx . response . body ) . toEqual ( { error : { code : 'invalid_request' } } )
93+ expect ( ctx . status ) . toBe ( 400 )
8194 } )
8295
8396 test ( 'returns 400 when there is a paymentService error' , async ( ) => {
@@ -86,22 +99,22 @@ describe('Payment Routes', () => {
8699 . spyOn ( paymentService , 'getWalletAddress' )
87100 . mockRejectedValueOnce ( new Error ( 'Wallet address error' ) )
88101 await paymentRoutes . payment ( ctx )
89- expect ( ctx . response . body ) . toBe ( 'Wallet address error' )
102+ expect ( ctx . response . body ) . toEqual ( { error : { code : 'invalid_request' } } )
90103 expect ( ctx . status ) . toBe ( 400 )
91104 } )
92105
93- test ( 'returns 500 when an unknown error is thrown' , async ( ) => {
106+ test ( 'returns 400 when an unknown error is thrown' , async ( ) => {
94107 const ctx = createPaymentContext ( )
95108 jest
96109 . spyOn ( paymentService , 'getWalletAddress' )
97110 . mockRejectedValueOnce ( 'Unknown error' )
98111 await paymentRoutes . payment ( ctx )
99- expect ( ctx . response . body ) . toBe ( 'Unknown error' )
100- expect ( ctx . status ) . toBe ( 500 )
112+ expect ( ctx . response . body ) . toEqual ( { error : { code : 'invalid_request' } } )
113+ expect ( ctx . status ) . toBe ( 400 )
101114 } )
102115
103116 test (
104- 'returns 504 if incoming payment event times out' ,
117+ 'returns 400 if incoming payment event times out' ,
105118 withConfigOverride (
106119 ( ) => config ,
107120 { webhookTimeoutMs : 1 } ,
@@ -118,10 +131,10 @@ describe('Payment Routes', () => {
118131 . spyOn ( cardServiceClient , 'sendPayment' )
119132 . mockResolvedValueOnce ( Result . APPROVED )
120133 await paymentRoutes . payment ( ctx )
121- expect ( ctx . response . body ) . toBe (
122- 'Timed out waiting for incoming payment event'
123- )
124- expect ( ctx . status ) . toBe ( 504 )
134+ expect ( ctx . response . body ) . toEqual ( {
135+ error : { code : 'invalid_request' }
136+ } )
137+ expect ( ctx . status ) . toBe ( 400 )
125138
126139 expect ( deleteSpy ) . toHaveBeenCalled ( )
127140 }
0 commit comments