Versie 0.2.0

This commit is contained in:
Atreides Assets committed 2026-10-29 11:57:29 +01:00
commit e77d8fd373
495 files changed
+81026

No files matched your search

+57
View File
@@ -0,0 +1,57 @@
// Generated, do not edit. sha256:b83eae2452e831916c5adb829943694b1474213183f0c8ae01a34491f818b8de
import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
import { feeCandidates, withFee } from '../../client/actions/valuation-fee.js';
const ACC = 1, ANDER = 2, BTC = 10, ETH = 11;
const ev = (o) => ({ id: o.id, assetId: BTC, type: 'sell', fromAccountId: ACC, toAccountId: null,
amount: 1000, unitFee: null, note: null, occurredAt: '2026-03-01T10:00:00Z', ...o });
const balans = (o) => ({ id: o.id, accountId: ACC, assetId: BTC, rateAt: '2026-04-01T00:00:00Z', ...o });
describe('feeCandidates', () => {
const v = balans({ id: 2 });
const vorige = balans({ id: 1, rateAt: '2026-02-01T00:00:00Z' });
it('geeft de uitgaande boekingen sinds de vorige balans, nieuwste eerst', () => {
const events = [
ev({ id: 10, occurredAt: '2026-02-15T00:00:00Z' }),
ev({ id: 11, type: 'transfer', toAccountId: ANDER, occurredAt: '2026-03-15T00:00:00Z' }),
ev({ id: 12, type: 'transfer', toAccountId: ACC, occurredAt: '2026-03-20T00:00:00Z' }),
];
assert.deepEqual(feeCandidates({ events, valuations: [vorige, v], v }).map(e => e.id), [12, 11, 10]);
});
it('laat weg wat de fee niet kan dragen of niet bij dit gat hoort', () => {
const events = [
ev({ id: 20, type: 'buy', fromAccountId: null, toAccountId: ACC }),
ev({ id: 21, type: 'interest', fromAccountId: null, toAccountId: ACC }),
ev({ id: 22, fromAccountId: ANDER }),
ev({ id: 23, assetId: ETH }),
ev({ id: 24, type: 'transfer', fromAccountId: ANDER, toAccountId: ACC }),
ev({ id: 25, occurredAt: '2026-01-15T00:00:00Z' }),
ev({ id: 26, occurredAt: '2026-04-02T00:00:00Z' }),
];
assert.deepEqual(feeCandidates({ events, valuations: [vorige, v], v }), []);
});
it('kijkt zonder vorige balans terug tot het begin, en een balans van een ander account telt niet', () => {
const events = [ev({ id: 30, occurredAt: '2025-01-01T00:00:00Z' })];
const ander = balans({ id: 3, accountId: ANDER, rateAt: '2026-02-01T00:00:00Z' });
assert.deepEqual(feeCandidates({ events, valuations: [ander, v], v }).map(e => e.id), [30]);
});
});
describe('withFee', () => {
it('telt het gat op bij een bestaande fee, als positief getal', () => {
assert.equal(withFee(ev({ id: 1, unitFee: 50 }), -200).unitFee, 250);
assert.equal(withFee(ev({ id: 1 }), -200).unitFee, 200);
});
it('laat de rest van de boeking staan en zet de notitie erachter', () => {
const uit = withFee(ev({ id: 1, note: 'betaling' }), -5, 'kosten aangevuld');
assert.equal(uit.amount, 1000);
assert.equal(uit.note, 'betaling · kosten aangevuld');
assert.equal(withFee(ev({ id: 1 }), -5, 'x').note, 'x');
});
});