Spaces:
Paused
Paused
File size: 1,130 Bytes
1fe7075 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | import { testConfig } from '../../test/support/test-config.js';
import type { Subscription } from '../generated/prisma/client.js';
import { allowanceFor } from './allowance.js';
const subscription = (plan: Subscription['plan']) =>
({ plan, currentPeriodStart: new Date('2026-10-01'), currentPeriodEnd: new Date('2026-11-01') }) as Subscription;
describe('allowanceFor', () => {
const config = testConfig();
it('gives free accounts their lifetime tries', () => {
expect(allowanceFor('user', null, config)).toEqual({ plan: 'free', limit: 5, countFrom: null, renewsAt: null });
});
it('gives subscribers their plan for the current billing period', () => {
expect(allowanceFor('user', subscription('starter'), config)).toEqual({
plan: 'starter',
limit: 150,
countFrom: new Date('2026-10-01'),
renewsAt: new Date('2026-11-01'),
});
expect(allowanceFor('user', subscription('growth'), config).limit).toBe(600);
});
it('never limits admins', () => {
expect(allowanceFor('admin', subscription('starter'), config)).toMatchObject({ plan: 'unlimited', limit: null });
});
});
|