test(usage 剩餘百分比): 補 rate.remaining 為 null/undefined 時不計算百分比的測試

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
Jeffery
2026-06-23 17:32:49 +08:00
co-authored by Claude Opus 4.8
parent fcde1b0bc9
commit ec8773d54d
+7
View File
@@ -210,6 +210,13 @@ describe('resolveRemainingPercent', () => {
} }
}); });
it('returns null percent when rate.remaining is null/undefined', () => {
for (const remaining of [null, undefined]) {
const pct = resolveRemainingPercent({ available: false, reason: 'x' }, { hasData: true, remaining, limit: 200000, kind: 'tokens' });
assert.equal(pct.percent, null, `rate.remaining=${remaining} 應算不出百分比`);
}
});
it('returns null percent when limit is finite but remaining is non-finite', () => { it('returns null percent when limit is finite but remaining is non-finite', () => {
const pct = resolveRemainingPercent({ available: true, used: 0, limit: 100, remaining: Infinity, currency: 'USD' }, null); const pct = resolveRemainingPercent({ available: true, used: 0, limit: 100, remaining: Infinity, currency: 'USD' }, null);
assert.equal(pct.percent, null); assert.equal(pct.percent, null);