Å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.
61 lines
3.0 KiB
TypeScript
61 lines
3.0 KiB
TypeScript
import { describe, it, expect } from 'vitest'
|
|
import { deriveTransactionLabel } from '../transaction-label'
|
|
|
|
describe('deriveTransactionLabel', () => {
|
|
it('prefers MCC over the ISO code (most specific signal)', () => {
|
|
expect(deriveTransactionLabel({ mcc: '6011' })).toBe('Uttag')
|
|
expect(deriveTransactionLabel({ mcc: 5411 })).toBe('Inköp dagligvaror')
|
|
// MCC wins even when a (different-meaning) bank code is also present.
|
|
expect(
|
|
deriveTransactionLabel({ mcc: '6011', bankTransactionCode: 'PMNT/CCRD' }),
|
|
).toBe('Uttag')
|
|
})
|
|
|
|
it('maps ISO 20022 Domain/Family codes', () => {
|
|
expect(deriveTransactionLabel({ bankTransactionCode: 'PMNT/RCDT' })).toBe('Inbetalning')
|
|
expect(deriveTransactionLabel({ bankTransactionCode: 'PMNT/ICDT' })).toBe('Betalning')
|
|
expect(deriveTransactionLabel({ bankTransactionCode: 'PMNT/CCRD' })).toBe('Kortköp')
|
|
expect(deriveTransactionLabel({ bankTransactionCode: 'PMNT/RDDT' })).toBe('Autogiro')
|
|
})
|
|
|
|
it('parses dash- and dot-separated three-part codes (Domain-Family-SubFamily)', () => {
|
|
expect(deriveTransactionLabel({ bankTransactionCode: 'PMNT-CCRD-POSD' })).toBe('Kortköp')
|
|
expect(deriveTransactionLabel({ bankTransactionCode: 'pmnt.rcdt.esct' })).toBe('Inbetalning')
|
|
})
|
|
|
|
it('falls back to a keyword scan for proprietary code strings', () => {
|
|
expect(
|
|
deriveTransactionLabel({ proprietaryBankTransactionCode: 'INTEREST PAYMENT' }),
|
|
).toBe('Ränta')
|
|
expect(
|
|
deriveTransactionLabel({ proprietaryBankTransactionCode: 'ACCOUNT FEE' }),
|
|
).toBe('Avgift')
|
|
expect(
|
|
deriveTransactionLabel({ proprietaryBankTransactionCode: 'ATM WITHDRAWAL' }),
|
|
).toBe('Uttag')
|
|
})
|
|
|
|
it('reads the combined Swedish channel wording "Kortköp/uttag" as a card purchase, not a withdrawal', () => {
|
|
// Enable Banking's flattened code description for ordinary card purchases
|
|
// at SEB/Swedbank. The card rule must win over the UTTAG keyword.
|
|
expect(deriveTransactionLabel({ bankTransactionCode: 'Kortköp/uttag' })).toBe('Kortköp')
|
|
expect(deriveTransactionLabel({ bankTransactionCode: 'Card purchase' })).toBe('Kortköp')
|
|
// A bare withdrawal wording still labels as Uttag.
|
|
expect(deriveTransactionLabel({ bankTransactionCode: 'ATM WITHDRAWAL' })).toBe('Uttag')
|
|
expect(deriveTransactionLabel({ bankTransactionCode: 'Uttag' })).toBe('Uttag')
|
|
})
|
|
|
|
it('uses the bare PMNT domain + direction as a last generic resort', () => {
|
|
expect(deriveTransactionLabel({ bankTransactionCode: 'PMNT', isCredit: true })).toBe('Inbetalning')
|
|
expect(deriveTransactionLabel({ bankTransactionCode: 'PMNT', isCredit: false })).toBe('Betalning')
|
|
})
|
|
|
|
it('returns null when nothing is recognized (caller falls through)', () => {
|
|
expect(deriveTransactionLabel({})).toBeNull()
|
|
expect(deriveTransactionLabel({ bankTransactionCode: 'ZZZZ/QQQQ' })).toBeNull()
|
|
expect(deriveTransactionLabel({ mcc: '0000' })).toBeNull()
|
|
// Bare unknown domain without isCredit cannot be classified.
|
|
expect(deriveTransactionLabel({ bankTransactionCode: 'PMNT' })).toBeNull()
|
|
})
|
|
})
|