2026-05-14 22:37:46 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
use App\Actions\User\CreateUser;
|
|
|
|
|
use App\Enums\UserWorkspace\Role;
|
2026-05-14 23:23:35 +00:00
|
|
|
use App\Models\Account;
|
|
|
|
|
use App\Models\User;
|
2026-05-14 22:37:46 +00:00
|
|
|
use App\Models\Workspace;
|
|
|
|
|
use Database\Seeders\PlanSeeder;
|
|
|
|
|
|
|
|
|
|
beforeEach(function () {
|
|
|
|
|
config(['trypost.self_hosted' => false]);
|
2026-05-21 13:02:38 +00:00
|
|
|
config(['trypost.billing.require_card_for_trial' => true]);
|
2026-05-14 22:37:46 +00:00
|
|
|
$this->seed(PlanSeeder::class);
|
|
|
|
|
});
|
|
|
|
|
|
2026-05-21 12:49:44 +00:00
|
|
|
test('user without subscription is redirected to subscribe', function () {
|
2026-05-14 22:37:46 +00:00
|
|
|
$user = CreateUser::execute([
|
|
|
|
|
'name' => 'Alice',
|
|
|
|
|
'email' => 'alice@example.com',
|
|
|
|
|
'password' => 'password123',
|
|
|
|
|
'registration_ip' => '127.0.0.1',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$workspace = Workspace::factory()->create([
|
|
|
|
|
'account_id' => $user->account_id,
|
|
|
|
|
'user_id' => $user->id,
|
|
|
|
|
]);
|
|
|
|
|
$workspace->members()->attach($user->id, ['role' => Role::Member->value]);
|
|
|
|
|
$user->update(['current_workspace_id' => $workspace->id]);
|
|
|
|
|
|
|
|
|
|
$response = $this->actingAs($user->fresh())->get(route('app.accounts'));
|
|
|
|
|
|
feat: per-workspace pricing, onboarding, and billing overhaul
Pricing
- Bill per workspace ($12/mo or $120/yr each); Stripe quantity tracks the
workspace count and syncs on workspace create/delete.
- 2,500 AI credits per workspace, pooled at the account level; monthly reset
on the billing anniversary, annual granted upfront (no rollover).
- One social account per network per workspace; remove all count-based limits
(workspace/social/member) and the legacy plan tiers (single Workspace plan).
Onboarding (cloud only: SELF_HOSTED=false + PostHog)
- Replace the /subscribe plan picker with /onboarding persona selection
(Creator/Freelancer/Startup/Agency/Small business/Other), saved on the user
(users.persona) and mirrored to PostHog, then Stripe Checkout on the monthly
price. 8-day trial so Stripe displays 7.
Billing screen
- Remove the Change Plan dialog (dead with a single plan); add an annual-upgrade
banner for monthly subscribers (swapToYearly).
- Current-plan card shows the workspace count instead of the plan name.
System AI
- Brand analyzer / workspace autofill is always allowed and never debits credits
(system feature, not the user's usage).
Self-hosted (SELF_HOSTED=true) bypasses all billing, credit, limit, network,
and onboarding logic.
2026-06-21 23:40:03 +00:00
|
|
|
$response->assertRedirect(route('app.onboarding'));
|
2026-05-14 22:37:46 +00:00
|
|
|
});
|
|
|
|
|
|
2026-05-21 12:49:44 +00:00
|
|
|
test('user with active subscription can access the app', function () {
|
2026-05-14 22:37:46 +00:00
|
|
|
$user = CreateUser::execute([
|
|
|
|
|
'name' => 'Alice',
|
|
|
|
|
'email' => 'alice2@example.com',
|
|
|
|
|
'password' => 'password123',
|
|
|
|
|
'registration_ip' => '127.0.0.1',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$workspace = Workspace::factory()->create([
|
|
|
|
|
'account_id' => $user->account_id,
|
|
|
|
|
'user_id' => $user->id,
|
|
|
|
|
]);
|
|
|
|
|
$workspace->members()->attach($user->id, ['role' => Role::Member->value]);
|
|
|
|
|
$user->update(['current_workspace_id' => $workspace->id]);
|
|
|
|
|
|
2026-05-21 12:49:44 +00:00
|
|
|
$user->account->subscriptions()->create([
|
|
|
|
|
'type' => Account::SUBSCRIPTION_NAME,
|
|
|
|
|
'stripe_id' => 'sub_test_'.fake()->uuid(),
|
|
|
|
|
'stripe_status' => 'active',
|
|
|
|
|
'stripe_price' => 'price_123',
|
|
|
|
|
]);
|
2026-05-14 22:37:46 +00:00
|
|
|
|
|
|
|
|
$response = $this->actingAs($user->fresh())->get(route('app.accounts'));
|
|
|
|
|
|
2026-05-21 12:49:44 +00:00
|
|
|
$response->assertOk();
|
2026-05-14 22:37:46 +00:00
|
|
|
});
|
2026-05-14 23:23:35 +00:00
|
|
|
|
|
|
|
|
test('user on trialing subscription (legacy trial-with-card) can access the app', function () {
|
|
|
|
|
$account = Account::factory()->create([
|
|
|
|
|
'trial_ends_at' => null,
|
|
|
|
|
'stripe_id' => 'cus_test_'.fake()->uuid(),
|
|
|
|
|
]);
|
|
|
|
|
$user = User::factory()->create(['account_id' => $account->id]);
|
|
|
|
|
$account->update(['owner_id' => $user->id]);
|
|
|
|
|
|
|
|
|
|
$account->subscriptions()->create([
|
|
|
|
|
'type' => Account::SUBSCRIPTION_NAME,
|
|
|
|
|
'stripe_id' => 'sub_test_'.fake()->uuid(),
|
|
|
|
|
'stripe_status' => 'trialing',
|
|
|
|
|
'stripe_price' => 'price_123',
|
|
|
|
|
'trial_ends_at' => now()->addDays(5),
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$workspace = Workspace::factory()->create([
|
|
|
|
|
'account_id' => $account->id,
|
|
|
|
|
'user_id' => $user->id,
|
|
|
|
|
]);
|
|
|
|
|
$workspace->members()->attach($user->id, ['role' => Role::Member->value]);
|
|
|
|
|
$user->update(['current_workspace_id' => $workspace->id]);
|
|
|
|
|
|
|
|
|
|
$response = $this->actingAs($user->fresh())->get(route('app.accounts'));
|
|
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
});
|
2026-05-21 13:02:38 +00:00
|
|
|
|
2026-06-14 18:46:17 +00:00
|
|
|
test('user with past_due subscription can access the app instead of being forced to subscribe', function () {
|
|
|
|
|
$account = Account::factory()->create([
|
|
|
|
|
'trial_ends_at' => null,
|
|
|
|
|
'stripe_id' => 'cus_test_'.fake()->uuid(),
|
|
|
|
|
]);
|
|
|
|
|
$user = User::factory()->create(['account_id' => $account->id]);
|
|
|
|
|
$account->update(['owner_id' => $user->id]);
|
|
|
|
|
|
|
|
|
|
$account->subscriptions()->create([
|
|
|
|
|
'type' => Account::SUBSCRIPTION_NAME,
|
|
|
|
|
'stripe_id' => 'sub_test_'.fake()->uuid(),
|
|
|
|
|
'stripe_status' => 'past_due',
|
|
|
|
|
'stripe_price' => 'price_123',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$workspace = Workspace::factory()->create([
|
|
|
|
|
'account_id' => $account->id,
|
|
|
|
|
'user_id' => $user->id,
|
|
|
|
|
]);
|
|
|
|
|
$workspace->members()->attach($user->id, ['role' => Role::Member->value]);
|
|
|
|
|
$user->update(['current_workspace_id' => $workspace->id]);
|
|
|
|
|
|
|
|
|
|
$response = $this->actingAs($user->fresh())->get(route('app.accounts'));
|
|
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
$response->assertSessionMissing('errors');
|
|
|
|
|
});
|
|
|
|
|
|
2026-05-21 13:02:38 +00:00
|
|
|
test('user on generic trial can access the app when card is not required', function () {
|
|
|
|
|
config(['trypost.billing.require_card_for_trial' => false]);
|
|
|
|
|
|
|
|
|
|
$user = CreateUser::execute([
|
|
|
|
|
'name' => 'Alice',
|
|
|
|
|
'email' => 'alice-generic@example.com',
|
|
|
|
|
'password' => 'password123',
|
|
|
|
|
'registration_ip' => '127.0.0.1',
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$workspace = Workspace::factory()->create([
|
|
|
|
|
'account_id' => $user->account_id,
|
|
|
|
|
'user_id' => $user->id,
|
|
|
|
|
]);
|
|
|
|
|
$workspace->members()->attach($user->id, ['role' => Role::Member->value]);
|
|
|
|
|
$user->update(['current_workspace_id' => $workspace->id]);
|
|
|
|
|
|
|
|
|
|
$response = $this->actingAs($user->fresh())->get(route('app.accounts'));
|
|
|
|
|
|
|
|
|
|
$response->assertOk();
|
|
|
|
|
});
|