Files
AtreidesAssetsFree/tests/price/intraday.test.mjs
T

48 lines
2.2 KiB
JavaScript
Raw Permalink Normal View History

2026-10-29 11:57:29 +01:00
// Generated, do not edit. sha256:51c49028629aebea324a581fb9c02f64b8a220708011bb4270da71cc94da3e61
import { describe, it, mock } from 'node:test';
import assert from 'node:assert/strict';
let ANTWOORD = null;
mock.module('../../client/data/market.js', { namedExports: { intradaySeries: async () => ANTWOORD } });
mock.module('../../client/price/providers.js', { namedExports: { currentRate: async () => 2 } });
const { loadIntraday } = await import('../../client/price/intraday.js');
const { t } = await import('../../client/i18n/index.js');
describe('loadIntraday: de bron per punt', () => {
it('maakt van een eigen bron per punt een label, en rekent de prijs om', async () => {
ANTWOORD = { status: 'ok', currency: 'USD', source: 'mempool',
points: [[1000, 10, 'bitvavo'], [2000, 11, 'mempool'], [3000, 12]] };
const r = await loadIntraday(1, 0);
assert.deepEqual(r.points, [[1000, 20], [2000, 22], [3000, 24]]);
assert.equal(r.source, t('marketService.sourceLive', { source: 'mempool' }));
assert.equal(r.sources.get(1000), t('marketService.sourceLive', { source: 'bitvavo' }));
assert.equal(r.sources.get(2000), t('marketService.sourceLive', { source: 'mempool' }));
assert.equal(r.sources.has(3000), false, 'zonder eigen bron valt het punt terug op de bron van de reeks');
});
it('een reeks zonder bron per rij geeft een lege kaart', async () => {
ANTWOORD = { status: 'ok', currency: 'USD', source: 'bitvavo', points: [[1000, 10]] };
const r = await loadIntraday(2, 0);
assert.equal(r.sources.size, 0);
});
});
describe('loadIntraday: zonder reeks geen melding', () => {
const gevallen = [
['de dienst is even weg', { status: 'unavailable', retryLater: true }],
['de dienst weigert', { status: 'unavailable', key: 'marketService.unauthorized' }],
['de app gebruikt de dienst niet', { status: 'off' }],
];
for (const [i, [naam, antwoord]] of gevallen.entries()) {
it(naam, async () => {
ANTWOORD = antwoord;
assert.deepEqual({ ...(await loadIntraday(10 + i, 0)) }, { points: null });
});
}
it('de aanroep gooit', async () => {
ANTWOORD = null;
assert.deepEqual({ ...(await loadIntraday(20, 0)) }, { points: null });
});
});