11import {
2+ AccountController ,
23 OnRampController ,
34 BlockchainApiController ,
45 ConstantsUtil ,
@@ -16,7 +17,18 @@ import type {
1617
1718// Mock dependencies
1819jest . mock ( '../../utils/StorageUtil' ) ;
19- jest . mock ( '../../controllers/BlockchainApiController' ) ;
20+ jest . mock ( '../../controllers/BlockchainApiController' , ( ) => ( {
21+ BlockchainApiController : {
22+ fetchOnRampCountries : jest . fn ( ) ,
23+ fetchOnRampServiceProviders : jest . fn ( ) ,
24+ fetchOnRampPaymentMethods : jest . fn ( ) ,
25+ fetchOnRampFiatCurrencies : jest . fn ( ) ,
26+ fetchOnRampCryptoCurrencies : jest . fn ( ) ,
27+ fetchOnRampFiatLimits : jest . fn ( ) ,
28+ fetchOnRampCountriesDefaults : jest . fn ( ) ,
29+ getOnRampQuotes : jest . fn ( )
30+ }
31+ } ) ) ;
2032jest . mock ( '../../controllers/EventsController' , ( ) => ( {
2133 EventsController : {
2234 sendEvent : jest . fn ( )
@@ -36,7 +48,8 @@ jest.mock('../../utils/CoreHelperUtil', () => ({
3648 getCountryFromTimezone : jest . fn ( ) ,
3749 getBlockchainApiUrl : jest . fn ( ) ,
3850 getApiUrl : jest . fn ( ) ,
39- debounce : jest . fn ( )
51+ debounce : jest . fn ( ) ,
52+ getPlainAddress : jest . fn ( caipAddress => caipAddress ?. split ( ':' ) [ 2 ] )
4053 }
4154} ) ) ;
4255
@@ -329,16 +342,28 @@ describe('OnRampController', () => {
329342 OnRampController . setPaymentCurrency ( mockFiatCurrency ) ;
330343 OnRampController . setPurchaseCurrency ( mockCryptoCurrency ) ;
331344 OnRampController . setPaymentAmount ( 100 ) ;
345+ AccountController . setCaipAddress ( 'eip155:1:0x1234567890123456789012345678901234567890' ) ;
332346
333347 // Mock API response
334348 ( BlockchainApiController . fetchOnRampPaymentMethods as jest . Mock ) . mockResolvedValue ( [
335349 mockPaymentMethod
336350 ] ) ;
351+ ( BlockchainApiController . fetchOnRampCryptoCurrencies as jest . Mock ) . mockResolvedValue ( [
352+ mockCryptoCurrency
353+ ] ) ;
337354 ( BlockchainApiController . getOnRampQuotes as jest . Mock ) . mockResolvedValue ( [ mockQuote ] ) ;
338355
339356 // Execute
340357 expect ( OnRampController . state . quotesLoading ) . toBe ( false ) ;
341358 await OnRampController . fetchPaymentMethods ( ) ;
359+ await OnRampController . fetchCryptoCurrencies ( ) ;
360+
361+ // Set loading to false to allow canGenerateQuote to return true
362+ OnRampController . state . loading = false ;
363+
364+ // Verify that canGenerateQuote returns true before calling getQuotes
365+ expect ( OnRampController . canGenerateQuote ( ) ) . toBe ( true ) ;
366+
342367 await OnRampController . getQuotes ( ) ;
343368
344369 // Verify
@@ -353,7 +378,8 @@ describe('OnRampController', () => {
353378 OnRampController . setSelectedPaymentMethod ( mockPaymentMethod ) ;
354379 OnRampController . setPaymentCurrency ( mockFiatCurrency ) ;
355380 OnRampController . setPurchaseCurrency ( mockCryptoCurrency ) ;
356- OnRampController . setPaymentAmount ( 100 ) ;
381+ OnRampController . setPaymentAmount ( 10 ) ;
382+ AccountController . setCaipAddress ( 'eip155:1:0x1234567890123456789012345678901234567890' ) ;
357383
358384 // Mock API error
359385 ( BlockchainApiController . getOnRampQuotes as jest . Mock ) . mockRejectedValue ( {
@@ -362,6 +388,12 @@ describe('OnRampController', () => {
362388 } ) ;
363389
364390 // Execute
391+ // Set loading to false to allow canGenerateQuote to return true
392+ OnRampController . state . loading = false ;
393+
394+ // Verify that canGenerateQuote returns true before calling getQuotes
395+ expect ( OnRampController . canGenerateQuote ( ) ) . toBe ( true ) ;
396+
365397 await OnRampController . getQuotes ( ) ;
366398
367399 // Verify
0 commit comments