Files
accounted/scripts/__tests__/import-tax-tables.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

41 lines
1.5 KiB
TypeScript

import { describe, it, expect } from 'vitest'
import { parseLine } from '../import-tax-tables'
// Build a fixed-width SKV 434 record: prefix(5) income_from(7) income_to(7)
// then six 5-char columns = 49 chars.
function record(prefix: string, from: string, to: string, cols: string[] = ['100', '200', '300', '400', '500', '600']): string {
return prefix + from.padStart(7) + to.padStart(7) + cols.map((c) => c.padStart(5)).join('')
}
describe('parseLine', () => {
it('parses a monthly B-row', () => {
const parsed = parseLine(record('30B29', '20001', '20200'))
expect(parsed).toEqual({
table: 29,
row: [20001, 20200, 100, 200, 300, 400, 500, 600, 0],
})
})
it('parses a monthly percent row with a blank open-ended upper bound', () => {
const parsed = parseLine(record('30%29', '80001', '', ['32', '30', '32', '28', '33', '34']))
expect(parsed).toEqual({
table: 29,
row: [80001, 0, 32, 30, 32, 28, 33, 34, 1],
})
})
it('throws loudly on a two-week 14B row instead of merging it into monthly data', () => {
expect(() => parseLine(record('14B29', '20001', '20200'))).toThrow(/Two-week table row/)
expect(() => parseLine(record('14%29', '80001', ''))).toThrow(/Two-week table row/)
})
it('skips rows with an unknown day-count prefix', () => {
expect(parseLine(record('90B29', '20001', '20200'))).toBeNull()
})
it('skips non-table lines (headers, short lines)', () => {
expect(parseLine('RUBRIK ALLMANNA TABELLER 2026')).toBeNull()
expect(parseLine('')).toBeNull()
})
})