Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/utils/__tests__/validation.test.js
Show First 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | describe('Validation utils', () => { | ||||
}); | }); | ||||
it(`Returns balance error if ${currency.ticker} send amount is greater than user balance with fiat currency selected`, () => { | it(`Returns balance error if ${currency.ticker} send amount is greater than user balance with fiat currency selected`, () => { | ||||
const expectedValidationError = `Amount cannot exceed your ${currency.ticker} balance`; | const expectedValidationError = `Amount cannot exceed your ${currency.ticker} balance`; | ||||
// Here, user is trying to send $170 USD, where 1 BCHA = $20 USD, and the user has a balance of 5 BCHA or $100 | // Here, user is trying to send $170 USD, where 1 BCHA = $20 USD, and the user has a balance of 5 BCHA or $100 | ||||
expect(shouldRejectAmountInput('170', 'USD', 20.0, 5)).toBe( | expect(shouldRejectAmountInput('170', 'USD', 20.0, 5)).toBe( | ||||
expectedValidationError, | expectedValidationError, | ||||
); | ); | ||||
}); | }); | ||||
it(`Returns precision error if ${currency.ticker} send amount has more than 8 decimal places`, () => { | it(`Returns precision error if ${currency.ticker} send amount has more than ${currency.cashDecimals} decimal places`, () => { | ||||
const expectedValidationError = `${currency.ticker} transactions do not support more than 8 decimal places`; | const expectedValidationError = `${currency.ticker} transactions do not support more than ${currency.cashDecimals} decimal places`; | ||||
expect( | expect( | ||||
shouldRejectAmountInput('17.123456789', currency.ticker, 20.0, 35), | shouldRejectAmountInput('17.123456789', currency.ticker, 20.0, 35), | ||||
).toBe(expectedValidationError); | ).toBe(expectedValidationError); | ||||
}); | }); | ||||
it(`Returns expected crypto amount with 8 decimals of precision even if inputs have higher precision`, () => { | it(`Returns expected crypto amount with ${currency.cashDecimals} decimals of precision even if inputs have higher precision`, () => { | ||||
expect(fiatToCrypto('10.97231694823432', 20.3231342349234234)).toBe( | expect(fiatToCrypto('10.97231694823432', 20.3231342349234234)).toBe( | ||||
'0.53989295', | '0.53989295', | ||||
); | ); | ||||
}); | }); | ||||
it(`Returns expected crypto amount with 8 decimals of precision even if inputs have lower precision`, () => { | it(`Returns expected crypto amount with ${currency.cashDecimals} decimals of precision even if inputs have lower precision`, () => { | ||||
expect(fiatToCrypto('10.94', 10)).toBe('1.09400000'); | expect(fiatToCrypto('10.94', 10)).toBe('1.09400000'); | ||||
}); | }); | ||||
}); | }); |