master-zapier-plan-draft/packages/zappier/tests/stripe.test.ts
George Lambert b4150c8250 Milestone 0: import zappier billing, Verae middleware, and Zapier research
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.
2026-09-09 02:37:36 -04:00

39 lines
1.2 KiB
TypeScript

import { MeterEventClient, reportUsage, METER_EVENT_NAME } from '../src/billing/stripe';
import { UsageEntry } from '../src/usage';
const entry = (cents: number): UsageEntry => ({
customerId: 'cust_1',
endpointId: 'storage',
cents,
metadataBytes: 0,
attachmentBytes: 0,
timestamp: new Date(),
});
const fakeClient = () => {
const calls: { eventName: string; customerId: string; value: string }[] = [];
const client: MeterEventClient = {
createMeterEvent: async (params) => {
calls.push(params);
},
};
return { client, calls };
};
describe('reportUsage', () => {
it('reports usage minus the monthly credit as one meter event', async () => {
const { client, calls } = fakeClient();
const reported = await reportUsage(client, 'cus_123', [entry(112), entry(4)], 100);
expect(reported).toBe(16); // 116 - 100 credit
expect(calls).toEqual([
{ eventName: METER_EVENT_NAME, customerId: 'cus_123', value: '16' },
]);
});
it('reports nothing when the credit covers all usage', async () => {
const { client, calls } = fakeClient();
const reported = await reportUsage(client, 'cus_123', [entry(4)], 100);
expect(reported).toBe(0);
expect(calls).toHaveLength(0);
});
});