@@ -8,6 +8,15 @@ import {
88
99import type { GrantType } from '@codebuff/internal/db/schema'
1010
11+ /**
12+ * Classifies a grant into an expiration bucket based on its expires_at value.
13+ * - Grants with expires_at set go to 'renewable' bucket
14+ * - Grants with expires_at: null go to 'nonRenewable' bucket
15+ */
16+ function classifyGrant ( expiresAt : Date | null ) : CreditExpirationBucket {
17+ return expiresAt ? 'renewable' : 'nonRenewable'
18+ }
19+
1120describe ( 'Expiration Buckets' , ( ) => {
1221 describe ( 'createInitialCreditBalance' , ( ) => {
1322 it ( 'should return a CreditBalance with all values initialized to 0' , ( ) => {
@@ -59,10 +68,6 @@ describe('Expiration Buckets', () => {
5968 // - Grants with expires_at set go to 'renewable' bucket
6069 // - Grants with expires_at: null go to 'nonRenewable' bucket
6170
62- function classifyGrant ( expiresAt : Date | null ) : CreditExpirationBucket {
63- return expiresAt ? 'renewable' : 'nonRenewable'
64- }
65-
6671 it ( 'should classify grants with expires_at date as renewable' , ( ) => {
6772 const futureDate = new Date ( Date . now ( ) + 30 * 24 * 60 * 60 * 1000 ) // 30 days from now
6873 expect ( classifyGrant ( futureDate ) ) . toBe ( 'renewable' )
@@ -217,10 +222,6 @@ describe('Expiration Buckets', () => {
217222 // - Zero-balance grants: add to principals/principalsByExpiration but NOT to breakdown/breakdownByExpiration
218223 // - Negative-balance (debt) grants: tracked separately via totalDebt, NOT added to any breakdown
219224
220- function classifyGrant ( expiresAt : Date | null ) : CreditExpirationBucket {
221- return expiresAt ? 'renewable' : 'nonRenewable'
222- }
223-
224225 /**
225226 * Simulates the accumulation logic from calculateUsageAndBalance.
226227 * This mirrors lines 354-368 of balance-calculator.ts.
0 commit comments