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:
@@ -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', () => {
|
||||
|
||||
Reference in New Issue
Block a user