-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #406 from PayButton/fix/supported-currencies
Fix/supported currencies
- Loading branch information
Showing
4 changed files
with
84 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
import { fiatCurrencies, isCrypto, isFiat, isValidCurrency } from '../util/api-client'; | ||
|
||
describe('API Client Util Tests', () => { | ||
describe('isCrypto', () => { | ||
it('recognizes valid crypto currencies', () => { | ||
expect(isCrypto('BCH')).toBeTruthy(); | ||
expect(isCrypto('XEC')).toBeTruthy(); | ||
}); | ||
|
||
it('does not recognize invalid crypto currencies', () => { | ||
expect(isCrypto('BTC')).toBeFalsy(); | ||
expect(isCrypto('ETH')).toBeFalsy(); | ||
}); | ||
|
||
it('is case-sensitive', () => { | ||
expect(isCrypto('bch')).toBeFalsy(); | ||
expect(isCrypto('xec')).toBeFalsy(); | ||
}); | ||
|
||
it('returns false for empty strings', () => { | ||
expect(isCrypto('')).toBeFalsy(); | ||
}); | ||
|
||
it('returns false for whitespace or special characters', () => { | ||
expect(isCrypto(' BCH ')).toBeFalsy(); | ||
expect(isCrypto('BCH@')).toBeFalsy(); | ||
}); | ||
}); | ||
|
||
describe('isValidCurrency', () => { | ||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
it('identifies fiat currencies correctly', () => { | ||
expect(isValidCurrency('USD')).toBeTruthy(); | ||
expect(isValidCurrency('EUR')).toBeFalsy(); | ||
expect(isValidCurrency('CAD')).toBeTruthy(); | ||
expect(isValidCurrency('GBP')).toBeFalsy(); | ||
expect(isValidCurrency('AUD')).toBeFalsy(); | ||
}); | ||
|
||
it('identifies crypto currencies correctly', () => { | ||
expect(isValidCurrency('BCH')).toBeTruthy(); | ||
expect(isValidCurrency('XEC')).toBeTruthy(); | ||
}); | ||
|
||
it('returns false for unrecognized currencies', () => { | ||
expect(isValidCurrency('XYZ')).toBeFalsy(); | ||
expect(isValidCurrency('ABC')).toBeFalsy(); | ||
}); | ||
|
||
it('is case-sensitive', () => { | ||
expect(isValidCurrency('bch')).toBeFalsy(); | ||
expect(isValidCurrency('usd')).toBeFalsy(); | ||
expect(isValidCurrency('xec')).toBeFalsy(); | ||
}); | ||
|
||
it('returns false for spaces or special characters', () => { | ||
expect(isValidCurrency(' BCH ')).toBeFalsy(); | ||
expect(isValidCurrency('USD@')).toBeFalsy(); | ||
}); | ||
}); | ||
|
||
describe('isFiat', () => { | ||
test('returns true for valid fiat currencies', () => { | ||
fiatCurrencies.forEach(currency => { | ||
expect(isFiat(currency)).toBe(true); | ||
}); | ||
}); | ||
|
||
test('returns false for invalid fiat currencies', () => { | ||
const invalidCurrencies = ['INR', 'JPY', 'BTC', 'ETH', 'XYZ', 'EUR']; | ||
invalidCurrencies.forEach(currency => { | ||
expect(isFiat(currency)).toBe(false); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters