Skip to content

Commit 91d62c5

Browse files
chore: fixed onramp test
1 parent ea56d23 commit 91d62c5

File tree

2 files changed

+47
-6
lines changed

2 files changed

+47
-6
lines changed

packages/core/src/__tests__/controllers/ConnectionController.test.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,31 @@ const client: ConnectionControllerClient = {
88
onUri(walletConnectUri);
99
await Promise.resolve();
1010
},
11-
disconnect: async () => Promise.resolve()
11+
disconnect: async () => Promise.resolve(),
12+
signMessage: function (): Promise<string> {
13+
throw new Error('Function not implemented.');
14+
},
15+
sendTransaction: function (): Promise<`0x${string}` | null> {
16+
throw new Error('Function not implemented.');
17+
},
18+
parseUnits: function (): bigint {
19+
throw new Error('Function not implemented.');
20+
},
21+
formatUnits: function (): string {
22+
throw new Error('Function not implemented.');
23+
},
24+
writeContract: function (): Promise<`0x${string}` | null> {
25+
throw new Error('Function not implemented.');
26+
},
27+
estimateGas: function (): Promise<bigint> {
28+
throw new Error('Function not implemented.');
29+
},
30+
getEnsAddress: function (): Promise<false | string> {
31+
throw new Error('Function not implemented.');
32+
},
33+
getEnsAvatar: function (): Promise<false | string> {
34+
throw new Error('Function not implemented.');
35+
}
1236
};
1337

1438
// -- Tests --------------------------------------------------------------------

packages/core/src/__tests__/controllers/OnRampController.test.ts

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
1-
import { OnRampController, BlockchainApiController, ConstantsUtil } from '../../index';
1+
import {
2+
OnRampController,
3+
BlockchainApiController,
4+
ConstantsUtil,
5+
CoreHelperUtil
6+
} from '../../index';
27
import { StorageUtil } from '../../utils/StorageUtil';
38
import type {
49
OnRampCountry,
@@ -17,6 +22,7 @@ jest.mock('../../controllers/EventsController', () => ({
1722
sendEvent: jest.fn()
1823
}
1924
}));
25+
2026
jest.mock('../../controllers/NetworkController', () => ({
2127
NetworkController: {
2228
state: {
@@ -25,6 +31,15 @@ jest.mock('../../controllers/NetworkController', () => ({
2531
}
2632
}));
2733

34+
jest.mock('../../utils/CoreHelperUtil', () => ({
35+
CoreHelperUtil: {
36+
getCountryFromTimezone: jest.fn(),
37+
getBlockchainApiUrl: jest.fn(),
38+
getApiUrl: jest.fn(),
39+
debounce: jest.fn()
40+
}
41+
}));
42+
2843
const mockCountry: OnRampCountry = {
2944
countryCode: 'US',
3045
flagImageUrl: 'https://flagcdn.com/w20/us.png',
@@ -214,16 +229,18 @@ describe('OnRampController', () => {
214229

215230
describe('setSelectedCountry', () => {
216231
it('should update country and currency', async () => {
217-
// Mock API responses
218-
(StorageUtil.setOnRampPreferredCountry as jest.Mock).mockResolvedValue(undefined);
219-
(StorageUtil.setOnRampPreferredFiatCurrency as jest.Mock).mockResolvedValue(undefined);
232+
// Mock utils
233+
(StorageUtil.getOnRampCountries as jest.Mock).mockResolvedValue([]);
234+
(StorageUtil.getOnRampPreferredCountry as jest.Mock).mockResolvedValue(undefined);
235+
(StorageUtil.setOnRampCountries as jest.Mock).mockImplementation(() => Promise.resolve([]));
236+
(CoreHelperUtil.getCountryFromTimezone as jest.Mock).mockReturnValue('US');
220237

221238
// Mock COUNTRY_CURRENCIES mapping
222239
const originalCountryCurrencies = ConstantsUtil.COUNTRY_CURRENCIES;
223240
Object.defineProperty(ConstantsUtil, 'COUNTRY_CURRENCIES', {
224241
value: {
225242
US: 'USD',
226-
AR: 'ARS' // Assuming mockCountry2 has ES country code
243+
AR: 'ARS'
227244
},
228245
configurable: true
229246
});

0 commit comments

Comments
 (0)