Fix: Kaufdatum-Validierung für Fahrrad-Erstellung

- Kaufdatum akzeptiert jetzt YYYY-MM-DD Format (HTML date input)
- Unterstützung für ISO datetime Format und Date-Objekte
- Transform konvertiert Datumsstrings automatisch zu Date-Objekten
- API-Routes verwenden validierte Daten direkt ohne weitere Konvertierung
- Erweiterte Testfälle für verschiedene Datumsformate hinzugefügt
- Test-Schema aktualisiert, um echte Validierung zu reflektieren
This commit is contained in:
Denis Urs Rudolph
2025-12-05 22:25:07 +01:00
parent b525c07ccc
commit 0d06151603
5 changed files with 148 additions and 7 deletions

View File

@@ -93,6 +93,50 @@ describe('Bikes API', () => {
expect(bike.name).toBe('My Test Bike')
})
it('should create bike with purchaseDate in YYYY-MM-DD format', async () => {
const bikeData = {
name: 'Bike with Date',
purchaseDate: new Date('2024-01-15T00:00:00.000Z'),
}
const bike = await prisma.bike.create({
data: bikeData,
})
expect(bike).toBeDefined()
expect(bike.purchaseDate).toBeInstanceOf(Date)
expect(bike.purchaseDate?.toISOString().split('T')[0]).toBe('2024-01-15')
})
it('should create bike with purchaseDate', async () => {
const purchaseDate = new Date('2024-03-20')
const bikeData = {
name: 'Bike with Purchase Date',
purchaseDate: purchaseDate,
}
const bike = await prisma.bike.create({
data: bikeData,
})
expect(bike).toBeDefined()
expect(bike.purchaseDate).toBeInstanceOf(Date)
expect(bike.purchaseDate?.getTime()).toBe(purchaseDate.getTime())
})
it('should create bike without purchaseDate', async () => {
const bikeData = {
name: 'Bike without Date',
}
const bike = await prisma.bike.create({
data: bikeData,
})
expect(bike).toBeDefined()
expect(bike.purchaseDate).toBeNull()
})
})
describe('GET /api/bikes', () => {