withoutMiddleware(EnsurePlatformSession::class); $this->admin = User::create([ 'public_id' => 'admin-001', 'name' => 'Admin User', 'email' => 'admin@example.com', ]); $this->organization = Organization::create([ 'owner_ref' => $this->admin->public_id, 'name' => 'Phase2 Org', 'slug' => 'phase2-org', 'settings' => ['onboarded' => true], ]); Member::create([ 'owner_ref' => $this->admin->public_id, 'organization_id' => $this->organization->id, 'user_ref' => $this->admin->public_id, 'role' => 'org_admin', ]); } public function test_onboarding_creates_organization_and_branch(): void { Organization::query()->delete(); Member::query()->delete(); $this->actingAs($this->admin) ->post(route('frontdesk.onboarding.store'), [ 'organization_name' => 'New Corp', 'branch_name' => 'HQ', 'timezone' => 'UTC', 'badge_expiry_hours' => 8, ]) ->assertRedirect(route('frontdesk.dashboard')); $this->assertDatabaseHas('frontdesk_organizations', ['name' => 'New Corp']); $this->assertDatabaseHas('frontdesk_branches', ['name' => 'HQ']); $this->assertDatabaseHas('frontdesk_members', ['role' => 'org_admin']); } public function test_org_admin_can_create_branch_on_pro(): void { $this->organization->update([ 'settings' => array_merge($this->organization->settings ?? [], [ 'plan' => 'pro', 'billed_branches' => 3, 'plan_expires_at' => now()->addMonth()->toIso8601String(), ]), ]); $this->actingAs($this->admin) ->post(route('frontdesk.branches.store'), [ 'name' => 'East Wing', 'address' => '123 Main St', ]) ->assertRedirect(route('frontdesk.branches.index')); $this->assertDatabaseHas('frontdesk_branches', ['name' => 'East Wing']); } public function test_free_plan_cannot_manage_branches(): void { $this->actingAs($this->admin) ->get(route('frontdesk.branches.index')) ->assertOk() ->assertSee('Upgrade to Pro'); $this->actingAs($this->admin) ->post(route('frontdesk.branches.store'), [ 'name' => 'East Wing', ]) ->assertRedirect(route('frontdesk.pro.index')) ->assertSessionHas('error'); } public function test_org_admin_can_add_team_member_on_pro(): void { $this->organization->update([ 'settings' => array_merge($this->organization->settings ?? [], [ 'plan' => 'pro', 'billed_branches' => 1, 'plan_expires_at' => now()->addMonth()->toIso8601String(), ]), ]); $branch = Branch::create([ 'owner_ref' => $this->admin->public_id, 'organization_id' => $this->organization->id, 'name' => 'Main', 'is_active' => true, ]); $this->mock(\App\Services\Identity\IdentityTeamClient::class, function ($mock) { $mock->shouldReceive('inviteAppMember')->once(); }); $this->actingAs($this->admin) ->post(route('frontdesk.members.store'), [ 'email' => 'receptionist@example.com', 'role' => 'receptionist', 'branch_id' => $branch->id, ]) ->assertRedirect(route('frontdesk.members.index')); $this->assertDatabaseHas('frontdesk_members', [ 'user_ref' => 'receptionist@example.com', 'role' => 'receptionist', ]); } public function test_free_plan_cannot_manage_team(): void { $this->actingAs($this->admin) ->get(route('frontdesk.members.index')) ->assertOk() ->assertSee('Upgrade to Pro'); } public function test_settings_links_to_branches_and_team(): void { $this->actingAs($this->admin) ->get(route('frontdesk.settings')) ->assertOk() ->assertSee('Branches') ->assertSee('Team') ->assertSee(route('frontdesk.branches.index'), false) ->assertSee(route('frontdesk.members.index'), false); } public function test_receptionist_cannot_manage_branches(): void { $receptionist = User::create([ 'public_id' => 'receptionist-001', 'name' => 'Receptionist', 'email' => 'rec@example.com', ]); Member::create([ 'owner_ref' => $this->admin->public_id, 'organization_id' => $this->organization->id, 'user_ref' => $receptionist->public_id, 'role' => 'receptionist', ]); $this->actingAs($receptionist) ->get(route('frontdesk.branches.create')) ->assertForbidden(); } public function test_receptionist_can_access_check_in(): void { $receptionist = User::create([ 'public_id' => 'receptionist-002', 'name' => 'Receptionist Two', 'email' => 'rec2@example.com', ]); Member::create([ 'owner_ref' => $this->admin->public_id, 'organization_id' => $this->organization->id, 'user_ref' => $receptionist->public_id, 'role' => 'receptionist', ]); $this->actingAs($receptionist) ->get(route('frontdesk.visits.create')) ->assertOk(); } }