import { describe, expect, it } from 'vitest' import { additionalDriverSchema, approvalSchema, createSchema, extendSchema, inspectionParamSchema, inspectionSchema, listQuerySchema, updateSchema } from './reservation.schemas' describe('reservation schemas edge cases', () => { it('defaults reservation creation arrays and deposit while requiring cuid identifiers', () => { const parsed = createSchema.parse({ vehicleId: 'ckvvehicle000000000000001', customerId: 'ckvcustomer00000000000001', startDate: '2026-07-01T10:00:00.000Z', endDate: '2026-07-03T10:00:00.000Z', }) expect(parsed.depositAmount).toBe(0) expect(parsed.selectedInsurancePolicyIds).toEqual([]) expect(parsed.additionalDrivers).toEqual([]) expect(createSchema.safeParse({ ...parsed, vehicleId: 'vehicle_1' }).success).toBe(false) }) it('validates additional drivers and inspection damage defaults', () => { expect(additionalDriverSchema.parse({ firstName: 'A', lastName: 'B', driverLicense: 'DL-1' })).toMatchObject({ driverLicense: 'DL-1' }) expect(additionalDriverSchema.safeParse({ firstName: '', lastName: 'B', driverLicense: 'DL-1' }).success).toBe(false) expect(additionalDriverSchema.safeParse({ firstName: 'A', lastName: 'B', driverLicense: 'DL-1', licenseExpiry: 'tomorrow' }).success).toBe(false) const parsed = inspectionSchema.parse({ fuelLevel: 'FULL', damagePoints: [{ viewType: 'FRONT', x: 12.5, y: 42, damageType: 'SCRATCH' }], }) expect(parsed.customerAgreed).toBe(false) expect(parsed.damagePoints[0]).toMatchObject({ severity: 'MINOR', isPreExisting: false }) expect(inspectionSchema.safeParse({ fuelLevel: 'OVERFLOWING_WITH_OPTIMISM' }).success).toBe(false) }) it('coerces list pagination and rejects unsafe update/extension payloads', () => { expect(listQuerySchema.parse({ page: '3', pageSize: '50', status: 'CONFIRMED' })).toMatchObject({ page: 3, pageSize: 50 }) expect(listQuerySchema.parse({})).toMatchObject({ page: 1, pageSize: 20 }) expect(listQuerySchema.safeParse({ pageSize: 101 }).success).toBe(false) expect(updateSchema.safeParse({ depositAmount: -1 }).success).toBe(false) expect(extendSchema.safeParse({ newEndDate: '2026-07-05T10:00:00.000Z', reason: '' }).success).toBe(false) expect(approvalSchema.parse({ approved: true })).toEqual({ approved: true }) expect(inspectionParamSchema.parse({ id: 'reservation_1', type: 'CHECKIN' })).toEqual({ id: 'reservation_1', type: 'CHECKIN' }) }) })