import { describe, expect, it } from 'vitest' import { carplaceReservationSchema, paginationSchema, reviewBodySchema, searchSchema } from './carplace.schemas' describe('carplace.schemas', () => { it('coerces pagination and caps untrusted public page sizes', () => { expect(paginationSchema.parse({ page: '2', pageSize: '40' })).toEqual({ page: 2, pageSize: 40 }) expect(paginationSchema.parse({})).toEqual({ page: 1, pageSize: 20 }) expect(() => paginationSchema.parse({ pageSize: '500' })).toThrow() }) it('trims search filters and coerces maxPrice', () => { expect(searchSchema.parse({ city: ' Rabat ', maxPrice: '500', dropoffMode: 'different' })).toEqual({ city: 'Rabat', maxPrice: 500, dropoffMode: 'different', }) expect(() => searchSchema.parse({ dropoffMode: 'teleport' })).toThrow() expect(() => searchSchema.parse({ maxPrice: '-1' })).toThrow() }) it('defaults carplace reservation language while keeping date and email validation strict', () => { const parsed = carplaceReservationSchema.parse({ vehicleId: 'ckvvehicle000000000000001', companySlug: 'atlas-cars', firstName: 'Aya', lastName: 'Benali', email: 'aya@example.com', startDate: '2026-07-01T10:00:00.000Z', endDate: '2026-07-03T10:00:00.000Z', }) expect(parsed.language).toBe('fr') expect(() => carplaceReservationSchema.parse({ ...parsed, email: 'bad-email' })).toThrow() expect(() => carplaceReservationSchema.parse({ ...parsed, startDate: '2026-07-01' })).toThrow() }) it('validates review ratings as bounded integers', () => { expect(reviewBodySchema.parse({ overallRating: 5, comment: 'Clean car' })).toEqual({ overallRating: 5, comment: 'Clean car' }) expect(() => reviewBodySchema.parse({ overallRating: 6 })).toThrow() expect(() => reviewBodySchema.parse({ overallRating: 4.5 })).toThrow() }) })