import { describe, it, expect } from 'vitest'
import { formatCents, formatCurrency } from './format'

describe('format utilities', () => {
    describe('formatCurrency', () => {
        it('should format number to comma-separated string', () => {
            expect(formatCurrency(10.00)).toBe('10,00')
            expect(formatCurrency(15.99)).toBe('15,99')
            expect(formatCurrency(1000.50)).toBe('1000,50')
        })

        it('should handle zero', () => {
            expect(formatCurrency(0)).toBe('0,00')
        })

        it('should handle undefined/null', () => {
            expect(formatCurrency(undefined)).toBe('0,00')
            expect(formatCurrency(null)).toBe('0,00')
        })

        it('should handle NaN', () => {
            expect(formatCurrency(NaN)).toBe('0,00')
        })
    })

    describe('formatCents', () => {
        it('should format cents to BRL currency', () => {
            expect(formatCents(1000)).toBe('R$ 10,00')
            expect(formatCents(1599)).toBe('R$ 15,99')
            expect(formatCents(100000)).toBe('R$ 1000,00')
        })

        it('should handle zero', () => {
            expect(formatCents(0)).toBe('R$ 0,00')
        })

        it('should handle undefined/null', () => {
            expect(formatCents(undefined)).toBe('R$ 0,00')
            expect(formatCents(null)).toBe('R$ 0,00')
        })

        it('should handle NaN', () => {
            expect(formatCents(NaN)).toBe('R$ 0,00')
        })

        it('should handle small amounts', () => {
            expect(formatCents(50)).toBe('R$ 0,50')
            expect(formatCents(1)).toBe('R$ 0,01')
        })
    })
})
