Skip to content

Commit 4064c46

Browse files
committed
fix tests
1 parent 836a937 commit 4064c46

File tree

1 file changed

+20
-19
lines changed

1 file changed

+20
-19
lines changed

packages/billing/src/__tests__/subscription.test.ts

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -412,11 +412,11 @@ describe('subscription', () => {
412412
const subscription = createMockSubscription()
413413

414414
it('should report weekly_limit when usage reaches limit', async () => {
415-
// tier 200 → weeklyCreditsLimit: 12000
415+
const weeklyLimit = SUBSCRIPTION_TIERS[200].weeklyCreditsLimit
416416
const { conn } = createSequentialMock({
417417
selectResults: [
418-
[], // no limit overrides
419-
[{ total: 12000 }], // weekly usage at limit
418+
[], // no limit overrides
419+
[{ total: weeklyLimit }], // weekly usage at limit
420420
],
421421
})
422422

@@ -430,8 +430,8 @@ describe('subscription', () => {
430430
expect(result.limited).toBe(true)
431431
expect(result.reason).toBe('weekly_limit')
432432
expect(result.canStartNewBlock).toBe(false)
433-
expect(result.weeklyUsed).toBe(12000)
434-
expect(result.weeklyLimit).toBe(SUBSCRIPTION_TIERS[200].weeklyCreditsLimit)
433+
expect(result.weeklyUsed).toBe(weeklyLimit)
434+
expect(result.weeklyLimit).toBe(weeklyLimit)
435435
})
436436

437437
it('should allow new block when no active block exists', async () => {
@@ -528,12 +528,12 @@ describe('subscription', () => {
528528
})
529529

530530
it('should return weekly limit error when limit is reached', async () => {
531-
// tier 200 → weeklyCreditsLimit: 12000
531+
const weeklyLimit = SUBSCRIPTION_TIERS[200].weeklyCreditsLimit
532532
const { conn } = createSequentialMock({
533533
selectResults: [
534-
[], // no existing grants
535-
[], // no limit overrides
536-
[{ total: 12000 }], // weekly limit reached
534+
[], // no existing grants
535+
[], // no limit overrides
536+
[{ total: weeklyLimit }], // weekly limit reached
537537
],
538538
})
539539

@@ -547,8 +547,8 @@ describe('subscription', () => {
547547
expect(isWeeklyLimitError(result)).toBe(true)
548548
const error = result as WeeklyLimitError
549549
expect(error.error).toBe('weekly_limit_reached')
550-
expect(error.used).toBe(12000)
551-
expect(error.limit).toBe(SUBSCRIPTION_TIERS[200].weeklyCreditsLimit)
550+
expect(error.used).toBe(weeklyLimit)
551+
expect(error.limit).toBe(weeklyLimit)
552552
})
553553

554554
it('should create new block grant when none exists', async () => {
@@ -583,14 +583,15 @@ describe('subscription', () => {
583583
})
584584

585585
it('should cap block credits to weekly remaining', async () => {
586-
// tier 200: creditsPerBlock=1200, weeklyCreditsLimit=12000
587-
// weekly used=11500 → remaining=500, block capped to 500
586+
const weeklyLimit = SUBSCRIPTION_TIERS[200].weeklyCreditsLimit
587+
const expectedRemaining = 500
588+
const weeklyUsed = weeklyLimit - expectedRemaining
588589
const now = new Date('2025-01-15T10:00:00Z')
589590
const { conn, captures } = createSequentialMock({
590591
selectResults: [
591-
[], // no existing grants
592-
[], // no limit overrides
593-
[{ total: 11500 }], // 500 remaining
592+
[], // no existing grants
593+
[], // no limit overrides
594+
[{ total: weeklyUsed }], // expectedRemaining credits remaining
594595
],
595596
insertResults: [
596597
[{ operation_id: 'capped-block' }],
@@ -607,9 +608,9 @@ describe('subscription', () => {
607608

608609
expect(isWeeklyLimitError(result)).toBe(false)
609610
const grant = result as BlockGrant
610-
expect(grant.credits).toBe(500)
611-
expect(captures.insertValues[0].principal).toBe(500)
612-
expect(captures.insertValues[0].balance).toBe(500)
611+
expect(grant.credits).toBe(expectedRemaining)
612+
expect(captures.insertValues[0].principal).toBe(expectedRemaining)
613+
expect(captures.insertValues[0].balance).toBe(expectedRemaining)
613614
})
614615

615616
it('should throw when insert returns no grant (duplicate operation)', async () => {

0 commit comments

Comments
 (0)