import request from 'supertest'
import { createApp } from '../../app'

const app = createApp()

describe('GET /health', () => {
  it('returns 200 with status ok', async () => {
    const res = await request(app).get('/health')
    expect(res.status).toBe(200)
    expect(res.body.status).toBe('ok')
    expect(res.body.version).toBe('1.0.0')
    expect(typeof res.body.timestamp).toBe('string')
  })

  it('GET /api/v1 returns the API entrypoint', async () => {
    const res = await request(app).get('/api/v1')
    expect(res.status).toBe(200)
    expect(res.body.name).toBe('rentaldrivego-api')
    expect(res.body.baseUrl).toBe('/api/v1')
    expect(res.body.docs).toBe('/api/v1/docs')
    expect(res.body.openApi).toBe('/api/v1/openapi.json')
  })

  it('GET /api/v1/docs returns route index', async () => {
    const res = await request(app).get('/api/v1/docs')
    expect(res.status).toBe(200)
    expect(res.body.name).toBe('rentaldrivego-api')
    expect(Array.isArray(res.body.routes)).toBe(true)
    expect(res.body.swaggerUi).toBe('/docs')
    expect(res.body.openApi).toBe('/api/v1/openapi.json')
  })

  it('GET /api/v1/openapi.json returns the OpenAPI document', async () => {
    const res = await request(app).get('/api/v1/openapi.json')
    expect(res.status).toBe(200)
    expect(res.body.openapi).toBe('3.0.3')
    expect(res.body.info?.title).toBe('RentalDriveGo API')
  })
})
