Files
accounted/extensions/ne-bilaga/__tests__/ne-engine.test.ts
T
Jakob WennbergandClaude Opus 4.6 acb85edf4a feat: wire Zod validation into API routes, improve types and components
- Add 8 new Zod schemas (UpdateCustomer, UpdateSupplier, UpdateSupplierInvoice,
  UpdateAccount, BankUnlink, RunReconciliation, CorrectJournalEntry,
  EvaluateMappingRules) and wire validateBody() into 24 JSON-body API routes
- Remove redundant manual validation checks replaced by Zod
- Add comprehensive schema tests (222 tests)
- Improve type definitions in types/index.ts with expanded interfaces
- Refactor extension types (push-notifications, receipt-ocr) for cleaner imports
- Update transaction components (BatchCategorySelector, SwipeCategorizationView,
  QuickReviewDialog, VatTreatmentSelect) and invoice inbox workspace
- Add invoice-inbox utilities and type decoupling tests
- Fix NE-bilaga, SRU export, and invoice PDF template type usage
- Update CLAUDE.md with expanded architecture documentation

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-02-23 16:00:38 +01:00

123 lines
3.5 KiB
TypeScript

import { describe, it, expect } from 'vitest'
import { NE_ACCOUNT_MAPPINGS } from '../ne-engine'
import type { NEAccountMapping } from '@/extensions/ne-bilaga/types'
/**
* Helper to check if an account falls into a specific ruta
*/
function findRutaForAccount(accountNumber: string): string | null {
for (const mapping of NE_ACCOUNT_MAPPINGS) {
for (const range of mapping.accountRanges) {
if (accountNumber >= range.start && accountNumber <= range.end) {
if (range.exclude && range.exclude.includes(accountNumber)) {
continue
}
return mapping.ruta
}
}
}
return null
}
describe('NE Account Mappings', () => {
describe('R1 - Försäljning med moms', () => {
it('includes standard revenue accounts 3001-3003', () => {
expect(findRutaForAccount('3001')).toBe('R1')
expect(findRutaForAccount('3002')).toBe('R1')
expect(findRutaForAccount('3003')).toBe('R1')
})
it('excludes 3100 (momsfria intäkter)', () => {
expect(findRutaForAccount('3100')).not.toBe('R1')
})
it('includes 3500 (Fakturerade kostnader)', () => {
expect(findRutaForAccount('3500')).toBe('R1')
})
it('includes 3500-3599 range', () => {
expect(findRutaForAccount('3510')).toBe('R1')
expect(findRutaForAccount('3599')).toBe('R1')
})
it('includes 3700-3799 (Lämnade rabatter)', () => {
expect(findRutaForAccount('3700')).toBe('R1')
expect(findRutaForAccount('3731')).toBe('R1')
expect(findRutaForAccount('3799')).toBe('R1')
})
})
describe('R2 - Momsfria intäkter', () => {
it('includes 3100', () => {
expect(findRutaForAccount('3100')).toBe('R2')
})
it('includes 3900 (Övriga rörelseintäkter)', () => {
expect(findRutaForAccount('3900')).toBe('R2')
})
it('includes 3910 (Hyresintäkter)', () => {
expect(findRutaForAccount('3910')).toBe('R2')
})
it('includes 3920 (Provisionsintäkter)', () => {
expect(findRutaForAccount('3920')).toBe('R2')
})
it('includes 3950 (Återvunna kundfordringar)', () => {
expect(findRutaForAccount('3950')).toBe('R2')
})
it('includes 3960 (Valutakursvinster)', () => {
expect(findRutaForAccount('3960')).toBe('R2')
})
it('includes 3970-3980 range', () => {
expect(findRutaForAccount('3970')).toBe('R2')
expect(findRutaForAccount('3980')).toBe('R2')
})
it('includes 3981-3999 range', () => {
expect(findRutaForAccount('3981')).toBe('R2')
expect(findRutaForAccount('3990')).toBe('R2')
expect(findRutaForAccount('3999')).toBe('R2')
})
})
describe('accounts are not silently dropped', () => {
it('3500 is mapped (not dropped)', () => {
expect(findRutaForAccount('3500')).not.toBeNull()
})
it('3700 is mapped (not dropped)', () => {
expect(findRutaForAccount('3700')).not.toBeNull()
})
it('3910 is mapped (not dropped)', () => {
expect(findRutaForAccount('3910')).not.toBeNull()
})
it('3960 is mapped (not dropped)', () => {
expect(findRutaForAccount('3960')).not.toBeNull()
})
it('3990 is mapped (not dropped)', () => {
expect(findRutaForAccount('3990')).not.toBeNull()
})
})
describe('no overlap between R1 and R2', () => {
it('3100 is in R2 not R1', () => {
expect(findRutaForAccount('3100')).toBe('R2')
})
it('3001 is in R1 not R2', () => {
expect(findRutaForAccount('3001')).toBe('R1')
})
it('3900 is in R2 not R1', () => {
expect(findRutaForAccount('3900')).toBe('R2')
})
})
})