import { describe, it, expect, vi } from 'vitest'
import { GET } from './route'
import { NextRequest } from 'next/server'

vi.mock('@/lib/spots', () => ({ getSpotDetail: vi.fn() }))

import { getSpotDetail } from '@/lib/spots'

describe('GET /api/spots/[id]', () => {
  it('returns 404 when spot not found', async () => {
    vi.mocked(getSpotDetail).mockResolvedValue(null)
    const res = await GET(new NextRequest('http://localhost/api/spots/bad'), { params: { id: 'bad' } })
    expect(res.status).toBe(404)
  })

  it('returns 200 with spot when found', async () => {
    vi.mocked(getSpotDetail).mockResolvedValue({ id: 'spot-1', name: 'Miradouro' } as any)
    const res = await GET(new NextRequest('http://localhost/api/spots/spot-1'), { params: { id: 'spot-1' } })
    expect(res.status).toBe(200)
    const data = await res.json()
    expect(data.spot.name).toBe('Miradouro')
  })
})
