fix(admin): show the cardless trial as a trial in the admin panel

The cardless trial writes trialEndsAt and nothing else, because there is no
Stripe subscription behind it to report trialing. subscriptionStatus stays
FREE, so every admin view reading that column alone showed a live trial as a
free account: On Trial sat at zero, Free Users counted the trials, the user
table badged them Free with an open-ended Active access, the Trialing filter
returned nobody and the growth scoreboard left them out of the paid accounts
table.

Access has always been resolved from the date (hasBillingAccess), so the
display now follows the same date through getEffectiveBillingStatus. Only FREE
is overridden: any other status means Stripe has an opinion worth showing.
This commit is contained in:
2026-08-18 18:55:41 +03:00
parent bf46860feb
commit 60c208b3b3
7 changed files with 282 additions and 22 deletions
+44 -3
View File
@@ -869,9 +869,11 @@ describe('getCachedStripeStats', () => {
await createUser({ subscriptionStatus: 'TRIALING' });
await createUser({ subscriptionStatus: 'PAST_DUE' });
await createUser({ subscriptionStatus: 'CANCELED' });
await createUser({ subscriptionStatus: 'FREE' });
await createUser({ subscriptionStatus: 'FREE' });
await createUser({ subscriptionStatus: 'FREE' });
// Free means free: no trial left to run, or these would be counted as the
// cardless trials they would then be.
await createUser({ subscriptionStatus: 'FREE', trialEndsAt: null });
await createUser({ subscriptionStatus: 'FREE', trialEndsAt: null });
await createUser({ subscriptionStatus: 'FREE', trialEndsAt: null });
const stripe = stubStripePrice({ unit_amount: 1900, currency: 'eur' });
expect(await getCachedStripeStats()).toEqual({
@@ -887,6 +889,45 @@ describe('getCachedStripeStats', () => {
expect(stripe.retrievedPriceIds).toEqual(['price_admin_stats_test']);
});
// The cardless trial writes only trialEndsAt, so the account sits at FREE with no
// Stripe subscription behind it. Counting the status column alone reported every
// one of them as a free user and left "On Trial" at zero on the dashboard.
it('counts a cardless trial as trialing rather than as free', async () => {
await createUser({ subscriptionStatus: 'FREE', trialEndsAt: new Date(Date.now() + 60_000) });
await createUser({ subscriptionStatus: 'FREE', trialEndsAt: null });
stubStripePrice({ unit_amount: 1900, currency: 'usd' });
const stats = await getCachedStripeStats();
expect(stats?.trialingUsers).toBe(1);
expect(stats?.freeUsers).toBe(1);
});
it('counts an expired trial back as a free user', async () => {
await createUser({ subscriptionStatus: 'FREE', trialEndsAt: new Date(Date.now() - 60_000) });
stubStripePrice({ unit_amount: 1900, currency: 'usd' });
const stats = await getCachedStripeStats();
expect(stats?.trialingUsers).toBe(0);
expect(stats?.freeUsers).toBe(1);
});
// A Stripe trial is already TRIALING and is not sitting in the FREE bucket, so it
// must not be added on top of the cardless count.
it('does not double count a Stripe trial that also carries a trial end date', async () => {
await createUser({
subscriptionStatus: 'TRIALING',
trialEndsAt: new Date(Date.now() + 60_000),
});
stubStripePrice({ unit_amount: 1900, currency: 'usd' });
const stats = await getCachedStripeStats();
expect(stats?.trialingUsers).toBe(1);
expect(stats?.freeUsers).toBe(0);
});
// UNPAID, INCOMPLETE and INCOMPLETE_EXPIRED are real values of the enum that used to
// belong to none of the reported buckets, so those users were counted nowhere and the
// five totals silently did not add up to the user table. They must not be folded into