From ec8773d54deb9e9c0bbe0244507dc839a0b88315 Mon Sep 17 00:00:00 2001 From: Jeffery Date: Tue, 23 Jun 2026 17:32:49 +0800 Subject: [PATCH] =?UTF-8?q?test(usage=20=E5=89=A9=E9=A4=98=E7=99=BE?= =?UTF-8?q?=E5=88=86=E6=AF=94):=20=E8=A3=9C=20rate.remaining=20=E7=82=BA?= =?UTF-8?q?=20null/undefined=20=E6=99=82=E4=B8=8D=E8=A8=88=E7=AE=97?= =?UTF-8?q?=E7=99=BE=E5=88=86=E6=AF=94=E7=9A=84=E6=B8=AC=E8=A9=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-Authored-By: Claude Opus 4.8 (1M context) --- app/usage.test.js | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/app/usage.test.js b/app/usage.test.js index 21655fc..783c9c7 100644 --- a/app/usage.test.js +++ b/app/usage.test.js @@ -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', () => { const pct = resolveRemainingPercent({ available: true, used: 0, limit: 100, remaining: Infinity, currency: 'USD' }, null); assert.equal(pct.percent, null);