fix: format peer metrics with contracted units

This commit is contained in:
2026-08-20 20:06:48 +03:30
parent d8c7e7263c
commit 23147cd60d
5 changed files with 60 additions and 2 deletions

View File

@@ -0,0 +1,21 @@
import { describe, expect, it } from 'vitest';
import { formatPeerMetric, peerMetricLabel } from './peer-metrics';
describe('peer metric presentation', () => {
it('formats timing medians in milliseconds instead of percent', () => {
expect(formatPeerMetric('init_time_ms_p50', '1240')).toBe('۱٬۲۴۰ میلی‌ثانیه');
expect(formatPeerMetric('verify_time_ms_p95', '980')).toBe('۹۸۰ میلی‌ثانیه');
});
it('formats rate medians as percentages', () => {
expect(formatPeerMetric('payment_success_rate', '87.25')).toBe('۸۷٫۲۵٪');
expect(formatPeerMetric('paid_fee_rate', '0.5')).toBe('۰٫۵٪');
});
it('provides Persian labels for every contracted peer metric', () => {
expect(peerMetricLabel('payment_success_rate')).toBe('نرخ موفقیت پرداخت');
expect(peerMetricLabel('init_time_ms_p95')).toBe('زمان آغاز پرداخت — صدک ۹۵');
expect(peerMetricLabel('verify_time_ms_p50')).toBe('زمان تأیید — میانه');
});
});