import { test, type TestContext } from 'node:test' import { parseDim, parseIB, parseKonto, parseObjekt, parseRAR, parseSRU, parseVer, parseTrans, parseUB, } from './parse_line.ts' test('parseDim', (t: TestContext) => { const line = '#DIM 6 "Projekt"' const expected = { number: 6, name: 'Projekt', } t.assert.deepStrictEqual(parseDim(line), expected) }) test('parseIB', (t: TestContext) => { let line = '#IB 0 1790 11946.07 0' let expected = { accountNumber: 1790, yearNumber: 0, balance: 11946.07, quantity: 0, } t.assert.deepStrictEqual(parseIB(line), expected) line = '#IB 0 2083 -57106301 0' expected = { accountNumber: 2083, yearNumber: 0, balance: -57106301, quantity: 0, } t.assert.deepStrictEqual(parseIB(line), expected) line = '#IB 0 1111 -5710630.1 3' expected = { accountNumber: 1111, yearNumber: 0, balance: -5710630.1, quantity: 3, } t.assert.deepStrictEqual(parseIB(line), expected) }) test('parseKonto', (t: TestContext) => { const line = '#KONTO 1249 "Ack avskr bilar/transportmedel"' const expected = { number: 1249, description: 'Ack avskr bilar/transportmedel', } t.assert.deepStrictEqual(parseKonto(line), expected) }) test('parseObjekt', (t: TestContext) => { let line = '#OBJEKT 1 "3" "3"' let expected = { dimensionNumber: 1, number: 3, name: '3', } t.assert.deepStrictEqual(parseObjekt(line), expected) line = '#OBJEKT 6 "338" "338"' expected = { dimensionNumber: 6, number: 338, name: '338', } line = '#OBJEKT 6 "4" "Entreer"' expected = { dimensionNumber: 6, number: 4, name: 'Entreer', } }) test('parseRAR', (t: TestContext) => { let line = '#RAR 0 20160101 20161231' let expected = { yearNumber: 0, startDate: '20160101', endDate: '20161231', } t.assert.deepStrictEqual(parseRAR(line), expected) line = '#RAR -1 20150101 20151231' expected = { yearNumber: -1, startDate: '20150101', endDate: '20151231', } t.assert.deepStrictEqual(parseRAR(line), expected) }) test('parseSRU', (t: TestContext) => { const line = '#SRU 1240 7215' const expected = { number: 1240, sru: 7215, } t.assert.deepStrictEqual(parseSRU(line), expected) }) test('parseTrans', (t: TestContext) => { type Expected = { accountNumber: number objectList: [number, number][] | null amount: number transactionDate: string | null description: string | null quantity: number | null signature: null } // Fortnox 3.57.11 let line = '#TRANS 1790 {1 "1"} 7509 "" "Faktura 9631584500436 172-57 - Perspektiv Bredband AB" 0' let expected: Expected = { accountNumber: 1790, objectList: [[1, 1]], amount: 7509, transactionDate: null, description: 'Faktura 9631584500436 172-57 - Perspektiv Bredband AB', quantity: 0, signature: null, } t.assert.deepStrictEqual(parseTrans(line), expected) // Fortnox 3.57.11 line = '#TRANS 2351 {} -3140000 "" "" 0' expected = { accountNumber: 2351, objectList: null, amount: -3140000, transactionDate: null, description: null, quantity: 0, signature: null, } t.assert.deepStrictEqual(parseTrans(line), expected) // Edison Ekonomi ByrÄ 6.1 line = '#TRANS 6310 {} 9076.00 20160131 "jan - mars"' expected = { accountNumber: 6310, objectList: null, amount: 9076.0, transactionDate: '20160131', description: 'jan - mars', quantity: null, signature: null, } t.assert.deepStrictEqual(parseTrans(line), expected) line = '#TRANS 4341 {1 "1" 6 "338"} 25000 "" "Faktura 748 172-114 - Bredablick Fastighetspartner AB" 0' expected = { accountNumber: 4341, objectList: [ [1, 1], [6, 338], ], amount: 25000, transactionDate: null, description: 'Faktura 748 172-114 - Bredablick Fastighetspartner AB', quantity: 0, signature: null, } t.assert.deepStrictEqual(parseTrans(line), expected) // line = '#TRANS 7010 {"1" "456" "7" "47"} 13200.00' // expected = { // accountNumber: 7010, // objectList: [[1, 1], [6, 338]], // amount: 13200, // transactionDate: null, // description: null, // quantity: null, // signature: null, // } // t.assert.deepStrictEqual(parseTrans(line), expected) }) test('parseUB', (t: TestContext) => { let line = '#UB 0 1110 77246210 0' let expected = { accountNumber: 1110, yearNumber: 0, balance: 77246210, quantity: 0, } t.assert.deepStrictEqual(parseUB(line), expected) line = '#UB 0 1229 -37390.26 0' expected = { accountNumber: 1229, yearNumber: 0, balance: -37390.26, quantity: 0, } t.assert.deepStrictEqual(parseUB(line), expected) line = '#UB 0 1730 26327.8 0' expected = { yearNumber: 0, accountNumber: 1730, balance: 26327.8, quantity: 0, } t.assert.deepStrictEqual(parseUB(line), expected) }) test('parseVer', (t: TestContext) => { // #VER A 1 20151231 "BR/RR 2015" 20231213 const line = '#VER A 1 20151231 "BR/RR 2015" 20231213' const expected = { journal: 'A', number: 1, transactionDate: '20151231', description: 'BR/RR 2015', entryDate: '20231213', signature: null, } t.assert.deepStrictEqual(parseVer(line), expected) })