mirror of
https://github.com/stablyai/orca.git
synced 2026-10-31 17:17:38 +00:00
Display provider credit and currency balances separately from rate limits. Preserve quotas when balance data is unavailable and translate complete labels. Supersedes #9363; credit to @mmarabel for the original implementation. Co-authored-by: mmarabel <166927047+mmarabel@users.noreply.github.com>
31 lines
1.1 KiB
TypeScript
31 lines
1.1 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
import { formatCurrencyAmount } from './currency-format'
|
|
|
|
describe('formatCurrencyAmount', () => {
|
|
it('formats USD amounts with the dollar symbol', () => {
|
|
// Force a stable locale-independent expectation by asserting substrings.
|
|
const formatted = formatCurrencyAmount(12.4, 'USD')
|
|
expect(formatted).toMatch(/12[.,]40/)
|
|
expect(formatted).toContain('$')
|
|
})
|
|
|
|
it('formats EUR amounts with the euro symbol and thousands separator', () => {
|
|
const formatted = formatCurrencyAmount(2000, 'EUR')
|
|
expect(formatted).toContain('€')
|
|
expect(formatted).toMatch(/2[.,]000/)
|
|
})
|
|
|
|
it('falls back to code + amount for a malformed currency code', () => {
|
|
// A non-3-letter code makes Intl.NumberFormat throw, exercising the fallback.
|
|
expect(formatCurrencyAmount(9.5, 'ZZ')).toBe('ZZ 9.50')
|
|
})
|
|
|
|
it('defaults blank currency codes to USD', () => {
|
|
expect(formatCurrencyAmount(1, ' ')).toContain('$')
|
|
})
|
|
|
|
it('treats non-finite amounts as zero', () => {
|
|
expect(formatCurrencyAmount(Number.NaN, 'USD')).toMatch(/0[.,]00/)
|
|
})
|
|
})
|