diff --git a/packages/bridge-controller/src/utils/index.test.ts b/packages/bridge-controller/src/utils/index.test.ts index af4e6cbb3b..beacf3e894 100644 --- a/packages/bridge-controller/src/utils/index.test.ts +++ b/packages/bridge-controller/src/utils/index.test.ts @@ -1,3 +1,4 @@ +/* eslint-disable n/no-process-env */ import { abiERC20 } from '@metamask/metamask-eth-abis'; import type { Hex } from '@metamask/utils'; import { Contract } from 'ethers'; @@ -8,8 +9,13 @@ import { isSwapsDefaultTokenAddress, isSwapsDefaultTokenSymbol, sumHexes, + getBridgeApiBaseUrl, } from '.'; import { ETH_USDT_ADDRESS, METABRIDGE_ETHEREUM_ADDRESS } from '../constants'; +import { + BRIDGE_DEV_API_BASE_URL, + BRIDGE_PROD_API_BASE_URL, +} from '../constants'; import { CHAIN_IDS } from '../constants/chains'; import { SWAPS_CHAINID_DEFAULT_TOKEN_MAP } from '../constants/tokens'; @@ -132,4 +138,30 @@ describe('Bridge utils', () => { expect(isSwapsDefaultTokenSymbol('ETH', '' as Hex)).toBe(false); }); }); + + describe('getBridgeApiBaseUrl', () => { + const originalEnv = process.env; + + beforeEach(() => { + process.env = { ...originalEnv }; + }); + + afterEach(() => { + process.env = originalEnv; + }); + + it('returns custom API URL when BRIDGE_CUSTOM_API_BASE_URL is set', () => { + process.env.BRIDGE_CUSTOM_API_BASE_URL = 'https://custom-api.example.com'; + expect(getBridgeApiBaseUrl()).toBe('https://custom-api.example.com'); + }); + + it('returns dev API URL when BRIDGE_USE_DEV_APIS is set', () => { + process.env.BRIDGE_USE_DEV_APIS = 'true'; + expect(getBridgeApiBaseUrl()).toBe(BRIDGE_DEV_API_BASE_URL); + }); + + it('returns prod API URL by default', () => { + expect(getBridgeApiBaseUrl()).toBe(BRIDGE_PROD_API_BASE_URL); + }); + }); });