|
7 | 7 | formatNetworkName, |
8 | 8 | isNetworkSupported, |
9 | 9 | parseAmount, |
| 10 | + sanitizePaymentRequest, |
10 | 11 | } from '../paymentHelpers' |
11 | 12 |
|
12 | 13 | describe('paymentHelpers', () => { |
@@ -77,6 +78,37 @@ describe('paymentHelpers', () => { |
77 | 78 | expect(request.googlePayMerchantId).toBe('google-pay-merchant-id') |
78 | 79 | }) |
79 | 80 |
|
| 81 | + it('omits undefined optional fields from created payment requests', () => { |
| 82 | + const request = createPaymentRequest({ |
| 83 | + amount: 10, |
| 84 | + label: 'Order', |
| 85 | + merchantName: undefined, |
| 86 | + googlePayMerchantId: undefined, |
| 87 | + googlePayGateway: 'stripe', |
| 88 | + }) |
| 89 | + |
| 90 | + expect(request).not.toHaveProperty('merchantName') |
| 91 | + expect(request).not.toHaveProperty('googlePayMerchantId') |
| 92 | + expect(request.googlePayGateway).toBe('stripe') |
| 93 | + }) |
| 94 | + |
| 95 | + it('sanitizes payment requests before native bridging', () => { |
| 96 | + const request = sanitizePaymentRequest({ |
| 97 | + countryCode: 'PL', |
| 98 | + currencyCode: 'PLN', |
| 99 | + paymentItems: [{ label: 'Order', amount: 10, type: 'final' }], |
| 100 | + supportedNetworks: ['visa'], |
| 101 | + merchantCapabilities: ['3DS'], |
| 102 | + merchantName: undefined, |
| 103 | + googlePayGateway: 'przelewy24', |
| 104 | + googlePayGatewayMerchantId: undefined, |
| 105 | + } as any) |
| 106 | + |
| 107 | + expect(request).not.toHaveProperty('merchantName') |
| 108 | + expect(request).not.toHaveProperty('googlePayGatewayMerchantId') |
| 109 | + expect(request.googlePayGateway).toBe('przelewy24') |
| 110 | + }) |
| 111 | + |
80 | 112 | it('formats and parses amount values', () => { |
81 | 113 | expect(formatAmount(29.9)).toBe('29.90') |
82 | 114 | expect(parseAmount('29.90')).toBeCloseTo(29.9) |
|
0 commit comments