Files
accounted/lib/company/__tests__/connection-iban.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

68 lines
2.0 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import { formatIbanGroups, uniqueConnectionIban } from '../connection-iban'
const IBAN_A = 'SE3550000000054910000003'
const IBAN_B = 'SE4550000000058398257466'
describe('uniqueConnectionIban', () => {
it('returns null for non-array input', () => {
expect(uniqueConnectionIban(null)).toBeNull()
expect(uniqueConnectionIban(undefined)).toBeNull()
expect(uniqueConnectionIban('rows')).toBeNull()
expect(uniqueConnectionIban({ iban: IBAN_A })).toBeNull()
})
it('returns null for an empty result', () => {
expect(uniqueConnectionIban([])).toBeNull()
})
it('returns the IBAN when exactly one account carries one', () => {
expect(uniqueConnectionIban([{ iban: IBAN_A }])).toBe(IBAN_A)
})
it('normalises spacing and case', () => {
expect(uniqueConnectionIban([{ iban: 'se35 5000 0000 0549 1000 0003' }])).toBe(IBAN_A)
})
it('treats the same IBAN across several accounts as one', () => {
expect(
uniqueConnectionIban([
{ iban: IBAN_A },
{ iban: 'SE35 5000 0000 0549 1000 0003' },
]),
).toBe(IBAN_A)
})
it('returns null when accounts disagree: no guessing between banks', () => {
expect(uniqueConnectionIban([{ iban: IBAN_A }, { iban: IBAN_B }])).toBeNull()
})
it('skips rows without a usable IBAN', () => {
expect(
uniqueConnectionIban([
null,
'not-a-row',
{ iban: null },
{ iban: 42 },
{ iban: 'NOT-AN-IBAN' },
{ iban: IBAN_A },
]),
).toBe(IBAN_A)
})
it('returns null when only invalid IBANs exist', () => {
expect(uniqueConnectionIban([{ iban: 'SE12' }, { iban: '' }])).toBeNull()
})
})
describe('formatIbanGroups', () => {
it('groups the IBAN in blocks of four', () => {
expect(formatIbanGroups(IBAN_A)).toBe('SE35 5000 0000 0549 1000 0003')
})
it('leaves a trailing partial group intact', () => {
expect(formatIbanGroups('SE355000')).toBe('SE35 5000')
expect(formatIbanGroups('SE3550001')).toBe('SE35 5000 1')
})
})