import { describe, it, expect, beforeEach } from 'vitest'
import { getCookie, setCookie } from '../cookie'

describe('cookie utils', () => {
  beforeEach(() => {
    document.cookie.split(';').forEach(c => {
      document.cookie = c.replace(/^ +/, '').replace(/=.*/, '=;expires=Thu, 01 Jan 1970 00:00:00 GMT;path=/')
    })
  })

  it('getCookie returns null for missing cookie', () => {
    expect(getCookie('nonexistent')).toBeNull()
  })

  it('setCookie + getCookie roundtrip', () => {
    setCookie('test-key', 'test-value')
    expect(getCookie('test-key')).toBe('test-value')
  })

  it('handles encoded values', () => {
    setCookie('encoded', 'hello world')
    expect(getCookie('encoded')).toBe('hello world')
  })
})
