Deploy Ladill Queue / deploy (push) Successful in 1m0s
Specialty module activation needs idempotent queue/counter upserts (by external_key or name+branch) plus soft deactivate, without opening Queue admin for each Care specialty. Co-authored-by: Cursor <cursoragent@cursor.com>
212 lines
7.3 KiB
PHP
212 lines
7.3 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\Branch;
|
|
use App\Models\Counter;
|
|
use App\Models\Organization;
|
|
use App\Models\ServiceQueue;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Tests\TestCase;
|
|
|
|
class CareIntegrationTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
protected function careHeaders(string $owner = 'care-owner-uuid'): array
|
|
{
|
|
config(['qms.service_api_keys.care' => 'test-care-key']);
|
|
|
|
return [
|
|
'Authorization' => 'Bearer test-care-key',
|
|
'Accept' => 'application/json',
|
|
];
|
|
}
|
|
|
|
protected function provisionCareOrg(string $owner = 'care-owner-uuid'): Organization
|
|
{
|
|
$this->postJson('/api/v1/integrations/provision', [
|
|
'owner' => $owner,
|
|
'organization_name' => 'Care Clinic',
|
|
'branch_name' => 'Main',
|
|
], $this->careHeaders($owner))->assertSuccessful();
|
|
|
|
return Organization::owned($owner)->firstOrFail();
|
|
}
|
|
|
|
public function test_provision_enables_care_integration(): void
|
|
{
|
|
$owner = 'care-owner-uuid';
|
|
|
|
$this->postJson('/api/v1/integrations/provision', [
|
|
'owner' => $owner,
|
|
'organization_name' => 'Care Clinic',
|
|
'branch_name' => 'Main',
|
|
], $this->careHeaders($owner))
|
|
->assertCreated()
|
|
->assertJsonPath('data.integrations.care', true);
|
|
|
|
$organization = Organization::owned($owner)->first();
|
|
$this->assertTrue((bool) data_get($organization->settings, 'integrations.care_enabled'));
|
|
}
|
|
|
|
public function test_counters_allowed_after_care_provision(): void
|
|
{
|
|
$owner = 'care-owner-uuid';
|
|
$headers = $this->careHeaders($owner);
|
|
|
|
$this->provisionCareOrg($owner);
|
|
|
|
$this->getJson('/api/v1/counters?owner='.$owner, $headers)
|
|
->assertOk();
|
|
}
|
|
|
|
public function test_counter_console_resolves_by_uuid(): void
|
|
{
|
|
$owner = 'care-owner-uuid';
|
|
$headers = $this->careHeaders($owner);
|
|
$organization = $this->provisionCareOrg($owner);
|
|
$branch = Branch::owned($owner)->where('organization_id', $organization->id)->firstOrFail();
|
|
$queue = ServiceQueue::create([
|
|
'owner_ref' => $owner,
|
|
'organization_id' => $organization->id,
|
|
'branch_id' => $branch->id,
|
|
'name' => 'Morning Shift',
|
|
'prefix' => 'A',
|
|
'strategy' => 'fifo',
|
|
'is_active' => true,
|
|
]);
|
|
$counter = Counter::create([
|
|
'owner_ref' => $owner,
|
|
'organization_id' => $organization->id,
|
|
'branch_id' => $branch->id,
|
|
'name' => 'Counter 1',
|
|
'code' => 'C001',
|
|
'status' => 'available',
|
|
'is_active' => true,
|
|
]);
|
|
$counter->serviceQueues()->sync([$queue->id]);
|
|
|
|
$this->getJson('/api/v1/counters/'.$counter->uuid.'/console?owner='.$owner, $headers)
|
|
->assertOk()
|
|
->assertJsonPath('data.counter.uuid', $counter->uuid);
|
|
}
|
|
|
|
public function test_queue_models_use_uuid_route_key(): void
|
|
{
|
|
$this->assertSame('uuid', (new Counter)->getRouteKeyName());
|
|
$this->assertSame('uuid', (new ServiceQueue)->getRouteKeyName());
|
|
}
|
|
|
|
public function test_care_can_create_queue_and_counter_idempotently(): void
|
|
{
|
|
$owner = 'care-owner-uuid';
|
|
$headers = $this->careHeaders($owner);
|
|
$this->provisionCareOrg($owner);
|
|
|
|
$queueResponse = $this->postJson('/api/v1/queues', [
|
|
'owner' => $owner,
|
|
'name' => 'Dentistry',
|
|
'prefix' => 'DEN',
|
|
'branch_name' => 'Main',
|
|
'external_key' => 'care:specialty:dentistry:queue:1',
|
|
'strategy' => 'fifo',
|
|
], $headers)
|
|
->assertCreated()
|
|
->assertJsonPath('data.name', 'Dentistry')
|
|
->assertJsonPath('data.external_key', 'care:specialty:dentistry:queue:1');
|
|
|
|
$queueUuid = $queueResponse->json('data.uuid');
|
|
|
|
$this->postJson('/api/v1/queues', [
|
|
'owner' => $owner,
|
|
'name' => 'Dentistry Desk',
|
|
'prefix' => 'DEN',
|
|
'branch_name' => 'Main',
|
|
'external_key' => 'care:specialty:dentistry:queue:1',
|
|
'strategy' => 'fifo',
|
|
], $headers)
|
|
->assertOk()
|
|
->assertJsonPath('data.uuid', $queueUuid)
|
|
->assertJsonPath('data.name', 'Dentistry Desk');
|
|
|
|
$this->assertSame(1, ServiceQueue::owned($owner)->count());
|
|
|
|
$counterResponse = $this->postJson('/api/v1/counters', [
|
|
'owner' => $owner,
|
|
'name' => 'Dentistry counter',
|
|
'branch_name' => 'Main',
|
|
'queue_uuids' => [$queueUuid],
|
|
'external_key' => 'care:specialty:dentistry:counter:1',
|
|
], $headers)
|
|
->assertCreated()
|
|
->assertJsonPath('data.name', 'Dentistry counter')
|
|
->assertJsonPath('data.branch', 'Main')
|
|
->assertJsonPath('data.queues.0.uuid', $queueUuid);
|
|
|
|
$counterUuid = $counterResponse->json('data.uuid');
|
|
|
|
$this->postJson('/api/v1/counters', [
|
|
'owner' => $owner,
|
|
'name' => 'Dentistry counter',
|
|
'branch_name' => 'Main',
|
|
'queue_uuids' => [$queueUuid],
|
|
'external_key' => 'care:specialty:dentistry:counter:1',
|
|
], $headers)
|
|
->assertOk()
|
|
->assertJsonPath('data.uuid', $counterUuid);
|
|
|
|
$this->assertSame(1, Counter::owned($owner)->count());
|
|
|
|
$this->getJson('/api/v1/counters?owner='.$owner, $headers)
|
|
->assertOk()
|
|
->assertJsonPath('data.0.uuid', $counterUuid)
|
|
->assertJsonPath('data.0.branch', 'Main')
|
|
->assertJsonPath('data.0.queues.0.name', 'Dentistry Desk');
|
|
}
|
|
|
|
public function test_care_can_soft_deactivate_counter(): void
|
|
{
|
|
$owner = 'care-owner-uuid';
|
|
$headers = $this->careHeaders($owner);
|
|
$organization = $this->provisionCareOrg($owner);
|
|
$branch = Branch::owned($owner)->where('organization_id', $organization->id)->firstOrFail();
|
|
$counter = Counter::create([
|
|
'owner_ref' => $owner,
|
|
'organization_id' => $organization->id,
|
|
'branch_id' => $branch->id,
|
|
'name' => 'Eye care counter',
|
|
'status' => 'offline',
|
|
'is_active' => true,
|
|
]);
|
|
|
|
$this->patchJson('/api/v1/counters/'.$counter->uuid, [
|
|
'owner' => $owner,
|
|
'is_active' => false,
|
|
], $headers)
|
|
->assertOk()
|
|
->assertJsonPath('data.is_active', false);
|
|
|
|
$this->assertFalse($counter->fresh()->is_active);
|
|
$this->assertDatabaseHas('queue_counters', ['id' => $counter->id]);
|
|
}
|
|
|
|
public function test_care_can_ensure_branch_by_name_idempotently(): void
|
|
{
|
|
$owner = 'care-owner-uuid';
|
|
$headers = $this->careHeaders($owner);
|
|
$this->provisionCareOrg($owner);
|
|
|
|
// Free plan is capped at 1 branch; provision already created Main — upsert must not duplicate.
|
|
$this->postJson('/api/v1/branches', [
|
|
'owner' => $owner,
|
|
'name' => 'Main',
|
|
], $headers)
|
|
->assertOk()
|
|
->assertJsonPath('data.name', 'Main')
|
|
->assertJsonPath('data.is_active', true);
|
|
|
|
$this->assertSame(1, Branch::owned($owner)->count());
|
|
}
|
|
}
|