Files
OpenFrame/tests/unit/lib/trial-limits.test.ts
yusufipk 39e81042bb feat(billing): let people try the product before handing over a card
The trial now starts inside the product, at email verification, and Stripe
grants none at all: checkout creates a subscription that bills immediately.
Verifying an address is what buys the seven days, which is also the cheapest
abuse control there is.

An unexpired trial is treated as an entitlement the account already holds, so a
Stripe sync can add access but never retracts a trial that has not run out. That
matters most for the abandoned checkout: the resulting incomplete subscription
carries no trial_end, and writing it through would have erased the days the
account still had and locked it out.

Unpaid accounts are bounded by what they can cost us rather than by what they
can do: one workspace, one project, 3 GiB of direct uploads. YouTube imports,
share links, guests, comments and approvals stay unlimited, because those are
the parts worth trying and they cost nothing. isPaidTier() is the new seam;
hasBillingAccess() answers a different question now that access no longer
implies a card.

Signup CTAs, the pricing card, the comparison pages, the terms and the refund
policy all said the trial converts to a paid plan by itself. It no longer does,
so they say what happens instead. Settings and a banner name both dates that
matter: when the trial ends, and the fifteen days after that during which
nothing is deleted.

/admin/growth compares the two funnels on signup to paid within a fixed 30 day
window, not trial to paid. Dropping the card requirement multiplies trials, so
the old ratio can fall while more people actually pay, and reading it that way
would retire the change for the wrong reason.
2026-08-05 19:40:36 +03:00

42 lines
1.3 KiB
TypeScript

import { describe, expect, it } from 'vitest';
import {
TRIAL_PROJECT_LIMIT,
TRIAL_STORAGE_LIMIT_BYTES,
TRIAL_WORKSPACE_LIMIT,
getStorageLimitBytes,
} from '@/lib/trial-limits';
const GIB = BigInt(1024) * BigInt(1024) * BigInt(1024);
describe('trial ceilings', () => {
it('holds a trial to one workspace and one project', () => {
expect(TRIAL_WORKSPACE_LIMIT).toBe(1);
expect(TRIAL_PROJECT_LIMIT).toBe(1);
});
it('caps trial storage at 3 GiB', () => {
expect(TRIAL_STORAGE_LIMIT_BYTES).toBe(BigInt(3) * GIB);
});
});
describe('getStorageLimitBytes', () => {
const PLAN_LIMIT = BigInt(200) * GIB;
it('gives a paying account the whole plan allowance', () => {
expect(getStorageLimitBytes(true, PLAN_LIMIT)).toBe(BigInt(214748364800));
});
it('holds an unpaid account to the trial ceiling', () => {
expect(getStorageLimitBytes(false, PLAN_LIMIT)).toBe(BigInt(3221225472));
});
// A self-hosted instance can configure a plan allowance below the trial one.
// Handing a trial account more storage than the plan itself grants would be a
// strange way to run out of disk.
it('never raises an account above a plan allowance smaller than the trial ceiling', () => {
const tinyPlan = BigInt(512) * BigInt(1024) * BigInt(1024);
expect(getStorageLimitBytes(false, tinyPlan)).toBe(BigInt(536870912));
});
});