UNPKG

@x47base/ch-finance-engine

Version:

This package is an finance and accounting engine specificly made based on the swiss system.

100 lines (92 loc) 3.9 kB
const { generateBuchungsaufgabe, verifySolution } = require('../src/utils/taskUtils'); const Engine = require('../src/models/engine'); jest.mock('../src/models/engine'); describe('generateBuchungsaufgabe', () => { let engine; beforeEach(() => { engine = new Engine(); engine.accounts = [ { code: 1000, name: 'Warenaufwand', type: 'Aufwand', aliases: [], balance: 0 }, { code: 2000, name: 'Verbindlichkeiten L+L', type: 'Passiv', aliases: [], balance: 0 }, { code: 3000, name: 'Vorsteuer 1170', type: 'Aktiv', aliases: [], balance: 0 }, ]; engine.performBuchung = jest.fn((txIdBase, accountSoll, accountHaben, amount, currency, description) => { const txSoll = { id: txIdBase, transactionSide: "Soll", accountCode: accountSoll, description, amount, currency, bookingType: "Buchung", status: "booked", toJSON: () => ({ id: txIdBase, transactionSide: "Soll", accountCode: accountSoll, description, amount, currency, bookingType: "Buchung", status: "booked" }) }; const txHaben = { id: txIdBase + 1, transactionSide: "Haben", accountCode: accountHaben, description, amount, currency, bookingType: "Buchung", status: "booked", toJSON: () => ({ id: txIdBase + 1, transactionSide: "Haben", accountCode: accountHaben, description, amount, currency, bookingType: "Buchung", status: "booked" }) }; return [txSoll, txHaben]; }); Engine.mockImplementation(() => engine); }); test('generates a task and solution', () => { const { task, solution } = generateBuchungsaufgabe(); expect(task).toHaveProperty('description'); expect(task).toHaveProperty('account1'); expect(task).toHaveProperty('account2'); expect(task).toHaveProperty('amount'); expect(task).toHaveProperty('currency', 'CHF'); expect(solution).toBeInstanceOf(Array); expect(solution.length).toBeGreaterThan(0); solution.forEach(tx => { expect(tx).toHaveProperty('id'); expect(tx).toHaveProperty('transactionSide'); expect(tx).toHaveProperty('accountCode'); expect(tx).toHaveProperty('description'); expect(tx).toHaveProperty('amount'); expect(tx).toHaveProperty('currency', 'CHF'); expect(tx).toHaveProperty('bookingType'); expect(tx).toHaveProperty('status'); }); }); test('verifies the solution correctly', () => { const { solution } = generateBuchungsaufgabe(); const result = verifySolution(solution, solution); expect(result.correct).toBe(true); expect(result.message).toBe("Alle Buchungen sind korrekt."); }); test('detects incorrect solution', () => { const { solution } = generateBuchungsaufgabe(); const incorrectSolution = [...solution]; incorrectSolution[0].amount = 9999; // Falscher Betrag const result = verifySolution(incorrectSolution, solution); expect(result.correct).toBe(false); expect(result.message).toContain("Fehler in Buchung 1"); }); });