Compose-ready workspace: packages/zappier (rate card, portal, Stripe), packages/verae-zapier-middleware (timestamp + NATS), packages/verae-zapier (CLI app), vendor/zapier-platform, and research/zapier vendor corpus. Gate 0 structure checks pass. Product code and research are not yet wired.
33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
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);
|
|
});
|
|
});
|