Files
accounted/components/bookkeeping/__tests__/correction-entry-description.test.ts
T
Jakob Wennberg 6bd85f94b6 fix(bookkeeping): editable verifikationstext on andringsverifikation (#1035)
The correction header was always built server-side as
"Rattelse: <original description>". When the original entry was labelled
after the wrong account, the correction kept echoing that stale label even
after the user switched to the correct account (follow-up to the
line-description fix in #1029).

- CorrectJournalEntrySchema gains an optional trimmed description
- correctEntry() accepts options.description; blank or absent falls back
  to the canonical "Rattelse: <original>" auto text
- both correct routes (dashboard + v1, which share the schema) thread the
  description through
- CorrectionEntryDialog surfaces an editable verifikationstext field,
  pre-filled with the auto text; an untouched or cleared prefill is NOT
  sent, so the server-side fallback stays the source of truth (same
  only-overwrite-auto-filled principle as #1029)

Forward-only: already-posted corrections are immutable per BFL.

Fixes #1031

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-07-16 18:14:02 +02:00

41 lines
1.6 KiB
TypeScript

import { describe, it, expect } from 'vitest'
import {
autoCorrectionDescription,
correctionDescriptionForSubmit,
} from '@/components/bookkeeping/correction-entry-description'
const ORIGINAL = 'Lån från närstående personer, långfristig del'
describe('autoCorrectionDescription', () => {
it('matches the server-side fallback format', () => {
expect(autoCorrectionDescription(ORIGINAL)).toBe(`Rättelse: ${ORIGINAL}`)
})
})
describe('correctionDescriptionForSubmit', () => {
it('sends nothing when the field still equals the auto prefill', () => {
expect(correctionDescriptionForSubmit(`Rättelse: ${ORIGINAL}`, ORIGINAL)).toBeUndefined()
})
it('sends nothing when the prefill only gained surrounding whitespace', () => {
expect(correctionDescriptionForSubmit(` Rättelse: ${ORIGINAL} `, ORIGINAL)).toBeUndefined()
})
it('sends nothing when the field was cleared (server fallback applies)', () => {
expect(correctionDescriptionForSubmit('', ORIGINAL)).toBeUndefined()
expect(correctionDescriptionForSubmit(' ', ORIGINAL)).toBeUndefined()
})
it('sends a user-edited description (the reported bug: relabel after account change)', () => {
expect(
correctionDescriptionForSubmit('Rättelse: Skulder till närstående personer, kortfristig del', ORIGINAL),
).toBe('Rättelse: Skulder till närstående personer, kortfristig del')
})
it('trims a user-edited description before sending', () => {
expect(correctionDescriptionForSubmit(' Omföring till rätt konto ', ORIGINAL)).toBe(
'Omföring till rätt konto',
)
})
})