withoutMiddleware(EnsurePlatformSession::class); $this->owner = User::create([ 'public_id' => 'pq-access-owner', 'name' => 'Owner', 'email' => 'pq-access-owner@example.com', ]); $this->organization = Organization::create([ 'owner_ref' => $this->owner->public_id, 'name' => 'PQ Clinic', 'slug' => 'pq-clinic', 'settings' => [ 'onboarded' => true, 'facility_type' => 'clinic', 'plan' => 'pro', 'plan_expires_at' => now()->addMonth()->toIso8601String(), 'queue_integration_enabled' => true, ], ]); Member::create([ 'owner_ref' => $this->owner->public_id, 'organization_id' => $this->organization->id, 'user_ref' => $this->owner->public_id, 'role' => 'hospital_admin', ]); $this->branch = Branch::create([ 'owner_ref' => $this->owner->public_id, 'organization_id' => $this->organization->id, 'name' => 'Main', 'is_active' => true, ]); } /** * @return array{0: User, 1: Member} */ protected function makeStaff(string $role, string $suffix): array { $user = User::create([ 'public_id' => 'pq-'.$suffix, 'name' => ucfirst($role).' '.$suffix, 'email' => $suffix.'@pq.example.com', ]); $member = Member::create([ 'owner_ref' => $this->owner->public_id, 'organization_id' => $this->organization->id, 'user_ref' => $user->public_id, 'role' => $role, 'branch_id' => $this->branch->id, ]); return [$user, $member]; } public function test_nurse_loses_queue_manage_and_cannot_open_patient_queue(): void { [$nurseUser, $nurseMember] = $this->makeStaff('nurse', 'nurse1'); $permissions = app(CarePermissions::class); $this->assertFalse($permissions->can($nurseMember, 'queue.manage')); $this->assertFalse($permissions->canAccessPatientQueue($nurseMember)); $this->assertTrue($permissions->handlesFloorCare($nurseMember)); $this->actingAs($nurseUser) ->get(route('care.queue.index')) ->assertForbidden(); $this->actingAs($nurseUser) ->get(route('care.dashboard')) ->assertOk() ->assertDontSee('href="'.e(route('care.queue.index')).'"', false); } public function test_doctor_and_receptionist_can_open_redesigned_queue_board(): void { [$doctorUser, $doctorMember] = $this->makeStaff('doctor', 'doc1'); [$receptionistUser, $receptionistMember] = $this->makeStaff('receptionist', 'rec1'); $permissions = app(CarePermissions::class); $this->assertTrue($permissions->canAccessPatientQueue($doctorMember)); $this->assertTrue($permissions->canAccessPatientQueue($receptionistMember)); $this->assertTrue($permissions->can($receptionistMember, 'queue.manage')); $this->actingAs($doctorUser) ->get(route('care.queue.index')) ->assertOk() ->assertSee('Patient flow') ->assertSee('Waiting') ->assertSee('Called') ->assertSee('Done'); $this->actingAs($receptionistUser) ->get(route('care.queue.index')) ->assertOk() ->assertSee('Patient flow') ->assertSee('Call next'); $this->actingAs($doctorUser) ->get(route('care.dashboard')) ->assertOk() ->assertSee('Queue', false); } public function test_nurse_specialty_show_redirects_to_workspace_not_queue(): void { [$nurseUser] = $this->makeStaff('nurse', 'nurse-spec'); app(\App\Services\Care\SpecialtyModuleService::class) ->ensureDefaultModulesProvisioned($this->organization, $this->owner->public_id); app(\App\Services\Care\SpecialtyModuleService::class) ->activate($this->organization->fresh(), $this->owner->public_id, 'emergency'); $this->actingAs($nurseUser) ->get(route('care.specialty.show', 'emergency')) ->assertRedirect(route('care.specialty.workspace', 'emergency')); } }