Files
accounted/lib/import/bank-file/__tests__/currency-summary.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

45 lines
1.4 KiB
TypeScript

import { describe, it, expect } from 'vitest'
import { summarizeByCurrency } from '../currency-summary'
import type { ParsedBankTransaction } from '../types'
function tx(overrides: Partial<ParsedBankTransaction>): ParsedBankTransaction {
return {
date: '2026-07-01',
description: 'Test',
amount: 0,
currency: 'SEK',
...overrides,
}
}
describe('summarizeByCurrency', () => {
it('groups income and expenses per currency instead of mixing them', () => {
const result = summarizeByCurrency([
tx({ amount: 2500, currency: 'USD' }),
tx({ amount: -100.5, currency: 'USD' }),
tx({ amount: 1000, currency: 'SEK' }),
tx({ amount: -250, currency: 'SEK' }),
tx({ amount: -30, currency: 'EUR' }),
])
expect(result).toEqual([
{ currency: 'EUR', total_income: 0, total_expenses: -30 },
{ currency: 'SEK', total_income: 1000, total_expenses: -250 },
{ currency: 'USD', total_income: 2500, total_expenses: -100.5 },
])
})
it('defaults a missing currency to SEK and rounds to ore', () => {
const result = summarizeByCurrency([
tx({ amount: 0.105, currency: '' }),
tx({ amount: 0.105, currency: '' }),
])
expect(result).toEqual([{ currency: 'SEK', total_income: 0.21, total_expenses: 0 }])
})
it('returns an empty list for no transactions', () => {
expect(summarizeByCurrency([])).toEqual([])
})
})