Initial import of zappier-edge from zapier monorepo
This commit is contained in:
commit
78e6201d43
120 changed files with 19867 additions and 0 deletions
39
tests/stripe.test.ts
Normal file
39
tests/stripe.test.ts
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
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);
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue