-
Notifications
You must be signed in to change notification settings - Fork 135
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 #561 from Expensify/andrewli-parsecurrency
Handle currency symbols with a period in fromUSDToNumber
- Loading branch information
Showing
2 changed files
with
60 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,6 +96,38 @@ describe('Str.sanitizeURL', () => { | |
}); | ||
}); | ||
|
||
describe('Str.fromCurrencyToNumber', () => { | ||
it('Handles negative amounts with minus sign', () => { | ||
expect(Str.fromCurrencyToNumber('-$5.23')).toBe(-523); | ||
expect(Str.fromCurrencyToNumber('$-5.23')).toBe(-523); | ||
}); | ||
|
||
it('Handles negative amounts with ()', () => { | ||
expect(Str.fromCurrencyToNumber('($5.23)')).toBe(-523); | ||
}); | ||
|
||
it('Handles fractional cents when allowed', () => { | ||
expect(Str.fromCurrencyToNumber('$5.223', true)).toBe(522.3); | ||
}); | ||
|
||
it('Handles amounts without leading zeros', () => { | ||
expect(Str.fromCurrencyToNumber('$.23')).toBe(23); | ||
}); | ||
|
||
it('Handles amounts without cents', () => { | ||
expect(Str.fromCurrencyToNumber('$5')).toBe(500); | ||
}); | ||
|
||
it('Handles currency symbols with a period', () => { | ||
expect(Str.fromCurrencyToNumber('Bs.S2.48')).toBe(248); | ||
expect(Str.fromCurrencyToNumber('Bs.S-2.48')).toBe(-248); | ||
expect(Str.fromCurrencyToNumber('-Bs.S2.48')).toBe(-248); | ||
expect(Str.fromCurrencyToNumber('(Bs.S2.48)')).toBe(-248); | ||
expect(Str.fromCurrencyToNumber('Bs.S.48')).toBe(48); | ||
expect(Str.fromCurrencyToNumber('Bs.S2')).toBe(200); | ||
}); | ||
}); | ||
|
||
describe('Str.isValidEmail', () => { | ||
it('Correctly detects a valid email', () => { | ||
expect(Str.isValidEmail('[email protected]')).toBeTruthy(); | ||
|
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