Deploy Ladill Care / deploy (push) Successful in 53s
Remove the standalone Service Queues nav so call-next/now-serving lives on clinical queue, appointments, pharmacy, lab, and specialty surfaces; Pro orgs can activate dentistry and related modules with branch departments and queue stubs. Co-authored-by: Cursor <cursoragent@cursor.com>
200 lines
6.8 KiB
PHP
200 lines
6.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 Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Tests\TestCase;
|
|
|
|
class CareNaturalQueueTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
protected User $owner;
|
|
|
|
protected Organization $organization;
|
|
|
|
protected function setUp(): void
|
|
{
|
|
parent::setUp();
|
|
$this->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,
|
|
],
|
|
]);
|
|
|
|
Member::create([
|
|
'owner_ref' => $this->owner->public_id,
|
|
'organization_id' => $this->organization->id,
|
|
'user_ref' => $this->owner->public_id,
|
|
'role' => 'hospital_admin',
|
|
]);
|
|
|
|
Branch::create([
|
|
'owner_ref' => $this->owner->public_id,
|
|
'organization_id' => $this->organization->id,
|
|
'name' => 'Main',
|
|
'is_active' => true,
|
|
]);
|
|
}
|
|
|
|
protected function fakeQueueApi(): void
|
|
{
|
|
Http::fake(function (\Illuminate\Http\Client\Request $request) {
|
|
$url = $request->url();
|
|
if (str_contains($url, '/counters/') && str_contains($url, '/console')) {
|
|
return Http::response([
|
|
'data' => [
|
|
'counter' => ['name' => 'Reception desk', 'branch' => 'Main', 'status' => 'available'],
|
|
'current_ticket' => null,
|
|
'queues' => [['uuid' => '22222222-2222-2222-2222-222222222222', 'name' => 'Consultation']],
|
|
'waiting_by_queue' => [],
|
|
'transfer_queues' => [],
|
|
],
|
|
], 200);
|
|
}
|
|
if (str_contains($url, '/counters')) {
|
|
return Http::response([
|
|
'data' => [[
|
|
'uuid' => '11111111-1111-1111-1111-111111111111',
|
|
'name' => 'Reception desk',
|
|
'branch' => 'Main',
|
|
'status' => 'available',
|
|
'queues' => [['uuid' => '22222222-2222-2222-2222-222222222222', 'name' => 'Consultation']],
|
|
]],
|
|
], 200);
|
|
}
|
|
|
|
return Http::response(['message' => 'unexpected '.$url], 500);
|
|
});
|
|
}
|
|
|
|
public function test_sidebar_does_not_show_service_queues_nav(): void
|
|
{
|
|
$this->fakeQueueApi();
|
|
|
|
$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_embeds_service_counter_panel(): void
|
|
{
|
|
$this->fakeQueueApi();
|
|
|
|
$this->actingAs($this->owner)
|
|
->get(route('care.queue.index'))
|
|
->assertOk()
|
|
->assertSee('Service counter')
|
|
->assertSee('Reception desk')
|
|
->assertSee('Call next');
|
|
}
|
|
|
|
public function test_pharmacist_sees_queue_panel_on_pharmacy_page(): void
|
|
{
|
|
$this->fakeQueueApi();
|
|
|
|
Member::query()->where('user_ref', $this->owner->public_id)->update(['role' => 'pharmacist']);
|
|
|
|
$this->actingAs($this->owner)
|
|
->get(route('care.prescriptions.queue'))
|
|
->assertOk()
|
|
->assertSee('Service counter');
|
|
}
|
|
|
|
public function test_lab_page_embeds_service_counter_when_integration_on(): void
|
|
{
|
|
$this->fakeQueueApi();
|
|
|
|
Member::query()->where('user_ref', $this->owner->public_id)->update(['role' => 'lab_technician']);
|
|
|
|
$this->actingAs($this->owner)
|
|
->get(route('care.lab.queue.index'))
|
|
->assertOk()
|
|
->assertSee('Service counter');
|
|
}
|
|
|
|
public function test_branch_scoped_member_panel_prefers_matching_branch_counter(): void
|
|
{
|
|
Http::fake(function (\Illuminate\Http\Client\Request $request) {
|
|
$url = $request->url();
|
|
if (str_contains($url, '/counters/') && str_contains($url, '/console')) {
|
|
return Http::response([
|
|
'data' => [
|
|
'counter' => ['name' => 'Main reception', 'branch' => 'Main'],
|
|
'current_ticket' => null,
|
|
'queues' => [['uuid' => 'cccccccc-cccc-cccc-cccc-cccccccccccc', 'name' => 'Consultation']],
|
|
'waiting_by_queue' => [],
|
|
'transfer_queues' => [],
|
|
],
|
|
], 200);
|
|
}
|
|
if (str_contains($url, '/counters')) {
|
|
return Http::response([
|
|
'data' => [
|
|
[
|
|
'uuid' => 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa',
|
|
'name' => 'Other site desk',
|
|
'branch' => 'Other',
|
|
'queues' => [['name' => 'Consultation']],
|
|
],
|
|
[
|
|
'uuid' => 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb',
|
|
'name' => 'Main reception',
|
|
'branch' => 'Main',
|
|
'queues' => [['name' => 'Consultation']],
|
|
],
|
|
],
|
|
], 200);
|
|
}
|
|
|
|
return Http::response(['message' => 'unexpected '.$url], 500);
|
|
});
|
|
|
|
$branch = Branch::query()->first();
|
|
Member::query()->where('user_ref', $this->owner->public_id)->update([
|
|
'role' => 'receptionist',
|
|
'branch_id' => $branch->id,
|
|
]);
|
|
|
|
$this->actingAs($this->owner)
|
|
->get(route('care.queue.index'))
|
|
->assertOk()
|
|
->assertSee('Main reception')
|
|
->assertDontSee('Other site desk');
|
|
}
|
|
}
|