withoutMiddleware(EnsurePlatformSession::class); $this->user = User::create([ 'public_id' => 'test-user-001', 'name' => 'Test User', 'email' => 'test@example.com', ]); $this->organization = Organization::create([ 'owner_ref' => $this->user->public_id, 'name' => 'Test Clinic', 'slug' => 'test-clinic', 'timezone' => 'UTC', 'settings' => ['onboarded' => true, 'facility_type' => 'clinic'], ]); Member::create([ 'owner_ref' => $this->user->public_id, 'organization_id' => $this->organization->id, 'user_ref' => $this->user->public_id, 'role' => 'hospital_admin', ]); $branch = Branch::create([ 'owner_ref' => $this->user->public_id, 'organization_id' => $this->organization->id, 'name' => 'Main Branch', 'is_active' => true, ]); Department::create([ 'owner_ref' => $this->user->public_id, 'branch_id' => $branch->id, 'name' => 'General Outpatient', 'type' => 'outpatient', 'is_active' => true, ]); } public function test_guest_is_redirected_to_sso(): void { $this->get('/dashboard')->assertRedirect(); } public function test_unonboarded_user_is_redirected_to_onboarding(): void { Organization::query()->delete(); Member::query()->delete(); $this->actingAs($this->user) ->get(route('care.dashboard')) ->assertRedirect(route('care.onboarding.show')); } public function test_dashboard_loads_for_authenticated_user(): void { $this->actingAs($this->user) ->get(route('care.dashboard')) ->assertOk() ->assertSee('Test Clinic') ->assertSee('Revenue today') ->assertSee('Open bills'); } public function test_doctor_dashboard_hides_finance_metrics(): void { Member::where('user_ref', $this->user->public_id)->update(['role' => 'doctor']); $this->actingAs($this->user) ->get(route('care.dashboard')) ->assertOk() ->assertSee('Patients today') ->assertSee('Appointments today') ->assertSee('Patients in queue') ->assertSee('No patients waiting right now.') ->assertDontSee('Revenue today') ->assertDontSee('Open bills') ->assertDontSee('Team members') ->assertDontSee('Active branches'); } public function test_onboarding_creates_organization(): void { Organization::query()->delete(); Member::query()->delete(); Branch::query()->delete(); Department::query()->delete(); $this->actingAs($this->user) ->post(route('care.onboarding.store'), [ 'organization_name' => 'Accra Medical Centre', 'facility_type' => 'hospital', 'branch_name' => 'Head Office', 'branch_address' => '123 Main St', 'branch_phone' => '+233201234567', 'timezone' => 'Africa/Accra', ]) ->assertRedirect(route('care.dashboard')); $this->assertDatabaseHas('care_organizations', ['name' => 'Accra Medical Centre']); $this->assertDatabaseHas('care_branches', ['name' => 'Head Office']); $this->assertDatabaseHas('care_departments', ['name' => 'General Outpatient']); } public function test_branches_index_loads(): void { $this->actingAs($this->user) ->get(route('care.branches.index')) ->assertOk() ->assertSee('Main Branch'); } public function test_members_index_loads(): void { $this->actingAs($this->user) ->get(route('care.members.index')) ->assertOk() ->assertSee('test-user-001'); } public function test_audit_log_index_loads(): void { $this->actingAs($this->user) ->get(route('care.audit.index')) ->assertOk() ->assertSee('Audit log'); } }