|
| 1 | +import { generateOffRampURL } from './generateOffRampURL'; |
| 2 | + |
| 3 | +describe('generateOffRampURL', () => { |
| 4 | + it('generates URL with expected default parameters', () => { |
| 5 | + const url = new URL( |
| 6 | + generateOffRampURL({ |
| 7 | + appId: 'test', |
| 8 | + }), |
| 9 | + ); |
| 10 | + |
| 11 | + expect(url.origin).toEqual('https://pay.coinbase.com'); |
| 12 | + expect(url.pathname).toEqual('/v3/sell/input'); |
| 13 | + expect(url.searchParams.get('appId')).toEqual('test'); |
| 14 | + }); |
| 15 | + |
| 16 | + it('should support redirectUrl', () => { |
| 17 | + const url = new URL( |
| 18 | + generateOffRampURL({ |
| 19 | + appId: 'test', |
| 20 | + redirectUrl: 'https://example.com', |
| 21 | + }), |
| 22 | + ); |
| 23 | + |
| 24 | + expect(url.searchParams.get('redirectUrl')).toEqual('https://example.com'); |
| 25 | + }); |
| 26 | + |
| 27 | + it('generates URL with multiple addresses', () => { |
| 28 | + const addresses = { |
| 29 | + '0x1': ['base', 'ethereum'], |
| 30 | + '123abc': ['solana'], |
| 31 | + }; |
| 32 | + |
| 33 | + const url = new URL( |
| 34 | + generateOffRampURL({ |
| 35 | + appId: 'test', |
| 36 | + addresses, |
| 37 | + redirectUrl: 'https://example.com', |
| 38 | + }), |
| 39 | + ); |
| 40 | + |
| 41 | + expect(url.searchParams.get('addresses')).toEqual( |
| 42 | + '{"0x1":["base","ethereum"],"123abc":["solana"]}', |
| 43 | + ); |
| 44 | + }); |
| 45 | + |
| 46 | + it('generates URL with multiple addresses and assets', () => { |
| 47 | + const url = new URL( |
| 48 | + generateOffRampURL({ |
| 49 | + appId: 'test', |
| 50 | + addresses: { |
| 51 | + '0x5ome4ddre55': ['ethereum', 'avalanche-c-chain'], |
| 52 | + '90123jd09ef09df': ['solana'], |
| 53 | + }, |
| 54 | + assets: ['USDC', 'SOL'], |
| 55 | + }), |
| 56 | + ); |
| 57 | + |
| 58 | + expect(url.searchParams.get('addresses')).toEqual( |
| 59 | + `{\"0x5ome4ddre55\":[\"ethereum\",\"avalanche-c-chain\"],\"90123jd09ef09df\":[\"solana\"]}`, |
| 60 | + ); |
| 61 | + expect(url.searchParams.get('assets')).toEqual('["USDC","SOL"]'); |
| 62 | + }); |
| 63 | + |
| 64 | + it('should support dynamic host', () => { |
| 65 | + const url = new URL( |
| 66 | + generateOffRampURL({ |
| 67 | + host: 'http://localhost:3000', |
| 68 | + appId: 'test', |
| 69 | + }), |
| 70 | + ); |
| 71 | + |
| 72 | + expect(url.origin).toEqual('http://localhost:3000'); |
| 73 | + expect(url.pathname).toEqual('/v3/sell/input'); |
| 74 | + expect(url.searchParams.get('appId')).toEqual('test'); |
| 75 | + }); |
| 76 | + |
| 77 | + it('should support preset amounts', () => { |
| 78 | + const url = new URL( |
| 79 | + generateOffRampURL({ |
| 80 | + appId: 'test', |
| 81 | + presetCryptoAmount: 0.1, |
| 82 | + presetFiatAmount: 20, |
| 83 | + }), |
| 84 | + ); |
| 85 | + |
| 86 | + expect(url.searchParams.get('presetFiatAmount')).toEqual('20'); |
| 87 | + expect(url.searchParams.get('presetCryptoAmount')).toEqual('0.1'); |
| 88 | + }); |
| 89 | + |
| 90 | + it('should support defaultNetwork', () => { |
| 91 | + const url = new URL( |
| 92 | + generateOffRampURL({ |
| 93 | + appId: 'test', |
| 94 | + defaultNetwork: 'ethereum', |
| 95 | + }), |
| 96 | + ); |
| 97 | + expect(url.searchParams.get('defaultNetwork')).toEqual('ethereum'); |
| 98 | + }); |
| 99 | + |
| 100 | + it('should support sessionToken', () => { |
| 101 | + const url = new URL( |
| 102 | + generateOffRampURL({ |
| 103 | + sessionToken: 'test', |
| 104 | + }), |
| 105 | + ); |
| 106 | + expect(url.origin).toEqual('https://pay.coinbase.com'); |
| 107 | + expect(url.pathname).toEqual('/v3/sell/input'); |
| 108 | + expect(url.searchParams.get('sessionToken')).toEqual('test'); |
| 109 | + }); |
| 110 | +}); |
0 commit comments