trypost/tests/Feature/Middleware/EnsureUserSetupIsCompleteTest.php
Paulo Castellano 2da15df96c feat: introduce Account entity as billing owner and refactor architecture
- Create Account model as Cashier Billable entity (stripe, plan, subscription)
- Account owns workspaces and has an owner_id (User)
- User belongs to one Account via account_id
- Workspace belongs to Account via account_id, no longer has billing fields
- Remove Brand model entirely (workspaces serve as grouping)
- Rename brand_limit to workspace_limit in plans
- Workspace roles simplified: admin/member/viewer (owner via Account)
- Invites now belong to Account with workspaces JSON array
- Pennant features scope changed from Workspace to Account
- EnsureSubscribed middleware checks Account subscription
- All controllers updated: BillingController, OnboardingController,
  WorkspaceInviteController, SocialController, StripeEventListener
- Frontend: extract GoogleAuthButton component, create WorkspaceRole
  enum for type-safe role checks, fix all views for new architecture
- All 1101 tests passing
2026-04-14 22:22:04 -03:00

84 lines
2.9 KiB
PHP

<?php
declare(strict_types=1);
use App\Enums\User\Setup;
use App\Enums\UserWorkspace\Role;
use App\Models\User;
use App\Models\Workspace;
test('user with completed setup can access protected routes', function () {
config(['trypost.self_hosted' => true]);
$user = User::factory()->create(['setup' => Setup::Completed]);
$workspace = Workspace::factory()->create(['user_id' => $user->id]);
$workspace->members()->attach($user->id, ['role' => Role::Member->value]);
$user->update(['current_workspace_id' => $workspace->id]);
$this->actingAs($user)
->get(route('app.calendar'))
->assertOk();
});
test('user on role step is redirected to onboarding step 1', function () {
config(['trypost.self_hosted' => true]);
$user = User::factory()->create(['setup' => Setup::Role]);
$workspace = Workspace::factory()->create(['user_id' => $user->id]);
$workspace->members()->attach($user->id, ['role' => Role::Member->value]);
$user->update(['current_workspace_id' => $workspace->id]);
$this->actingAs($user)
->get(route('app.calendar'))
->assertRedirect(route('app.onboarding.role'));
});
test('user on connections step is redirected to onboarding step 2', function () {
config(['trypost.self_hosted' => true]);
$user = User::factory()->create(['setup' => Setup::Connections]);
$workspace = Workspace::factory()->create(['user_id' => $user->id]);
$workspace->members()->attach($user->id, ['role' => Role::Member->value]);
$user->update(['current_workspace_id' => $workspace->id]);
$this->actingAs($user)
->get(route('app.calendar'))
->assertRedirect(route('app.onboarding.connect'));
});
test('user on subscription step is redirected to subscribe', function () {
config(['trypost.self_hosted' => true]);
$user = User::factory()->create(['setup' => Setup::Subscription]);
$workspace = Workspace::factory()->create(['user_id' => $user->id]);
$workspace->members()->attach($user->id, ['role' => Role::Member->value]);
$user->update(['current_workspace_id' => $workspace->id]);
$this->actingAs($user)
->get(route('app.calendar'))
->assertRedirect(route('app.subscribe'));
});
test('user on role step can access onboarding step 1', function () {
$user = User::factory()->create(['setup' => Setup::Role]);
$this->actingAs($user)
->get(route('app.onboarding.role'))
->assertOk();
});
test('user on connections step can access onboarding step 2', function () {
$user = User::factory()->create(['setup' => Setup::Connections]);
$this->actingAs($user)
->get(route('app.onboarding.connect'))
->assertOk();
});
test('user on connections step can access social connect routes', function () {
$user = User::factory()->create(['setup' => Setup::Connections]);
$this->actingAs($user)
->get(route('app.social.linkedin.connect'))
->assertRedirect();
});