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);