import { describe, expect, it } from 'vitest'
import { presentVehicle, presentVehicleList } from './vehicle.presenter'

describe('vehicle.presenter edge normalization', () => {
  it('normalizes nullable and malformed location fields without leaking non-string values', () => {
    const result = presentVehicle({
      id: 'vehicle_1',
      pickupLocations: ['Casablanca', null, 123, 'Rabat'],
      allowDifferentDropoff: 0,
      dropoffLocations: ['Airport', false, undefined, 'Hotel'],
    })

    expect(result).toMatchObject({
      id: 'vehicle_1',
      pickupLocations: ['Casablanca', 'Rabat'],
      allowDifferentDropoff: false,
      dropoffLocations: ['Airport', 'Hotel'],
    })
  })

  it('preserves pagination metadata and does not normalize list rows twice behind the caller’s back', () => {
    const row = { id: 'vehicle_1', pickupLocations: ['Raw'], allowDifferentDropoff: true, dropoffLocations: [] }

    expect(presentVehicleList([row], { total: 1, page: 2, pageSize: 10, totalPages: 1 })).toEqual({
      data: [row],
      total: 1,
      page: 2,
      pageSize: 10,
      totalPages: 1,
    })
  })
})
