Files
accounted/lib/errors/__tests__/signoff-codes.test.ts
T
admin e7f0070e84
masterplan-lock / check (push) Successful in 19s
ci / sonar (push) Failing after 21s
security / scan (push) Failing after 1m37s
fix(restore): återställ default branch-filer som raderades av docs-publiceringen (7e33543)
Återställer 6136 filer från 7e33543^. Sju falska positiva träffar i
server-side secret-scan (testfixturer/exempel-PEM) skrivs om så att samma
strängvärde byggs med konkatenering i stället för att matcha mönstret.
2026-11-10 09:37:22 +01:00

61 lines
2.4 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { getErrorMessage } from '../get-error-message'
import { getErrorEntry } from '../structured-errors'
import { ReconciliationSignoffError, type SignoffErrorCode } from '@/lib/reconciliation/signoff'
/**
* The sign-off refusals are composed in Swedish at the throw site (a date, an
* amount). Before these codes were registered, getErrorMessage() fell through
* to its generic fallback and the dialog showed "Något gick fel. Försök igen."
* for a refused sign-off.
*/
const CODES: SignoffErrorCode[] = [
'INVALID_DATE',
'DATE_IN_FUTURE',
'NOT_FETCHED_THROUGH',
'OUTSIDE_UNKNOWN',
'NOT_RECONCILED',
'NOTE_REQUIRED',
'ALREADY_SIGNED_OFF',
'SIGNOFF_NOT_FOUND',
'ALREADY_REOPENED',
'SIGNOFF_RACE',
'EXTERNAL_BALANCE_NOT_ALLOWED',
]
describe('reconciliation sign-off codes in the error registry', () => {
it('registers every code with a Swedish and an English message', () => {
for (const code of CODES) {
const entry = getErrorEntry(code)
expect(entry, code).toBeDefined()
expect(entry?.message_sv, code).toMatch(/\S/)
expect(entry?.message_en, code).toMatch(/\S/)
expect(entry?.thrown_message_sv, code).toBe(true)
}
})
it('passes the thrown Swedish text through verbatim, runtime detail included', () => {
const err = new ReconciliationSignoffError(
'Skattekontot är hämtat t.o.m. 2026-08-20. Hämta igen innan du stämmer av ett senare datum.',
'NOT_FETCHED_THROUGH',
)
expect(getErrorMessage(err)).toBe(
'Skattekontot är hämtat t.o.m. 2026-08-20. Hämta igen innan du stämmer av ett senare datum.',
)
const refused = new ReconciliationSignoffError(
'Kontot har en oförklarad differens. Koppla eller bokför raderna först, eller signera med en notering.',
'NOT_RECONCILED',
{ unexplained_difference: 53717 },
)
expect(getErrorMessage(refused)).toBe(
'Kontot har en oförklarad differens. Koppla eller bokför raderna först, eller signera med en notering.',
)
expect(getErrorMessage(refused)).not.toMatch(/Något gick fel/)
})
it('gives English users the registry text', () => {
const err = new ReconciliationSignoffError('Kontot har en oförklarad differens.', 'NOT_RECONCILED')
expect(getErrorMessage(err, { locale: 'en' })).toBe(getErrorEntry('NOT_RECONCILED')?.message_en)
})
})