Files
carmanagement/apps/api/src/modules/marketplace/marketplace.schemas.test.ts
T
2026-06-10 00:40:19 -04:00

43 lines
1.9 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { marketplaceReservationSchema, paginationSchema, reviewBodySchema, searchSchema } from './marketplace.schemas'
describe('marketplace.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 marketplace reservation language while keeping date and email validation strict', () => {
const parsed = marketplaceReservationSchema.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(() => marketplaceReservationSchema.parse({ ...parsed, email: 'bad-email' })).toThrow()
expect(() => marketplaceReservationSchema.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()
})
})