import { applyMonthlyCredit } from '../src/billing/credit'; import { DEFAULT_TIERS } from '../src/pricing'; import { UsageSummary } from '../src/usage'; const freeTier = DEFAULT_TIERS.find((t) => t.id === 'free')!; // monthlyCreditCents: 100 const summary = (totalCents: number): UsageSummary => ({ customerId: 'cust_1', totalCents, calls: 1, byEndpoint: {}, }); describe('applyMonthlyCredit', () => { it('covers usage fully when under the monthly credit', () => { const billed = applyMonthlyCredit(summary(60), freeTier); expect(billed.includedCents).toBe(60); expect(billed.billableCents).toBe(0); expect(billed.totalCents).toBe(60); }); it('bills only the overage when usage exceeds the credit', () => { const billed = applyMonthlyCredit(summary(250), freeTier); expect(billed.includedCents).toBe(100); expect(billed.billableCents).toBe(150); }); it('bills nothing when there is no usage', () => { const billed = applyMonthlyCredit(summary(0), freeTier); expect(billed.includedCents).toBe(0); expect(billed.billableCents).toBe(0); }); });