Hard-delete Care remote Queue adapter (Phase 5).
Deploy Ladill Care / deploy (push) Failing after 1m13s

Care Queue Engine is the only path; remove QueueClient, driver config, and remote HTTP tests.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
isaacclad
2026-07-18 11:16:41 +00:00
co-authored by Cursor
parent 966f0496b2
commit dd4bc493b4
31 changed files with 441 additions and 2108 deletions
@@ -47,11 +47,6 @@ class CareFinancialWorkflowRuntimeTest extends TestCase
parent::setUp();
$this->withoutMiddleware(EnsurePlatformSession::class);
config([
'care.queue.api_url' => 'https://queue.test/api/v1',
'care.queue.api_key' => 'workflow-test-key',
]);
$this->owner = User::create([
'public_id' => 'financial-workflow-owner',
'name' => 'Workflow Admin',
+1 -8
View File
@@ -39,12 +39,6 @@ class CareNativeQueueTest extends TestCase
parent::setUp();
$this->withoutMiddleware(EnsurePlatformSession::class);
config([
'care.queue.driver' => 'native',
'care.queue.api_url' => '',
'care.queue.api_key' => '',
]);
$this->owner = User::create([
'public_id' => 'native-queue-owner',
'name' => 'Owner',
@@ -99,10 +93,9 @@ class CareNativeQueueTest extends TestCase
]);
}
public function test_bridge_enabled_without_queue_api_keys(): void
public function test_bridge_enabled_when_integration_on(): void
{
$this->assertTrue(app(CareQueueBridge::class)->isEnabled($this->organization));
$this->assertSame('', (string) config('care.queue.api_key'));
}
public function test_check_in_issues_native_consultation_ticket(): void
+58 -59
View File
@@ -3,11 +3,17 @@
namespace Tests\Feature;
use App\Http\Middleware\EnsurePlatformSession;
use App\Models\Appointment;
use App\Models\Branch;
use App\Models\CareQueueTicket;
use App\Models\Member;
use App\Models\Organization;
use App\Models\Patient;
use App\Models\Practitioner;
use App\Models\User;
use App\Services\Care\AppointmentService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Http;
use Tests\TestCase;
/**
@@ -21,16 +27,13 @@ class CareNaturalQueueTest extends TestCase
protected Organization $organization;
protected Branch $branch;
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',
@@ -47,38 +50,6 @@ class CareNaturalQueueTest extends TestCase
'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',
]],
],
],
],
]);
@@ -89,19 +60,12 @@ class CareNaturalQueueTest extends TestCase
'role' => 'hospital_admin',
]);
$branch = Branch::create([
$this->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
@@ -165,24 +129,59 @@ class CareNaturalQueueTest extends TestCase
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),
Http::fake();
$practitioner = Practitioner::create([
'owner_ref' => $this->owner->public_id,
'organization_id' => $this->organization->id,
'branch_id' => $this->branch->id,
'name' => 'Dr. Natural',
'room' => 'Room 1',
'is_active' => true,
]);
$branchId = Branch::query()->firstOrFail()->id;
$patient = Patient::create([
'owner_ref' => $this->owner->public_id,
'organization_id' => $this->organization->id,
'branch_id' => $this->branch->id,
'patient_number' => 'P-N1',
'first_name' => 'Ada',
'last_name' => 'Lovelace',
]);
$appointment = Appointment::create([
'owner_ref' => $this->owner->public_id,
'organization_id' => $this->organization->id,
'branch_id' => $this->branch->id,
'patient_id' => $patient->id,
'practitioner_id' => $practitioner->id,
'type' => Appointment::TYPE_WALK_IN,
'status' => Appointment::STATUS_SCHEDULED,
'scheduled_at' => now(),
]);
app(AppointmentService::class)->checkIn(
$appointment->fresh(['organization', 'patient', 'practitioner']),
$this->owner->public_id,
$this->owner->public_id,
);
$this->actingAs($this->owner)
->post(route('care.queue.call-next'), ['branch_id' => $branchId])
->assertRedirect();
->post(route('care.queue.call-next'), [
'branch_id' => $this->branch->id,
'practitioner_id' => $practitioner->id,
])
->assertRedirect()
->assertSessionHas('success');
\Illuminate\Support\Facades\Http::assertSent(function ($request) {
return str_contains($request->url(), '/queues/aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa/call-next');
});
$this->assertDatabaseHas('care_queue_tickets', [
'care_entity_id' => $appointment->id,
'status' => CareQueueTicket::STATUS_CALLED,
]);
$this->assertDatabaseMissing('care_service_queues', [
'organization_id' => $this->organization->id,
'context' => 'reception',
]);
Http::assertNothingSent();
}
}
+1 -1
View File
@@ -64,7 +64,7 @@ class CareProTest extends TestCase
->assertSee('/branch/mo')
->assertSee('Unlimited branches')
->assertSee('Core patient records')
->assertSee('Queue integration')
->assertSee('In-app service queues')
->assertSee('Custom multi-department workflow')
->assertSee('AI-assisted healthcare integration')
->assertSee('Upgrade to Pro')
+76 -179
View File
@@ -5,6 +5,7 @@ namespace Tests\Feature;
use App\Http\Middleware\EnsurePlatformSession;
use App\Models\Appointment;
use App\Models\Branch;
use App\Models\CareQueueTicket;
use App\Models\Member;
use App\Models\Organization;
use App\Models\Patient;
@@ -32,11 +33,6 @@ class CareQueueBridgeTest extends TestCase
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' => 'bridge-owner',
'name' => 'Owner',
@@ -70,33 +66,6 @@ class CareQueueBridgeTest extends TestCase
'is_active' => true,
]);
$settings = $this->organization->settings;
$settings['department_queue_provisioning'] = [
CareQueueContexts::CONSULTATION => [
'queues' => [[
'branch_id' => $this->branch->id,
'branch_name' => 'Main',
'name' => 'Consultation',
'prefix' => 'C',
'active' => true,
'synced' => true,
'routing_mode' => 'assigned_only',
'queue_uuid' => 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa',
'counter_uuid' => 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb',
'queue_external_key' => CareQueueContexts::queueExternalKey(CareQueueContexts::CONSULTATION, $this->branch->id),
'counter_external_key' => CareQueueContexts::counterExternalKey(CareQueueContexts::CONSULTATION, $this->branch->id),
'points' => [[
'kind' => 'practitioner',
'ref_id' => 0, // filled after practitioner create in tests that need it
'destination' => 'Consultation desk',
'counter_uuid' => 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb',
'synced' => true,
]],
]],
],
];
$this->organization->update(['settings' => $settings]);
$this->patient = Patient::create([
'owner_ref' => $this->owner->public_id,
'organization_id' => $this->organization->id,
@@ -111,6 +80,8 @@ class CareQueueBridgeTest extends TestCase
public function test_check_in_issues_consultation_ticket_when_integration_on(): void
{
Http::fake();
$practitioner = \App\Models\Practitioner::create([
'owner_ref' => $this->owner->public_id,
'organization_id' => $this->organization->id,
@@ -120,36 +91,6 @@ class CareQueueBridgeTest extends TestCase
'is_active' => true,
]);
$settings = $this->organization->settings;
$settings['department_queue_provisioning'][CareQueueContexts::CONSULTATION]['queues'][0]['points'] = [[
'kind' => 'practitioner',
'ref_id' => $practitioner->id,
'destination' => 'Room 1',
'staff_display_name' => 'Dr. Bridge',
'counter_uuid' => 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb',
'synced' => true,
]];
$this->organization->update(['settings' => $settings]);
Http::fake(function (\Illuminate\Http\Client\Request $request) {
if (str_contains($request->url(), '/tickets') && $request->method() === 'POST') {
$this->assertSame('bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb', $request['assigned_counter_id'] ?? null);
return Http::response([
'data' => [
'uuid' => 'cccccccc-cccc-cccc-cccc-cccccccccccc',
'ticket_number' => 'C001',
'status' => 'waiting',
'assigned_counter' => ['uuid' => 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb'],
'destination' => 'Room 1',
'staff_display_name' => 'Dr. Bridge',
],
], 201);
}
return Http::response(['message' => 'unexpected '.$request->url()], 500);
});
$appointment = Appointment::create([
'owner_ref' => $this->owner->public_id,
'organization_id' => $this->organization->id,
@@ -163,13 +104,19 @@ class CareQueueBridgeTest extends TestCase
$result = app(AppointmentService::class)->checkIn($appointment, $this->owner->public_id, $this->owner->public_id);
$this->assertSame('C001', $result->queue_ticket_number);
$this->assertNotNull($result->queue_ticket_uuid);
$this->assertSame('waiting', $result->queue_ticket_status);
$this->assertSame('cccccccc-cccc-cccc-cccc-cccccccccccc', $result->queue_ticket_uuid);
Http::assertSent(fn ($request) => str_contains($request->url(), '/tickets')
&& ($request['service_queue_id'] ?? null) === 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa'
&& ($request['customer_name'] ?? null) === 'Ada Lovelace');
$this->assertStringStartsWith('C', (string) $result->queue_ticket_number);
$this->assertSame('Room 1', $result->queue_destination);
$this->assertSame('Dr. Bridge', $result->queue_staff_display_name);
$this->assertDatabaseHas('care_queue_tickets', [
'uuid' => $result->queue_ticket_uuid,
'ticket_number' => $result->queue_ticket_number,
'status' => CareQueueTicket::STATUS_WAITING,
'care_entity' => 'appointment',
'care_entity_id' => $result->id,
]);
Http::assertNothingSent();
}
public function test_check_in_skips_ticket_when_integration_off(): void
@@ -227,6 +174,8 @@ class CareQueueBridgeTest extends TestCase
public function test_call_next_backfills_missing_ticket_then_calls(): void
{
Http::fake();
$practitioner = \App\Models\Practitioner::create([
'owner_ref' => $this->owner->public_id,
'organization_id' => $this->organization->id,
@@ -236,50 +185,6 @@ class CareQueueBridgeTest extends TestCase
'is_active' => true,
]);
$settings = $this->organization->settings;
$settings['department_queue_provisioning'][CareQueueContexts::CONSULTATION]['queues'][0]['points'] = [[
'kind' => 'practitioner',
'ref_id' => $practitioner->id,
'destination' => 'Room 3',
'counter_uuid' => 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb',
'synced' => true,
]];
$settings['department_queue_provisioning'][CareQueueContexts::CONSULTATION]['queues'][0]['counter_uuid'] = 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb';
$this->organization->update(['settings' => $settings]);
$ticketSeq = 0;
Http::fake(function (\Illuminate\Http\Client\Request $request) use (&$ticketSeq) {
if (str_contains($request->url(), '/call-next') && $request->method() === 'POST') {
if ($ticketSeq < 1) {
return Http::response(['data' => null], 200);
}
return Http::response([
'data' => [
'uuid' => 'ffffffff-ffff-ffff-ffff-ffffffffffff',
'ticket_number' => 'C100',
'customer_name' => 'Ada Lovelace',
'status' => 'called',
],
], 200);
}
if (str_contains($request->url(), '/tickets') && $request->method() === 'POST') {
$ticketSeq++;
return Http::response([
'data' => [
'uuid' => 'ffffffff-ffff-ffff-ffff-ffffffffffff',
'ticket_number' => 'C100',
'status' => 'waiting',
'assigned_counter' => ['uuid' => 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb'],
],
], 201);
}
return Http::response(['message' => 'unexpected '.$request->url()], 500);
});
Appointment::create([
'owner_ref' => $this->owner->public_id,
'organization_id' => $this->organization->id,
@@ -302,16 +207,19 @@ class CareQueueBridgeTest extends TestCase
->assertRedirect(route('care.queue.index'))
->assertSessionHas('success');
$this->assertNotNull(Appointment::query()->where('patient_id', $this->patient->id)->value('queue_ticket_uuid'));
Http::assertSent(fn ($r) => str_contains($r->url(), '/tickets') && $r->method() === 'POST');
Http::assertSent(fn ($r) => str_contains($r->url(), '/call-next'));
$appointment = Appointment::query()->where('patient_id', $this->patient->id)->first();
$this->assertNotNull($appointment?->queue_ticket_uuid);
$this->assertSame('called', $appointment->queue_ticket_status);
$this->assertDatabaseHas('care_queue_tickets', [
'uuid' => $appointment->queue_ticket_uuid,
'status' => CareQueueTicket::STATUS_CALLED,
]);
Http::assertNothingSent();
}
public function test_call_next_empty_queue_flashes_info_not_error(): void
{
Http::fake([
'*/queues/*/call-next*' => Http::response(['data' => null], 200),
]);
Http::fake();
$this->actingAs($this->owner)
->from(route('care.queue.index'))
@@ -319,35 +227,51 @@ class CareQueueBridgeTest extends TestCase
->assertRedirect(route('care.queue.index'))
->assertSessionHas('info', 'No patients waiting at your consultation service point.')
->assertSessionMissing('error');
Http::assertNothingSent();
}
public function test_recall_reannounces_called_ticket_from_patient_queue(): void
{
Http::fake();
$practitioner = \App\Models\Practitioner::create([
'owner_ref' => $this->owner->public_id,
'organization_id' => $this->organization->id,
'branch_id' => $this->branch->id,
'name' => 'Dr. Recall',
'room' => 'Room 2',
'is_active' => true,
]);
$appointment = Appointment::create([
'owner_ref' => $this->owner->public_id,
'organization_id' => $this->organization->id,
'branch_id' => $this->branch->id,
'patient_id' => $this->patient->id,
'practitioner_id' => $practitioner->id,
'type' => Appointment::TYPE_WALK_IN,
'status' => Appointment::STATUS_WAITING,
'status' => Appointment::STATUS_SCHEDULED,
'scheduled_at' => now(),
'waiting_at' => now(),
'queue_position' => 1,
'queue_ticket_uuid' => 'eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee',
'queue_ticket_number' => 'C055',
'queue_ticket_status' => 'called',
]);
Http::fake([
'*/tickets/*/action*' => Http::response([
'data' => [
'uuid' => 'eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee',
'ticket_number' => 'C055',
'status' => 'called',
'customer_name' => 'Ada Lovelace',
],
], 200),
]);
$checkedIn = app(AppointmentService::class)->checkIn(
$appointment->fresh(['organization', 'patient', 'practitioner']),
$this->owner->public_id,
$this->owner->public_id,
);
$bridge = app(\App\Services\Care\CareQueueBridge::class);
$called = $bridge->callNext(
$this->organization->fresh(),
CareQueueContexts::CONSULTATION,
(int) $this->branch->id,
null,
$practitioner->id,
);
$this->assertNotNull($called['ticket']);
$appointment = $checkedIn->fresh();
$this->assertSame('called', $appointment->queue_ticket_status);
$this->actingAs($this->owner)
->from(route('care.queue.index'))
@@ -355,22 +279,20 @@ class CareQueueBridgeTest extends TestCase
->assertRedirect(route('care.queue.index'))
->assertSessionHas('success');
Http::assertSent(function ($request) {
return str_contains($request->url(), '/tickets/eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee/action')
&& ($request['action'] ?? null) === 'recall';
});
$this->assertSame('called', $appointment->fresh()->queue_ticket_status);
$this->actingAs($this->owner)
->get(route('care.queue.index', ['branch_id' => $this->branch->id]))
->assertOk()
->assertSee('Call again')
->assertSee('C055');
->assertSee($appointment->queue_ticket_number);
Http::assertNothingSent();
}
public function test_patient_queue_sync_issues_specialty_tickets(): void
{
Http::fake();
$department = \App\Models\Department::create([
'owner_ref' => $this->owner->public_id,
'branch_id' => $this->branch->id,
@@ -402,20 +324,7 @@ class CareQueueBridgeTest extends TestCase
'name' => 'Dentistry',
'prefix' => 'DEN',
'active' => true,
'synced' => true,
'routing_mode' => 'assigned_only',
'queue_uuid' => 'dddddddd-dddd-dddd-dddd-dddddddddddd',
'counter_uuid' => 'eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee',
'queue_external_key' => CareQueueContexts::queueExternalKey('dentistry', $this->branch->id),
'counter_external_key' => CareQueueContexts::counterExternalKey('dentistry', $this->branch->id),
'points' => [[
'kind' => 'practitioner',
'ref_id' => $practitioner->id,
'destination' => 'Dental Bay 1',
'staff_display_name' => 'Dentistry Clinic',
'counter_uuid' => 'eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee',
'synced' => true,
]],
'synced' => false,
]],
],
];
@@ -436,36 +345,24 @@ class CareQueueBridgeTest extends TestCase
'reason' => 'Toothache',
]);
Http::fake(function (\Illuminate\Http\Client\Request $request) {
if (str_contains($request->url(), '/tickets') && $request->method() === 'POST') {
$this->assertSame('dddddddd-dddd-dddd-dddd-dddddddddddd', $request['service_queue_id'] ?? null);
$this->assertSame('eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee', $request['assigned_counter_id'] ?? null);
return Http::response([
'data' => [
'uuid' => 'ffffffff-ffff-ffff-ffff-ffffffffffff',
'ticket_number' => 'DEN001',
'status' => 'waiting',
'assigned_counter' => ['uuid' => 'eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee'],
'destination' => 'Dental Bay 1',
'staff_display_name' => 'Dentistry Clinic',
],
], 201);
}
return Http::response(['data' => []], 200);
});
$this->actingAs($this->owner)
->get(route('care.queue.index', ['branch_id' => $this->branch->id]))
->assertOk()
->assertSee('DEN001')
->assertSee('Toothache');
$this->assertDatabaseHas('care_appointments', [
'patient_id' => $this->patient->id,
'queue_ticket_number' => 'DEN001',
$appointment = Appointment::query()->where('patient_id', $this->patient->id)->first();
$this->assertNotNull($appointment?->queue_ticket_uuid);
$this->assertStringStartsWith('DEN', (string) $appointment->queue_ticket_number);
$this->assertDatabaseHas('care_service_queues', [
'organization_id' => $this->organization->id,
'branch_id' => $this->branch->id,
'context' => 'dentistry',
]);
$this->assertDatabaseHas('care_queue_tickets', [
'uuid' => $appointment->queue_ticket_uuid,
'ticket_number' => $appointment->queue_ticket_number,
'status' => CareQueueTicket::STATUS_WAITING,
]);
Http::assertNothingSent();
}
}
+122 -195
View File
@@ -5,12 +5,12 @@ namespace Tests\Feature;
use App\Http\Middleware\EnsurePlatformSession;
use App\Models\Appointment;
use App\Models\Branch;
use App\Models\CareQueueTicket;
use App\Models\CareServiceQueue;
use App\Models\Member;
use App\Models\Organization;
use App\Models\Patient;
use App\Models\Prescription;
use App\Models\User;
use App\Models\Visit;
use App\Services\Care\AppointmentService;
use App\Services\Care\CareQueueBridge;
use App\Services\Care\CareQueueContexts;
@@ -34,11 +34,6 @@ class CareQueueWorkflowTest extends TestCase
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-workflow-owner',
'name' => 'Owner',
@@ -73,105 +68,6 @@ class CareQueueWorkflowTest extends TestCase
]);
}
protected function fakeQueueApi(): void
{
$consultationQueue = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa';
$pharmacyQueue = 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb';
$consultationCounter = 'cccccccc-cccc-cccc-cccc-cccccccccccc';
$pharmacyCounter = 'dddddddd-dddd-dddd-dddd-dddddddddddd';
$seq = ['C' => 0, 'P' => 0];
Http::fake(function (\Illuminate\Http\Client\Request $request) use (
$consultationQueue,
$pharmacyQueue,
$consultationCounter,
$pharmacyCounter,
&$seq,
) {
$url = $request->url();
$method = $request->method();
if (str_contains($url, '/integrations/status')) {
return Http::response([
'data' => [
'provisioned' => true,
'integrations' => ['care' => true],
],
], 200);
}
if ($method === 'POST' && str_contains($url, '/branches')) {
return Http::response(['data' => ['id' => 1, 'name' => 'Main']], 201);
}
if ($method === 'POST' && str_contains($url, '/queues') && ! str_contains($url, 'call-next')) {
$payload = $request->data();
$key = (string) ($payload['external_key'] ?? '');
$isPharmacy = str_contains($key, 'pharmacy');
return Http::response([
'data' => [
'uuid' => $isPharmacy ? $pharmacyQueue : $consultationQueue,
'name' => $payload['name'] ?? 'Queue',
'prefix' => $payload['prefix'] ?? 'X',
],
], 201);
}
if ($method === 'POST' && str_contains($url, '/counters')) {
$payload = $request->data();
$key = (string) ($payload['external_key'] ?? '');
$isPharmacy = str_contains($key, 'pharmacy');
return Http::response([
'data' => [
'uuid' => $isPharmacy ? $pharmacyCounter : $consultationCounter,
'name' => $payload['name'] ?? 'Counter',
],
], 201);
}
if ($method === 'POST' && preg_match('#/tickets$#', parse_url($url, PHP_URL_PATH) ?? '')) {
$payload = $request->data();
$queueId = (string) ($payload['service_queue_id'] ?? '');
$prefix = $queueId === $pharmacyQueue ? 'P' : 'C';
$seq[$prefix]++;
return Http::response([
'data' => [
'uuid' => (string) Str::uuid(),
'ticket_number' => $prefix.sprintf('%03d', $seq[$prefix]),
'status' => 'waiting',
'customer_name' => $payload['customer_name'] ?? null,
],
], 201);
}
if ($method === 'POST' && str_contains($url, '/call-next')) {
$path = parse_url($url, PHP_URL_PATH) ?? '';
$isPharmacy = str_contains($path, $pharmacyQueue);
return Http::response([
'data' => [
'uuid' => (string) Str::uuid(),
'ticket_number' => $isPharmacy ? 'P001' : 'C001',
'status' => 'called',
'customer_name' => 'Called Patient',
],
], 200);
}
if ($method === 'POST' && str_contains($url, '/tickets/') && str_contains($url, '/action')) {
$payload = $request->data();
return Http::response([
'data' => [
'uuid' => basename(dirname(parse_url($url, PHP_URL_PATH) ?? '/x/x')),
'ticket_number' => 'C001',
'status' => $payload['action'] === 'complete' ? 'completed' : ($payload['action'] === 'start' ? 'serving' : 'called'),
],
], 200);
}
return Http::response(['message' => 'unexpected '.$method.' '.$url], 500);
});
}
public function test_integration_off_does_not_issue_tickets_on_check_in(): void
{
$settings = $this->organization->settings;
@@ -211,7 +107,7 @@ class CareQueueWorkflowTest extends TestCase
public function test_integration_on_issues_consultation_ticket_on_check_in(): void
{
$this->fakeQueueApi();
Http::fake();
$practitioner = \App\Models\Practitioner::create([
'owner_ref' => $this->owner->public_id,
@@ -222,33 +118,6 @@ class CareQueueWorkflowTest extends TestCase
'is_active' => true,
]);
$this->organization->update([
'settings' => array_merge($this->organization->settings ?? [], [
'department_queue_provisioning' => [
CareQueueContexts::CONSULTATION => [
'queues' => [[
'branch_id' => $this->branch->id,
'branch_name' => 'Main',
'name' => 'Consultation',
'prefix' => 'C',
'active' => true,
'synced' => true,
'routing_mode' => 'assigned_only',
'queue_uuid' => 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa',
'counter_uuid' => 'cccccccc-cccc-cccc-cccc-cccccccccccc',
'points' => [[
'kind' => 'practitioner',
'ref_id' => $practitioner->id,
'destination' => 'Room 2',
'counter_uuid' => 'cccccccc-cccc-cccc-cccc-cccccccccccc',
'synced' => true,
]],
]],
],
],
]),
]);
$patient = Patient::create([
'uuid' => (string) Str::uuid(),
'owner_ref' => $this->owner->public_id,
@@ -277,11 +146,22 @@ class CareQueueWorkflowTest extends TestCase
$this->assertNotNull($appointment->queue_ticket_uuid);
$this->assertSame('C001', $appointment->queue_ticket_number);
$this->assertSame('waiting', $appointment->queue_ticket_status);
$this->assertDatabaseHas('care_queue_tickets', [
'uuid' => $appointment->queue_ticket_uuid,
'ticket_number' => 'C001',
'status' => CareQueueTicket::STATUS_WAITING,
]);
$this->assertDatabaseHas('care_service_queues', [
'organization_id' => $this->organization->id,
'branch_id' => $this->branch->id,
'context' => CareQueueContexts::CONSULTATION,
]);
Http::assertNothingSent();
}
public function test_pharmacy_call_next_uses_pharmacy_queue_not_reception(): void
{
$this->fakeQueueApi();
Http::fake();
$pharmacist = Member::create([
'owner_ref' => $this->owner->public_id,
@@ -291,51 +171,98 @@ class CareQueueWorkflowTest extends TestCase
'branch_id' => $this->branch->id,
]);
$this->organization->update([
'settings' => array_merge($this->organization->settings ?? [], [
'department_queue_provisioning' => [
CareQueueContexts::PHARMACY => [
'queues' => [[
'branch_id' => $this->branch->id,
'branch_name' => 'Main',
'name' => 'Pharmacy',
'prefix' => 'P',
'active' => true,
'synced' => true,
'routing_mode' => 'assigned_only',
'queue_uuid' => 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb',
'counter_uuid' => 'dddddddd-dddd-dddd-dddd-dddddddddddd',
'queue_external_key' => CareQueueContexts::queueExternalKey(CareQueueContexts::PHARMACY, $this->branch->id),
'counter_external_key' => CareQueueContexts::counterExternalKey(CareQueueContexts::PHARMACY, $this->branch->id),
'points' => [[
'kind' => 'member',
'ref_id' => $pharmacist->id,
'staff_ref' => 'pharm-workflow',
'destination' => 'Pharmacy counter 1',
'counter_uuid' => 'dddddddd-dddd-dddd-dddd-dddddddddddd',
'synced' => true,
]],
]],
],
],
]),
Member::query()->where('user_ref', $this->owner->public_id)->update(['role' => 'pharmacist']);
$queue = CareServiceQueue::create([
'owner_ref' => $this->owner->public_id,
'organization_id' => $this->organization->id,
'branch_id' => $this->branch->id,
'context' => CareQueueContexts::PHARMACY,
'name' => 'Pharmacy',
'prefix' => 'P',
'routing_mode' => 'assigned_only',
'external_key' => CareQueueContexts::queueExternalKey(CareQueueContexts::PHARMACY, $this->branch->id),
]);
Member::query()->where('user_ref', $this->owner->public_id)->update(['role' => 'pharmacist']);
$point = $queue->points()->create([
'owner_ref' => $this->owner->public_id,
'organization_id' => $this->organization->id,
'name' => 'Pharmacy counter 1',
'destination' => 'Pharmacy counter 1',
'kind' => 'member',
'ref_id' => $pharmacist->id,
'staff_ref' => 'pharm-workflow',
'external_key' => CareQueueContexts::pointExternalKey(
CareQueueContexts::PHARMACY,
$this->branch->id,
'member',
$pharmacist->id,
),
]);
$settings = $this->organization->settings;
$settings['department_queue_provisioning'] = [
CareQueueContexts::PHARMACY => [
'queues' => [[
'branch_id' => $this->branch->id,
'branch_name' => 'Main',
'name' => 'Pharmacy',
'prefix' => 'P',
'active' => true,
'synced' => true,
'routing_mode' => 'assigned_only',
'queue_uuid' => $queue->uuid,
'counter_uuid' => $point->uuid,
'queue_external_key' => $queue->external_key,
'points' => [[
'kind' => 'member',
'ref_id' => $pharmacist->id,
'staff_ref' => 'pharm-workflow',
'destination' => 'Pharmacy counter 1',
'counter_uuid' => $point->uuid,
'external_key' => $point->external_key,
'synced' => true,
]],
]],
],
];
$this->organization->update(['settings' => $settings]);
CareQueueTicket::create([
'owner_ref' => $this->owner->public_id,
'organization_id' => $this->organization->id,
'service_queue_id' => $queue->id,
'service_point_id' => $point->id,
'ticket_number' => 'P001',
'status' => CareQueueTicket::STATUS_WAITING,
'priority' => 'walk_in',
'customer_name' => 'Pharmacy Patient',
]);
$this->actingAs($this->owner)
->post(route('care.prescriptions.call-next'), ['branch_id' => $this->branch->id])
->assertRedirect();
Http::assertSent(function (\Illuminate\Http\Client\Request $request) {
return $request->method() === 'POST'
&& str_contains($request->url(), '/queues/bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb/call-next');
});
$this->assertDatabaseHas('care_queue_tickets', [
'ticket_number' => 'P001',
'status' => CareQueueTicket::STATUS_CALLED,
'service_queue_id' => $queue->id,
]);
Http::assertNothingSent();
}
public function test_complete_advances_ticket_status_on_appointment(): void
{
$this->fakeQueueApi();
Http::fake();
$practitioner = \App\Models\Practitioner::create([
'owner_ref' => $this->owner->public_id,
'organization_id' => $this->organization->id,
'branch_id' => $this->branch->id,
'name' => 'Dr. Complete',
'room' => 'Room 1',
'is_active' => true,
]);
$patient = Patient::create([
'uuid' => (string) Str::uuid(),
@@ -353,42 +280,41 @@ class CareQueueWorkflowTest extends TestCase
'organization_id' => $this->organization->id,
'branch_id' => $this->branch->id,
'patient_id' => $patient->id,
'practitioner_id' => $practitioner->id,
'type' => Appointment::TYPE_WALK_IN,
'status' => Appointment::STATUS_WAITING,
'queue_ticket_uuid' => 'eeeeeeee-eeee-eeee-eeee-eeeeeeeeeeee',
'queue_ticket_number' => 'C009',
'queue_ticket_status' => 'serving',
'status' => Appointment::STATUS_SCHEDULED,
'scheduled_at' => now(),
]);
app(CareQueueBridge::class)->complete($this->organization, $appointment);
$appointment->refresh();
$appointment = app(AppointmentService::class)->checkIn(
$appointment->fresh(['organization', 'patient', 'practitioner']),
$this->owner->public_id,
$this->owner->public_id,
);
$bridge = app(CareQueueBridge::class);
$bridge->callNext(
$this->organization->fresh(),
CareQueueContexts::CONSULTATION,
(int) $this->branch->id,
null,
$practitioner->id,
);
$bridge->serve($this->organization->fresh(), $appointment->fresh());
$bridge->complete($this->organization->fresh(), $appointment->fresh());
$appointment->refresh();
$this->assertSame('completed', $appointment->queue_ticket_status);
$this->assertDatabaseHas('care_queue_tickets', [
'uuid' => $appointment->queue_ticket_uuid,
'status' => CareQueueTicket::STATUS_COMPLETED,
]);
Http::assertNothingSent();
}
public function test_patient_queue_shows_call_next_not_service_counter_panel(): void
{
$this->fakeQueueApi();
$this->organization->update([
'settings' => array_merge($this->organization->settings ?? [], [
'department_queue_provisioning' => [
CareQueueContexts::CONSULTATION => [
'queues' => [[
'branch_id' => $this->branch->id,
'branch_name' => 'Main',
'name' => 'Consultation',
'prefix' => 'C',
'active' => true,
'synced' => true,
'queue_uuid' => 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa',
'counter_uuid' => 'cccccccc-cccc-cccc-cccc-cccccccccccc',
]],
],
],
]),
]);
Http::fake();
$this->actingAs($this->owner)
->get(route('care.queue.index'))
@@ -396,6 +322,7 @@ class CareQueueWorkflowTest extends TestCase
->assertDontSee('Service counter')
->assertSee('Call next')
->assertSee('assigned service point', false);
Http::assertNothingSent();
}
public function test_integration_off_hides_queue_ops_on_pharmacy_page(): void
+78 -186
View File
@@ -5,6 +5,9 @@ namespace Tests\Feature;
use App\Http\Middleware\EnsurePlatformSession;
use App\Models\Appointment;
use App\Models\Branch;
use App\Models\CareQueueTicket;
use App\Models\CareServicePoint;
use App\Models\CareServiceQueue;
use App\Models\Member;
use App\Models\Organization;
use App\Models\Patient;
@@ -38,11 +41,6 @@ class CareServicePointRoutingTest extends TestCase
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' => 'sp-care-owner',
'name' => 'Owner',
@@ -97,101 +95,11 @@ class CareServicePointRoutingTest extends TestCase
'user_ref' => 'doc-okai',
'is_active' => true,
]);
$settings = $this->organization->settings;
$settings['department_queue_provisioning'] = [
CareQueueContexts::CONSULTATION => [
'queues' => [[
'branch_id' => $this->branch->id,
'branch_name' => 'Main',
'name' => 'Consultation',
'prefix' => 'C',
'active' => true,
'synced' => true,
'routing_mode' => 'assigned_only',
'queue_uuid' => 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa',
'queue_external_key' => CareQueueContexts::queueExternalKey(CareQueueContexts::CONSULTATION, $this->branch->id),
'points' => [
[
'kind' => 'practitioner',
'ref_id' => $this->doctorA->id,
'name' => 'Dr. Mensah',
'destination' => 'Consultation Room 4',
'staff_display_name' => 'Dr. Mensah',
'external_key' => CareQueueContexts::pointExternalKey(
CareQueueContexts::CONSULTATION,
$this->branch->id,
'practitioner',
$this->doctorA->id,
),
'counter_uuid' => '11111111-1111-1111-1111-111111111111',
'synced' => true,
],
[
'kind' => 'practitioner',
'ref_id' => $this->doctorB->id,
'name' => 'Dr. Okai',
'destination' => 'Consultation Room 5',
'staff_display_name' => 'Dr. Okai',
'external_key' => CareQueueContexts::pointExternalKey(
CareQueueContexts::CONSULTATION,
$this->branch->id,
'practitioner',
$this->doctorB->id,
),
'counter_uuid' => '22222222-2222-2222-2222-222222222222',
'synced' => true,
],
],
]],
],
CareQueueContexts::PHARMACY => [
'queues' => [[
'branch_id' => $this->branch->id,
'name' => 'Pharmacy',
'prefix' => 'P',
'active' => true,
'synced' => true,
'routing_mode' => 'assigned_only',
'queue_uuid' => 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb',
'points' => [[
'kind' => 'member',
'ref_id' => 1,
'destination' => 'Pharmacy counter 1',
'counter_uuid' => '33333333-3333-3333-3333-333333333333',
'synced' => true,
]],
]],
],
];
$this->organization->update(['settings' => $settings]);
}
public function test_fixed_doctor_appointment_issues_to_that_doctors_point(): void
{
Http::fake(function (\Illuminate\Http\Client\Request $request) {
if ($request->method() === 'POST' && str_contains($request->url(), '/tickets')) {
$this->assertSame('11111111-1111-1111-1111-111111111111', $request['assigned_counter_id'] ?? null);
$this->assertSame('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', $request['service_queue_id'] ?? null);
return Http::response([
'data' => [
'uuid' => (string) Str::uuid(),
'ticket_number' => 'C001',
'status' => 'waiting',
'destination' => 'Consultation Room 4',
'staff_display_name' => 'Dr. Mensah',
'assigned_counter' => [
'uuid' => '11111111-1111-1111-1111-111111111111',
'destination' => 'Consultation Room 4',
'staff_display_name' => 'Dr. Mensah',
],
],
], 201);
}
return Http::response(['message' => 'unexpected'], 500);
});
Http::fake();
$patient = Patient::create([
'uuid' => (string) Str::uuid(),
@@ -217,14 +125,22 @@ class CareServicePointRoutingTest extends TestCase
$result = app(AppointmentService::class)->checkIn($appointment, $this->owner->public_id);
$point = CareServicePoint::query()
->where('organization_id', $this->organization->id)
->where('kind', 'practitioner')
->where('ref_id', $this->doctorA->id)
->first();
$this->assertNotNull($point);
$this->assertSame('C001', $result->queue_ticket_number);
$this->assertSame('11111111-1111-1111-1111-111111111111', $result->queue_service_point_uuid);
$this->assertSame($point->uuid, $result->queue_service_point_uuid);
$this->assertSame('Consultation Room 4', $result->queue_destination);
$this->assertSame('Dr. Mensah', $result->queue_staff_display_name);
$this->assertSame(CareQueueContexts::ROUTING_ROUTED, $result->queue_routing_status);
Http::assertNothingSent();
}
public function test_walk_in_without_doctor_flags_unresolved_and_does_not_issue(): void
public function test_walk_in_without_doctor_routes_to_default_desk(): void
{
Http::fake();
@@ -252,31 +168,19 @@ class CareServicePointRoutingTest extends TestCase
$result = app(CareQueueBridge::class)->issueForAppointment($this->organization, $appointment);
$this->assertNull($result->queue_ticket_uuid);
$this->assertSame(CareQueueContexts::ROUTING_UNRESOLVED, $result->queue_routing_status);
// Native engine prefers an available desk over leaving waiters without a ticket.
$this->assertNotNull($result->queue_ticket_uuid);
$this->assertSame(CareQueueContexts::ROUTING_ROUTED, $result->queue_routing_status);
$this->assertDatabaseHas('care_queue_tickets', [
'uuid' => $result->queue_ticket_uuid,
'status' => CareQueueTicket::STATUS_WAITING,
]);
Http::assertNothingSent();
}
public function test_walk_in_with_selected_doctor_routes_only_to_that_point(): void
{
Http::fake(function (\Illuminate\Http\Client\Request $request) {
if ($request->method() === 'POST' && str_contains($request->url(), '/tickets')) {
$this->assertSame('22222222-2222-2222-2222-222222222222', $request['assigned_counter_id'] ?? null);
return Http::response([
'data' => [
'uuid' => (string) Str::uuid(),
'ticket_number' => 'C002',
'status' => 'waiting',
'assigned_counter' => ['uuid' => '22222222-2222-2222-2222-222222222222'],
'destination' => 'Consultation Room 5',
'staff_display_name' => 'Dr. Okai',
],
], 201);
}
return Http::response(['message' => 'unexpected'], 500);
});
Http::fake();
$patient = Patient::create([
'uuid' => (string) Str::uuid(),
@@ -300,13 +204,24 @@ class CareServicePointRoutingTest extends TestCase
$this->owner->public_id,
);
$point = CareServicePoint::query()
->where('organization_id', $this->organization->id)
->where('kind', 'practitioner')
->where('ref_id', $this->doctorB->id)
->first();
$this->assertSame($this->doctorB->id, $appointment->practitioner_id);
$this->assertSame('C002', $appointment->queue_ticket_number);
$this->assertSame('C001', $appointment->queue_ticket_number);
$this->assertSame('Consultation Room 5', $appointment->queue_destination);
$this->assertNotNull($point);
$this->assertSame($point->uuid, $appointment->queue_service_point_uuid);
Http::assertNothingSent();
}
public function test_pharmacist_call_next_uses_pharmacy_point(): void
{
Http::fake();
$pharmacist = Member::create([
'owner_ref' => $this->owner->public_id,
'organization_id' => $this->organization->id,
@@ -315,33 +230,34 @@ class CareServicePointRoutingTest extends TestCase
'branch_id' => $this->branch->id,
]);
$settings = $this->organization->settings;
$settings['department_queue_provisioning'][CareQueueContexts::PHARMACY]['queues'][0]['points'] = [[
'kind' => 'member',
'ref_id' => $pharmacist->id,
'destination' => 'Pharmacy counter 1',
'staff_ref' => 'pharm-1',
'counter_uuid' => '33333333-3333-3333-3333-333333333333',
'synced' => true,
]];
$this->organization->update(['settings' => $settings]);
app(CareQueueProvisioner::class)->ensure(
$this->organization->fresh(),
CareQueueContexts::PHARMACY,
$this->branch->id,
);
Http::fake(function (\Illuminate\Http\Client\Request $request) {
if (str_contains($request->url(), '/call-next')) {
$this->assertStringContainsString('bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb', $request->url());
$this->assertSame('33333333-3333-3333-3333-333333333333', $request['counter_id'] ?? null);
$queue = CareServiceQueue::query()
->where('organization_id', $this->organization->id)
->where('context', CareQueueContexts::PHARMACY)
->where('branch_id', $this->branch->id)
->firstOrFail();
return Http::response([
'data' => [
'uuid' => (string) Str::uuid(),
'ticket_number' => 'P001',
'status' => 'called',
],
], 200);
}
$point = CareServicePoint::query()
->where('service_queue_id', $queue->id)
->where('kind', 'member')
->where('ref_id', $pharmacist->id)
->firstOrFail();
return Http::response(['message' => 'unexpected'], 500);
});
CareQueueTicket::create([
'owner_ref' => $this->owner->public_id,
'organization_id' => $this->organization->id,
'service_queue_id' => $queue->id,
'service_point_id' => $point->id,
'ticket_number' => 'P001',
'status' => CareQueueTicket::STATUS_WAITING,
'priority' => 'walk_in',
'customer_name' => 'Pharmacy Patient',
]);
$result = app(CareQueueBridge::class)->callNext(
$this->organization->fresh(),
@@ -351,6 +267,9 @@ class CareServicePointRoutingTest extends TestCase
);
$this->assertSame('P001', $result['ticket']['ticket_number'] ?? null);
$this->assertSame('called', $result['ticket']['status'] ?? null);
$this->assertSame($point->uuid, $result['ticket']['assigned_counter']['uuid'] ?? null);
Http::assertNothingSent();
}
public function test_integration_off_preserves_behavior_without_ticket_issuance(): void
@@ -391,57 +310,30 @@ class CareServicePointRoutingTest extends TestCase
public function test_provisioner_builds_one_point_per_practitioner_idempotently(): void
{
$calls = ['queues' => 0, 'counters' => 0];
Http::fake(function (\Illuminate\Http\Client\Request $request) use (&$calls) {
if (str_contains($request->url(), '/integrations/status')) {
return Http::response(['data' => ['provisioned' => true, 'integrations' => ['care' => true]]], 200);
}
if (str_contains($request->url(), '/branches') && $request->method() === 'POST') {
return Http::response(['data' => ['name' => 'Main']], 201);
}
if (str_contains($request->url(), '/departments') && $request->method() === 'POST') {
return Http::response(['data' => ['id' => 9, 'name' => $request['name'] ?? 'Dept']], 201);
}
if (str_contains($request->url(), '/queues') && $request->method() === 'POST' && ! str_contains($request->url(), 'call-next')) {
$calls['queues']++;
$this->assertSame('assigned_only', $request['routing_mode'] ?? null);
return Http::response([
'data' => [
'uuid' => (string) Str::uuid(),
'name' => $request['name'] ?? 'Q',
'external_key' => $request['external_key'] ?? null,
],
], 201);
}
if (str_contains($request->url(), '/counters') && $request->method() === 'POST') {
$calls['counters']++;
return Http::response([
'data' => [
'uuid' => (string) Str::uuid(),
'name' => $request['name'] ?? 'C',
'destination' => $request['destination'] ?? null,
],
], 201);
}
return Http::response(['message' => 'unexpected '.$request->url()], 500);
});
// Clear prior stub so provisioner builds fresh.
$settings = $this->organization->settings;
unset($settings['department_queue_provisioning']);
$this->organization->update(['settings' => $settings]);
Http::fake();
app(CareQueueProvisioner::class)->provisionOrganization($this->organization->fresh());
$first = data_get($this->organization->fresh()->settings, 'department_queue_provisioning.consultation.queues.0.points');
$this->assertIsArray($first);
$this->assertGreaterThanOrEqual(2, count($first));
$this->assertDatabaseHas('care_service_queues', [
'organization_id' => $this->organization->id,
'branch_id' => $this->branch->id,
'context' => CareQueueContexts::CONSULTATION,
]);
$this->assertEquals(
2,
CareServicePoint::query()
->where('organization_id', $this->organization->id)
->where('kind', 'practitioner')
->whereIn('ref_id', [$this->doctorA->id, $this->doctorB->id])
->count(),
);
app(CareQueueProvisioner::class)->provisionOrganization($this->organization->fresh());
$second = data_get($this->organization->fresh()->settings, 'department_queue_provisioning.consultation.queues.0.points');
$this->assertCount(count($first), $second);
Http::assertNothingSent();
}
}
@@ -30,7 +30,6 @@ class CareSpecialtyClinicalTest extends TestCase
{
parent::setUp();
$this->withoutMiddleware(EnsurePlatformSession::class);
config(['care.queue.driver' => 'native']);
$this->owner = User::create([
'public_id' => 'clinical-owner',
+42 -88
View File
@@ -4,6 +4,7 @@ namespace Tests\Feature;
use App\Http\Middleware\EnsurePlatformSession;
use App\Models\Branch;
use App\Models\CareServiceQueue;
use App\Models\Department;
use App\Models\Member;
use App\Models\Organization;
@@ -85,12 +86,9 @@ class CareSpecialtyModulesTest extends TestCase
$this->assertSame($this->branch->id, $stubs[0]['branch_id']);
}
public function test_activating_with_queue_integration_creates_real_counters(): void
public function test_activating_with_queue_integration_creates_native_service_queues(): void
{
config([
'care.queue.api_url' => 'https://queue.test/api/v1',
'care.queue.api_key' => 'care-test-key',
]);
Http::fake();
$this->organization->update([
'settings' => array_merge($this->organization->settings ?? [], [
@@ -98,37 +96,6 @@ class CareSpecialtyModulesTest extends TestCase
]),
]);
$queueUuid = 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa';
$counterUuid = 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb';
Http::fake([
'https://queue.test/api/v1/integrations/status*' => Http::response([
'data' => [
'provisioned' => true,
'integrations' => ['care' => true],
],
], 200),
'https://queue.test/api/v1/branches*' => Http::sequence()
->push(['data' => ['id' => 1, 'name' => 'Main', 'is_active' => true]], 200)
->push(['data' => ['id' => 1, 'name' => 'Main', 'is_active' => true]], 200),
'https://queue.test/api/v1/queues*' => Http::response([
'data' => [
'uuid' => $queueUuid,
'name' => 'Dentistry',
'prefix' => 'DEN',
'external_key' => 'care:specialty:dentistry:queue:'.$this->branch->id,
],
], 201),
'https://queue.test/api/v1/counters*' => Http::response([
'data' => [
'uuid' => $counterUuid,
'name' => 'Dentistry counter',
'branch' => 'Main',
'queues' => [['uuid' => $queueUuid, 'name' => 'Dentistry']],
],
], 201),
]);
app(SpecialtyModuleService::class)->activate(
$this->organization->fresh(),
$this->owner->public_id,
@@ -138,69 +105,47 @@ class CareSpecialtyModulesTest extends TestCase
$this->organization->refresh();
$stub = data_get($this->organization->settings, 'specialty_module_provisioning.dentistry.queues.0');
$this->assertTrue((bool) ($stub['synced'] ?? false));
$this->assertSame($queueUuid, $stub['queue_uuid'] ?? null);
$this->assertSame($counterUuid, $stub['counter_uuid'] ?? null);
$this->assertNotEmpty($stub['queue_uuid'] ?? null);
$this->assertNotEmpty($stub['counter_uuid'] ?? null);
Http::assertSent(function ($request) {
return $request->method() === 'POST'
&& str_contains($request->url(), '/queues')
&& ($request['external_key'] ?? null) === 'care:specialty:dentistry:queue:'.$this->branch->id;
});
$this->assertDatabaseHas('care_service_queues', [
'organization_id' => $this->organization->id,
'branch_id' => $this->branch->id,
'context' => 'dentistry',
'uuid' => $stub['queue_uuid'],
]);
Http::assertNothingSent();
}
public function test_reactivation_is_idempotent_for_queue_external_keys(): void
{
config([
'care.queue.api_url' => 'https://queue.test/api/v1',
'care.queue.api_key' => 'care-test-key',
]);
Http::fake();
$this->organization->update([
'settings' => array_merge($this->organization->settings ?? [], [
'queue_integration_enabled' => true,
'specialty_module_provisioning' => [
'dentistry' => [
'active' => false,
'queues' => [[
'module' => 'dentistry',
'branch_id' => $this->branch->id,
'branch_name' => 'Main',
'name' => 'Dentistry',
'prefix' => 'DEN',
'active' => false,
'synced' => true,
'queue_uuid' => 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa',
'counter_uuid' => 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb',
'queue_external_key' => 'care:specialty:dentistry:queue:'.$this->branch->id,
'counter_external_key' => 'care:specialty:dentistry:counter:'.$this->branch->id,
]],
],
],
]),
]);
Http::fake([
'https://queue.test/api/v1/integrations/status*' => Http::response([
'data' => ['provisioned' => true, 'integrations' => ['care' => true]],
], 200),
'https://queue.test/api/v1/branches*' => Http::response([
'data' => ['id' => 1, 'name' => 'Main', 'is_active' => true],
], 200),
'https://queue.test/api/v1/queues*' => Http::response([
'data' => [
'uuid' => 'aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa',
'name' => 'Dentistry',
'external_key' => 'care:specialty:dentistry:queue:'.$this->branch->id,
],
], 200),
'https://queue.test/api/v1/counters*' => Http::response([
'data' => [
'uuid' => 'bbbbbbbb-bbbb-bbbb-bbbb-bbbbbbbbbbbb',
'name' => 'Dentistry counter',
],
], 200),
]);
app(SpecialtyModuleService::class)->activate(
$this->organization->fresh(),
$this->owner->public_id,
'dentistry',
);
$firstQueue = CareServiceQueue::query()
->where('organization_id', $this->organization->id)
->where('context', 'dentistry')
->where('branch_id', $this->branch->id)
->firstOrFail();
$firstUuid = $firstQueue->uuid;
$externalKey = $firstQueue->external_key;
app(SpecialtyModuleService::class)->deactivate(
$this->organization->fresh(),
$this->owner->public_id,
'dentistry',
);
app(SpecialtyModuleService::class)->activate(
$this->organization->fresh(),
$this->owner->public_id,
@@ -209,8 +154,17 @@ class CareSpecialtyModulesTest extends TestCase
$this->organization->refresh();
$stub = data_get($this->organization->settings, 'specialty_module_provisioning.dentistry.queues.0');
$this->assertSame('care:specialty:dentistry:queue:'.$this->branch->id, $stub['queue_external_key']);
$this->assertSame('aaaaaaaa-aaaa-aaaa-aaaa-aaaaaaaaaaaa', $stub['queue_uuid']);
$this->assertSame($externalKey, $stub['queue_external_key'] ?? $firstQueue->external_key);
$this->assertSame($firstUuid, $stub['queue_uuid'] ?? null);
$this->assertEquals(
1,
CareServiceQueue::query()
->where('organization_id', $this->organization->id)
->where('context', 'dentistry')
->where('branch_id', $this->branch->id)
->count(),
);
Http::assertNothingSent();
}
public function test_deactivating_hides_department_without_deleting(): void
-2
View File
@@ -32,8 +32,6 @@ class CareSpecialtyShellTest extends TestCase
parent::setUp();
$this->withoutMiddleware(EnsurePlatformSession::class);
config(['care.queue.driver' => 'native']);
$this->owner = User::create([
'public_id' => 'shell-owner',
'name' => 'Owner',