import {describe, expect, test} from 'bun:test'

import {parseCoordParams} from '@/lib/geo'

describe('parseCoordParams', () => {
  test('parses a finite pair', () => {
    expect(parseCoordParams('37.7749', '-122.4194')).toEqual({
      latitude: 37.7749,
      longitude: -122.4194,
    })
  })

  test('rejects a missing or empty param', () => {
    expect(parseCoordParams(undefined, '-122.4')).toBeNull()
    expect(parseCoordParams('37.7', undefined)).toBeNull()
    expect(parseCoordParams('', '-122.4')).toBeNull()
    expect(parseCoordParams('37.7', '')).toBeNull()
  })

  test('rejects non-numeric and non-finite values', () => {
    expect(parseCoordParams('abc', '-122.4')).toBeNull()
    expect(parseCoordParams('37.7', 'NaN')).toBeNull()
    expect(parseCoordParams('Infinity', '-122.4')).toBeNull()
  })
})
