Files
AtreidesAssetsFree/tests/ui/huidige-stand-groepen.test.mjs
2026-10-29 11:57:29 +01:00

94 lines
3.9 KiB
JavaScript

// Generated, do not edit. sha256:62bcb62c65034fb71f6266f0193d341686cd42445f45be42aee861e04fc09615
import { describe, it } from 'node:test';
import assert from 'node:assert/strict';
import { groupStanding, standingGroupingOf, standingToday, standingShowsToday } from '../../client/widgets/standing-groups.js';
const beurs = { id: 1, name: 'Bitvavo', kind: 'exchange' };
const kluis = { id: 2, name: 'Kluis', kind: 'vault' };
const koude = { id: 3, name: 'Trezor', kind: 'wallet' };
const geen = { id: null, name: 'Zonder account', isUnassigned: true };
const btc = { id: 10, kind: 'crypto' };
const eth = { id: 11, kind: 'crypto' };
const goud = { id: 12, kind: 'metal' };
const RIJEN = [
{ account: beurs, asset: btc, value: 100, origin: 'spot' },
{ account: beurs, asset: eth, value: 50, origin: 'spot' },
{ account: koude, asset: btc, value: 300, origin: 'spot' },
{ account: kluis, asset: goud, value: 200, origin: 'day' },
{ account: geen, asset: goud, value: 20, origin: 'day' },
{ account: koude, asset: eth, value: null, origin: null },
];
const TOTAAL = 670;
const som = groepen => groepen.reduce((s, g) => s + g.value, 0);
const waarden = groepen => groepen.map(g => [g.key, g.value]);
describe('groupStanding', () => {
it('per account, hoogste eerst, met de rij zonder account als eigen groep', () => {
const g = groupStanding(RIJEN, 'account');
assert.deepEqual(waarden(g), [['a3', 300], ['a2', 200], ['a1', 150], ['none', 20]]);
assert.equal(som(g), TOTAAL);
});
it('per accountsoort: twee beursrijen worden één, zonder account blijft apart', () => {
const g = groupStanding(RIJEN, 'accountKind');
assert.deepEqual(waarden(g), [['wallet', 300], ['vault', 200], ['exchange', 150], ['none', 20]]);
assert.equal(som(g), TOTAAL);
});
it('per asset: dezelfde munt op twee accounts telt op', () => {
const g = groupStanding(RIJEN, 'asset');
assert.deepEqual(waarden(g), [['s10', 400], ['s12', 220], ['s11', 50]]);
assert.equal(som(g), TOTAAL);
});
it('per assetsoort', () => {
const g = groupStanding(RIJEN, 'assetKind');
assert.deepEqual(waarden(g), [['crypto', 450], ['metal', 220]]);
assert.equal(som(g), TOTAAL);
});
it('draagt de herkomst van elke koers mee, ook van een rij zonder koers', () => {
const crypto = groupStanding(RIJEN, 'assetKind').find(g => g.key === 'crypto');
assert.equal(crypto.origins.length, 4);
});
it('valt bij een onbekende of ontbrekende groepering terug op per account', () => {
assert.equal(standingGroupingOf(undefined), 'account');
assert.equal(standingGroupingOf('perSoort'), 'account');
assert.deepEqual(waarden(groupStanding(RIJEN, 'onzin')), waarden(groupStanding(RIJEN, 'account')));
});
});
describe('standingToday', () => {
const VANDAAG = { total: 17, perAsset: new Map([[10, 12], [11, -5], [12, 10]]) };
it('per asset: elk asset één keer, hoe veel accounts het ook heeft', () => {
assert.deepEqual([...standingToday(RIJEN, 'asset', VANDAAG)], [['s10', 12], ['s11', -5], ['s12', 10]]);
});
it('per assetsoort: de assets van die soort opgeteld', () => {
assert.deepEqual([...standingToday(RIJEN, 'assetKind', VANDAAG)], [['crypto', 7], ['metal', 10]]);
});
it('per account niets, want de dagreeks kent geen accounts', () => {
assert.equal(standingToday(RIJEN, 'account', VANDAAG).size, 0);
assert.equal(standingToday(RIJEN, 'accountKind', VANDAAG).size, 0);
});
it('niets zonder resultaat van vandaag', () => {
assert.equal(standingToday(RIJEN, 'asset', null).size, 0);
});
});
describe('standingShowsToday', () => {
it('staat aan zonder instelling, ook bij een widget zonder parameters', () => {
assert.equal(standingShowsToday(null), true);
assert.equal(standingShowsToday({ groupBy: 'asset' }), true);
});
it('staat alleen uit als de instelling false is', () => {
assert.equal(standingShowsToday({ showToday: false }), false);
assert.equal(standingShowsToday({ showToday: true }), true);
});
});