@@ -221,6 +221,29 @@ describe("POST /api/hire-us/coinpay-checkout", () => {
221221 expect ( body . payment . checkout_url ) . toBe ( "https://checkout.stripe.test/card-only" ) ;
222222 } ) ;
223223
224+ it ( "falls back when CoinPay returns an invalid checkout amount" , async ( ) => {
225+ process . env . COINPAY_API_KEY = "cp_test_key" ;
226+ process . env . COINPAY_API_URL = "https://coinpayportal.example" ;
227+ process . env . COINPAY_BUSINESS_ID = "business-123" ;
228+ process . env . COINPAY_ELIGIBILITY_MERCHANT_ID = "merchant-123" ;
229+
230+ vi . spyOn ( globalThis , "fetch" ) . mockImplementation ( async ( input ) => {
231+ const url = typeof input === "string" ? input : input . toString ( ) ;
232+ if ( url . includes ( "/api/payments/merchant-eligibility" ) ) {
233+ return jsonResponse ( { success : true , accepts_card : true , accepts_crypto : false , chains : [ ] } ) ;
234+ }
235+ return jsonResponse ( { success : true , payment : { id : "pay_123" , amount_usd : "not-a-number" } } , 201 ) ;
236+ } ) ;
237+
238+ const response = await coinpayCheckout (
239+ new NextRequest ( "http://localhost/api/hire-us/coinpay-checkout" , { method : "POST" , body : "{}" } )
240+ ) ;
241+ const body = await response . json ( ) ;
242+
243+ expect ( response . status ) . toBe ( 201 ) ;
244+ expect ( body . payment . amount_usd ) . toBe ( 250 ) ;
245+ } ) ;
246+
224247 it ( "does not create checkout when no payment rail is available" , async ( ) => {
225248 process . env . COINPAY_API_KEY = "cp_test_key" ;
226249 process . env . COINPAY_API_URL = "https://coinpayportal.example" ;
0 commit comments