import { describe, expect, it } from 'vitest'
import type { Request } from 'express'
import { z } from 'zod'
import { parseBody, parseParams, parseQuery } from './index'

describe('http/validate parsers', () => {
  it('parseBody returns typed and coerced request body values', () => {
    const schema = z.object({ seats: z.coerce.number().int().min(1), brand: z.string().min(1) })
    const req = { body: { seats: '5', brand: 'Toyota' } } as Request

    expect(parseBody(schema, req)).toEqual({ seats: 5, brand: 'Toyota' })
  })

  it('parseQuery validates query values and throws ZodError for invalid input', () => {
    const schema = z.object({ page: z.coerce.number().int().positive() })
    const req = { query: { page: '0' } } as unknown as Request

    expect(() => parseQuery(schema, req)).toThrow('Number must be greater than 0')
  })

  it('parseParams returns validated path parameters', () => {
    const schema = z.object({ vehicleId: z.string().min(1) })
    const req = { params: { vehicleId: 'veh_123' } } as unknown as Request

    expect(parseParams(schema, req)).toEqual({ vehicleId: 'veh_123' })
  })
})
