Changeset View
Changeset View
Standalone View
Standalone View
web/cashtab/src/utils/__tests__/validation.test.js
import { | import { | ||||
shouldRejectAmountInput, | shouldRejectAmountInput, | ||||
fiatToCrypto, | fiatToCrypto, | ||||
isValidTokenName, | isValidTokenName, | ||||
isValidTokenTicker, | isValidTokenTicker, | ||||
isValidTokenDecimals, | isValidTokenDecimals, | ||||
isValidTokenInitialQty, | isValidTokenInitialQty, | ||||
isValidTokenDocumentUrl, | isValidTokenDocumentUrl, | ||||
} from '../validation'; | } from '../validation'; | ||||
import { currency } from '@components/Common/Ticker.js'; | import { currency } from '@components/Common/Ticker.js'; | ||||
import { fromSmallestDenomination } from '@utils/cashMethods'; | |||||
describe('Validation utils', () => { | describe('Validation utils', () => { | ||||
it(`Returns 'false' if ${currency.ticker} send amount is a valid send amount`, () => { | it(`Returns 'false' if ${currency.ticker} send amount is a valid send amount`, () => { | ||||
expect(shouldRejectAmountInput('10', currency.ticker, 20.0, 300)).toBe( | expect(shouldRejectAmountInput('10', currency.ticker, 20.0, 300)).toBe( | ||||
false, | false, | ||||
); | ); | ||||
}); | }); | ||||
it(`Returns 'false' if ${currency.ticker} send amount is a valid send amount in USD`, () => { | it(`Returns 'false' if ${currency.ticker} send amount is a valid send amount in USD`, () => { | ||||
Show All 25 Lines | it(`Returns balance error if ${currency.ticker} send amount is greater than user balance`, () => { | ||||
); | ); | ||||
}); | }); | ||||
it(`Returns balance error if ${currency.ticker} send amount is greater than user balance`, () => { | it(`Returns balance error if ${currency.ticker} send amount is greater than user balance`, () => { | ||||
const expectedValidationError = `Amount cannot exceed your ${currency.ticker} balance`; | const expectedValidationError = `Amount cannot exceed your ${currency.ticker} balance`; | ||||
expect(shouldRejectAmountInput('17', currency.ticker, 20.0, 3)).toBe( | expect(shouldRejectAmountInput('17', currency.ticker, 20.0, 3)).toBe( | ||||
expectedValidationError, | expectedValidationError, | ||||
); | ); | ||||
}); | }); | ||||
it(`Returns error if ${currency.ticker} send amount is less than ${currency.dust} minimum`, () => { | it(`Returns error if ${ | ||||
const expectedValidationError = `Send amount must be at least ${currency.dust} ${currency.ticker}`; | currency.ticker | ||||
} send amount is less than ${fromSmallestDenomination( | |||||
currency.dustSats, | |||||
).toString()} minimum`, () => { | |||||
const expectedValidationError = `Send amount must be at least ${fromSmallestDenomination( | |||||
currency.dustSats, | |||||
).toString()} ${currency.ticker}`; | |||||
expect( | expect( | ||||
shouldRejectAmountInput( | shouldRejectAmountInput( | ||||
(currency.dust - 0.00000001).toString(), | ( | ||||
fromSmallestDenomination(currency.dustSats).toString() - | |||||
0.00000001 | |||||
).toString(), | |||||
currency.ticker, | currency.ticker, | ||||
20.0, | 20.0, | ||||
3, | 3, | ||||
), | ), | ||||
).toBe(expectedValidationError); | ).toBe(expectedValidationError); | ||||
}); | }); | ||||
it(`Returns error if ${currency.ticker} send amount is less than ${currency.dust} minimum in fiat currency`, () => { | it(`Returns error if ${ | ||||
const expectedValidationError = `Send amount must be at least ${currency.dust} ${currency.ticker}`; | currency.ticker | ||||
} send amount is less than ${fromSmallestDenomination( | |||||
currency.dustSats, | |||||
).toString()} minimum in fiat currency`, () => { | |||||
const expectedValidationError = `Send amount must be at least ${fromSmallestDenomination( | |||||
currency.dustSats, | |||||
).toString()} ${currency.ticker}`; | |||||
expect( | expect( | ||||
shouldRejectAmountInput('0.0000005', 'USD', 14.63, 0.52574662), | shouldRejectAmountInput('0.0000005', 'USD', 14.63, 0.52574662), | ||||
).toBe(expectedValidationError); | ).toBe(expectedValidationError); | ||||
}); | }); | ||||
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( | ||||
▲ Show 20 Lines • Show All 104 Lines • Show Last 20 Lines |