Deploy Ladill Care / deploy (push) Successful in 39s
Shared queue-board is now a Waiting/Called/In care/Done stage board with prominent tickets and Call next; nurses lose queue.manage and canAccessPatientQueue so /queue and queue nav are gated while specialty workspaces stay available. Co-authored-by: Cursor <cursoragent@cursor.com>
147 lines
4.8 KiB
PHP
147 lines
4.8 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Http\Middleware\EnsurePlatformSession;
|
|
use App\Models\Branch;
|
|
use App\Models\Member;
|
|
use App\Models\Organization;
|
|
use App\Models\User;
|
|
use App\Services\Care\CarePermissions;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class CarePatientQueueAccessTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
protected User $owner;
|
|
|
|
protected Organization $organization;
|
|
|
|
protected Branch $branch;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->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'));
|
|
}
|
|
}
|