Intelligence, Advanced Charting & Trading Platform

1 import test from 'node:test';
2 import assert from 'node:assert/strict';
3 import { qualityScore } from '../src/quality-score.mjs';
4
5 test('scores healthy fresh observations at 100', () => {
6 assert.equal(qualityScore({ state: 'GOOD', flags: [], ageRatio: 0.1 }), 100);
7 });
8
9 test('penalizes divergence and approaching staleness deterministically', () => {
10 const score = qualityScore({ state: 'DEGRADED', flags: ['PROVIDER_DIVERGENCE'], ageRatio: 0.8 });
11 assert.equal(score, 55);
12 });
13
14 test('caps stale observations below healthy presentation threshold', () => {
15 assert.ok(qualityScore({ state: 'STALE', flags: ['STALE_SOURCE'], ageRatio: 2 }) <= 30);
16 });
17
18 test('invalid observations always score zero', () => {
19 assert.equal(qualityScore({ state: 'INVALID', flags: ['NON_POSITIVE_PRICE'], ageRatio: 0 }), 0);
20 });