Initial import of zappier-edge from zapier monorepo

This commit is contained in:
George Lambert 2026-09-11 13:31:54 -04:00
commit 48cd80ce5f
120 changed files with 19867 additions and 0 deletions

33
tests/credit.test.ts Normal file
View file

@ -0,0 +1,33 @@
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);
});
});