withoutMiddleware(EnsurePlatformSession::class); config([ 'care.queue.api_url' => 'https://queue.test/api/v1', 'care.queue.api_key' => 'care-test-key', ]); $this->owner = User::create([ 'public_id' => 'care-queue-owner', 'name' => 'Owner', 'email' => 'queue-owner@example.com', ]); $this->organization = Organization::create([ 'owner_ref' => $this->owner->public_id, 'name' => 'Queue Clinic', 'slug' => 'queue-clinic', 'settings' => [ 'onboarded' => true, 'facility_type' => 'clinic', 'plan' => 'pro', 'plan_expires_at' => now()->addMonth()->toIso8601String(), 'queue_integration_enabled' => true, 'department_queue_provisioning' => [ 'consultation' => [ 'queues' => [[ 'branch_id' => 1, 'name' => 'Consultation', 'active' => true, 'synced' => true, 'queue_uuid' => 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', 'counter_uuid' => 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb', ]], ], 'pharmacy' => [ 'queues' => [[ 'branch_id' => 1, 'name' => 'Pharmacy', 'active' => true, 'synced' => true, 'queue_uuid' => 'cccccccc-cccc-cccc-cccc-cccccccccccc', 'counter_uuid' => 'dddddddd-dddd-dddd-dddd-dddddddddddd', ]], ], 'laboratory' => [ 'queues' => [[ 'branch_id' => 1, 'name' => 'Laboratory', 'active' => true, 'synced' => true, 'queue_uuid' => 'eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', 'counter_uuid' => 'ffffffff-ffff-ffff-ffff-ffffffffffff', ]], ], ], ], ]); Member::create([ 'owner_ref' => $this->owner->public_id, 'organization_id' => $this->organization->id, 'user_ref' => $this->owner->public_id, 'role' => 'hospital_admin', ]); $branch = Branch::create([ 'owner_ref' => $this->owner->public_id, 'organization_id' => $this->organization->id, 'name' => 'Main', 'is_active' => true, ]); // Keep provisioning stubs aligned with the created branch id. $settings = $this->organization->settings; foreach (['consultation', 'pharmacy', 'laboratory'] as $ctx) { $settings['department_queue_provisioning'][$ctx]['queues'][0]['branch_id'] = $branch->id; } $this->organization->update(['settings' => $settings]); } public function test_sidebar_does_not_show_service_queues_nav(): void { $this->actingAs($this->owner) ->get(route('care.dashboard')) ->assertOk() ->assertDontSee('Service queues', false); } public function test_service_queues_index_redirects_to_clinical_queue(): void { $this->actingAs($this->owner) ->get(route('care.service-queues.index')) ->assertRedirect(route('care.queue.index')); } public function test_clinical_queue_shows_inline_ops_not_service_counter(): void { $this->actingAs($this->owner) ->get(route('care.queue.index')) ->assertOk() ->assertDontSee('Service counter') ->assertSee('Call next'); } public function test_pharmacist_sees_call_next_on_pharmacy_page(): void { Member::query()->where('user_ref', $this->owner->public_id)->update(['role' => 'pharmacist']); $this->actingAs($this->owner) ->get(route('care.prescriptions.queue')) ->assertOk() ->assertDontSee('Service counter') ->assertSee('Call next'); } public function test_lab_page_shows_call_next_when_integration_on(): void { Member::query()->where('user_ref', $this->owner->public_id)->update(['role' => 'lab_technician']); $this->actingAs($this->owner) ->get(route('care.lab.queue.index')) ->assertOk() ->assertDontSee('Service counter') ->assertSee('Call next'); } public function test_integration_off_hides_queue_controls(): void { $settings = $this->organization->settings; $settings['queue_integration_enabled'] = false; $this->organization->update(['settings' => $settings]); $this->actingAs($this->owner) ->get(route('care.queue.index')) ->assertOk() ->assertDontSee('Call next') ->assertDontSee('Service counter'); } public function test_doctor_call_next_uses_consultation_queue_not_reception(): void { \Illuminate\Support\Facades\Http::fake([ '*/queues/*/call-next*' => \Illuminate\Support\Facades\Http::response([ 'data' => [ 'uuid' => '77777777-7777-7777-7777-777777777777', 'ticket_number' => 'C001', 'status' => 'called', ], ], 200), ]); $branchId = Branch::query()->firstOrFail()->id; $this->actingAs($this->owner) ->post(route('care.queue.call-next'), ['branch_id' => $branchId]) ->assertRedirect(); \Illuminate\Support\Facades\Http::assertSent(function ($request) { return str_contains($request->url(), '/queues/aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa/call-next'); }); } }