import { InMemoryUsageRepo, UsageEntry } from '../src/usage'; const entry = (over: Partial = {}): UsageEntry => ({ customerId: 'cust_1', endpointId: 'transform', cents: 4, metadataBytes: 0, attachmentBytes: 0, timestamp: new Date('2026-07-27T10:00:00Z'), ...over, }); describe('InMemoryUsageRepo', () => { it('records and lists entries per customer', () => { const repo = new InMemoryUsageRepo(); repo.record(entry()); repo.record(entry({ customerId: 'cust_2' })); expect(repo.listFor('cust_1')).toHaveLength(1); expect(repo.listFor('cust_2')).toHaveLength(1); }); it('filters entries by since date', () => { const repo = new InMemoryUsageRepo(); repo.record(entry({ timestamp: new Date('2026-07-01T00:00:00Z') })); repo.record(entry({ timestamp: new Date('2026-07-27T00:00:00Z') })); expect(repo.listFor('cust_1', new Date('2026-07-15T00:00:00Z'))).toHaveLength(1); }); it('summarizes totals by endpoint', () => { const repo = new InMemoryUsageRepo(); repo.record(entry()); repo.record(entry({ endpointId: 'storage', cents: 112 })); repo.record(entry()); const s = repo.summaryFor('cust_1'); expect(s.customerId).toBe('cust_1'); expect(s.calls).toBe(3); expect(s.totalCents).toBe(120); expect(s.byEndpoint.transform).toEqual({ calls: 2, cents: 8 }); expect(s.byEndpoint.storage).toEqual({ calls: 1, cents: 112 }); }); });