import { describe, it, expect } from 'bun:test'
import { normalizeStateCode, isValidStateCode } from '../../src/utils/states.js'

describe('normalizeStateCode', () => {
  it('normalizes two-letter codes', () => {
    expect(normalizeStateCode('tx')).toBe('TX')
    expect(normalizeStateCode('TX')).toBe('TX')
    expect(normalizeStateCode('Tx')).toBe('TX')
    expect(normalizeStateCode(' ca ')).toBe('CA')
  })

  it('normalizes full state names', () => {
    expect(normalizeStateCode('Texas')).toBe('TX')
    expect(normalizeStateCode('texas')).toBe('TX')
    expect(normalizeStateCode('CALIFORNIA')).toBe('CA')
    expect(normalizeStateCode('New York')).toBe('NY')
    expect(normalizeStateCode('north carolina')).toBe('NC')
  })

  it('returns null for invalid input', () => {
    expect(normalizeStateCode('ZZ')).toBeNull()
    expect(normalizeStateCode('Narnia')).toBeNull()
    expect(normalizeStateCode('')).toBeNull()
  })

  it('handles territories', () => {
    expect(normalizeStateCode('DC')).toBe('DC')
    expect(normalizeStateCode('Puerto Rico')).toBe('PR')
    expect(normalizeStateCode('GU')).toBe('GU')
  })
})

describe('isValidStateCode', () => {
  it('returns true for valid codes', () => {
    expect(isValidStateCode('TX')).toBe(true)
    expect(isValidStateCode('ca')).toBe(true)
  })

  it('returns false for invalid codes', () => {
    expect(isValidStateCode('ZZ')).toBe(false)
    expect(isValidStateCode('Texas')).toBe(false)
  })
})
