Initial import of zappier-edge from zapier monorepo
This commit is contained in:
commit
6ae11f8875
120 changed files with 19867 additions and 0 deletions
63
tests/db-pricing.test.ts
Normal file
63
tests/db-pricing.test.ts
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
import Database from 'better-sqlite3';
|
||||
import { SqlitePricingStore } from '../src/db/pricing-store';
|
||||
|
||||
describe('SqlitePricingStore', () => {
|
||||
it('seeds the default rate card and tiers when empty', () => {
|
||||
const store = new SqlitePricingStore(new Database(':memory:'));
|
||||
expect(store.getRateCard().endpoints.transform).toEqual({ kind: 'fixed', fixedCents: 4 });
|
||||
expect(store.getTiers().map((t) => t.id)).toEqual(['free', 'pro', 'business']);
|
||||
});
|
||||
|
||||
it('seeds only once', () => {
|
||||
const db = new Database(':memory:');
|
||||
const first = new SqlitePricingStore(db);
|
||||
first.deleteEndpoint('transform');
|
||||
const second = new SqlitePricingStore(db);
|
||||
expect(second.getRateCard().endpoints.transform).toBeUndefined();
|
||||
});
|
||||
|
||||
it('reseeds endpoints without reverting admin tier edits', () => {
|
||||
const db = new Database(':memory:');
|
||||
const first = new SqlitePricingStore(db);
|
||||
for (const id of Object.keys(first.getRateCard().endpoints)) {
|
||||
first.deleteEndpoint(id);
|
||||
}
|
||||
first.upsertTier({ id: 'pro', name: 'Pro', multiplier: 0.9, monthlyCreditCents: 1000 });
|
||||
const second = new SqlitePricingStore(db);
|
||||
expect(second.getRateCard().endpoints.transform).toBeDefined();
|
||||
expect(second.getTiers().find((t) => t.id === 'pro')?.multiplier).toBe(0.9);
|
||||
});
|
||||
|
||||
it('upserts and deletes endpoints', () => {
|
||||
const store = new SqlitePricingStore(new Database(':memory:'));
|
||||
store.upsertEndpoint('experimental', { kind: 'variable', baseCents: 3, perKbCents: 2, perMbCents: 20 });
|
||||
expect(store.getRateCard().endpoints.experimental).toEqual({
|
||||
kind: 'variable',
|
||||
baseCents: 3,
|
||||
perKbCents: 2,
|
||||
perMbCents: 20,
|
||||
});
|
||||
store.deleteEndpoint('experimental');
|
||||
expect(store.getRateCard().endpoints.experimental).toBeUndefined();
|
||||
});
|
||||
|
||||
it('upserts tiers including default rules, and deletes them', () => {
|
||||
const store = new SqlitePricingStore(new Database(':memory:'));
|
||||
store.upsertTier({
|
||||
id: 'edu',
|
||||
name: 'Education',
|
||||
multiplier: 0.4,
|
||||
monthlyCreditCents: 500,
|
||||
defaultRule: { kind: 'fixed', fixedCents: 6 },
|
||||
});
|
||||
expect(store.getTiers().find((t) => t.id === 'edu')?.defaultRule).toEqual({
|
||||
kind: 'fixed',
|
||||
fixedCents: 6,
|
||||
});
|
||||
store.upsertTier({ id: 'edu', name: 'Education', multiplier: 0.3, monthlyCreditCents: 500 });
|
||||
expect(store.getTiers().filter((t) => t.id === 'edu')).toHaveLength(1);
|
||||
expect(store.getTiers().find((t) => t.id === 'edu')?.multiplier).toBe(0.3);
|
||||
store.deleteTier('edu');
|
||||
expect(store.getTiers().find((t) => t.id === 'edu')).toBeUndefined();
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue