Files
carmanagement/apps/api/src/modules/notifications/notification.schemas.edge.test.ts
T
root f6fcd7ce54
Build & Push / Pipeline Tests (push) Failing after 1m8s
Build & Push / Build & Push Docker Image (push) Has been skipped
Test / Type Check (all packages) (push) Successful in 53s
Test / API Unit Tests (push) Failing after 52s
Test / Homepage Unit Tests (push) Successful in 46s
Test / Carplace Unit Tests (push) Successful in 43s
Test / Admin Unit Tests (push) Successful in 43s
Test / Dashboard Unit Tests (push) Successful in 46s
Test / API Integration Tests (push) Successful in 1m7s
fix notifications
2026-07-22 22:31:39 -04:00

30 lines
1.5 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { historyQuerySchema, idParamSchema, preferencesSchema, unreadQuerySchema } from './notification.schemas'
describe('notification schema contracts', () => {
it('requires complete preference entries', () => {
expect(preferencesSchema.parse([{ notificationType: 'NEW_BOOKING', channel: 'EMAIL', enabled: true }])).toEqual([
{ notificationType: 'NEW_BOOKING', channel: 'EMAIL', enabled: true },
])
expect(() => preferencesSchema.parse([{ notificationType: 'NEW_BOOKING', channel: 'EMAIL' }])).toThrow()
expect(() => preferencesSchema.parse([{ notificationType: 'RESERVATION_CREATED', channel: 'EMAIL', enabled: true }])).toThrow()
expect(() => preferencesSchema.parse([{ notificationType: 'NEW_BOOKING', channel: 'PUSH', enabled: true }])).toThrow()
})
it('coerces history limits and caps bulk history requests', () => {
expect(historyQuerySchema.parse({ channel: 'EMAIL', status: 'SENT', limit: '25' })).toEqual({
channel: 'EMAIL',
status: 'SENT',
limit: 25,
})
expect(() => historyQuerySchema.parse({ limit: '0' })).toThrow()
expect(() => historyQuerySchema.parse({ limit: '501' })).toThrow()
})
it('accepts unread query passthrough but rejects empty ids', () => {
expect(unreadQuerySchema.parse({ unread: 'true' })).toEqual({ unread: 'true' })
expect(idParamSchema.parse({ id: 'notification_1' })).toEqual({ id: 'notification_1' })
expect(() => idParamSchema.parse({ id: '' })).toThrow()
})
})