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

36 lines
1.2 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { createSchema, updateSchema, listQuerySchema } from './complaint.schemas'
describe('complaint schemas', () => {
it('defaults new complaints to the lowest severity when not provided', () => {
expect(createSchema.parse({ category: 'BILLING', subject: 'Incorrect invoice' })).toMatchObject({
category: 'BILLING',
subject: 'Incorrect invoice',
severity: 'LEVEL_1',
})
})
it('rejects empty complaint subjects', () => {
expect(() => createSchema.parse({ category: 'BILLING', subject: '' })).toThrow()
})
it('accepts lifecycle updates without requiring immutable creation fields', () => {
expect(updateSchema.parse({ status: 'RESOLVED', resolution: 'Refund issued' })).toEqual({
status: 'RESOLVED',
resolution: 'Refund issued',
})
})
it('coerces pagination and applies default page size for list queries', () => {
expect(listQuerySchema.parse({ page: '2', severity: 'LEVEL_3' })).toEqual({
page: 2,
pageSize: 20,
severity: 'LEVEL_3',
})
})
it('rejects pathological page sizes before they hit the database', () => {
expect(() => listQuerySchema.parse({ pageSize: '101' })).toThrow()
})
})