import { describe, expect, it } from 'vitest' import { entrySchema, fieldForError } from './schema' const schema = entrySchema('2026-12-01', '2026-12-31') const ok = { amount: '1.250,50', group: 'needs', category_id: 'c1', payment_method_id: '', date: '2026-12-31', description: '', } const errorsOf = (v: object) => schema.safeParse({ ...ok, ...v }).error?.issues.map((i) => [i.path[0], i.message]) ?? [] describe('entry form', () => { it('accepts a valid entry', () => { expect(schema.safeParse(ok).success).toBe(true) }) it('rejects missing and out-of-range values with Turkish messages', () => { expect(errorsOf({ amount: '' })).toEqual([['amount', 'Tutarı yazın']]) expect(errorsOf({ amount: '0' })).toEqual([['amount', 'Tutar sıfırdan büyük olmalı']]) expect(errorsOf({ group: '' })).toEqual([['group', 'Ana grubu seçin']]) expect(errorsOf({ category_id: '' })).toEqual([['category_id', 'Kategori seçin']]) expect(errorsOf({ date: '2027-01-01' })).toEqual([['date', 'Tarih dönem içinde olmalı']]) expect(errorsOf({ date: '' })).toEqual([['date', 'Tarih geçersiz']]) }) it('counts description characters like the backend', () => { expect(errorsOf({ description: '🛒'.repeat(200) })).toEqual([]) expect(errorsOf({ description: 'a'.repeat(201) })[0][0]).toBe('description') }) it('maps server messages to fields', () => { expect(fieldForError('Tarih dönem içinde olmalı')).toBe('date') expect(fieldForError('Bu kategori pasif; başka bir kategori seçin')).toBe('category_id') expect(fieldForError('Bu ödeme türü pasif; başka birini seçin')).toBe('payment_method_id') expect(fieldForError('Bağlantı kurulamadı')).toBe('root') }) })