Files
accounted/lib/bokslut/__tests__/rantefordelning-calculator.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

35 lines
1.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { describe, it, expect } from 'vitest'
import { calculateRantefordelning, NEGATIVE_THRESHOLD } from '../enskild-firma/rantefordelning-calculator'
describe('calculateRantefordelning', () => {
it('positive: SLR+6 pe × kapitalunderlag', () => {
// SLR 2025-11-30 = 2.55 %, +6 = 8.55 %. 1 000 000 × 0.0855 = 85 500
const r = calculateRantefordelning({ kapitalunderlag: 1_000_000 })
expect(r).not.toBeNull()
expect(r!.kind).toBe('rantefordelning_positive')
expect(r!.amount).toBe(85_500)
})
it('returns null between 0 and the -500 000 negative threshold', () => {
expect(calculateRantefordelning({ kapitalunderlag: 0 })).toBeNull()
expect(calculateRantefordelning({ kapitalunderlag: -100_000 })).toBeNull()
expect(calculateRantefordelning({ kapitalunderlag: NEGATIVE_THRESHOLD })).toBeNull()
})
it('negative: SLR+1 pe × |kapitalunderlag| when under -500 000', () => {
// -600 000 < -500 000. 600 000 × (0.0255 + 0.01) = 21 300
const r = calculateRantefordelning({ kapitalunderlag: -600_000 })
expect(r).not.toBeNull()
expect(r!.kind).toBe('rantefordelning_negative')
expect(r!.amount).toBe(21_300)
expect(r!.warnings[0]).toContain('-500 000')
})
it('honors a custom SLR rate', () => {
// For inkomstår 2025: SLR = 1.96 %. Positive at +6 = 7.96 %. On 100 000 = 7 960
const r = calculateRantefordelning({ kapitalunderlag: 100_000, slrRate: 0.0196 })
expect(r).not.toBeNull()
expect(r!.amount).toBe(7_960)
})
})