Files
ladill-queue/tests/Feature/TicketTransferProTest.php
T
isaaccladandCursor b208e59bd0
Deploy Ladill Queue / deploy (push) Successful in 3m12s
Strip healthcare packaging and Care integration from Queue.
Queue is general-purpose QMS only; Care runs its own native engine.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-18 10:15:32 +00:00

161 lines
5.3 KiB
PHP

<?php
namespace Tests\Feature;
use App\Http\Middleware\EnsurePlatformSession;
use App\Models\Branch;
use App\Models\Counter;
use App\Models\ServiceQueue;
use App\Models\Ticket;
use App\Models\User;
use App\Services\Qms\OrganizationResolver;
use App\Services\Qms\QueueEngine;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class TicketTransferProTest extends TestCase
{
use RefreshDatabase;
protected User $owner;
protected \App\Models\Organization $organization;
protected Branch $branch;
protected ServiceQueue $queue;
protected ServiceQueue $lab;
protected Counter $counter;
protected Ticket $ticket;
protected function setUp(): void
{
parent::setUp();
$this->withoutMiddleware(EnsurePlatformSession::class);
$this->owner = User::create([
'public_id' => 'queue-transfer-owner-001',
'name' => 'Owner',
'email' => 'transfer-owner@example.com',
'password' => bcrypt('password'),
]);
$this->organization = app(OrganizationResolver::class)->completeOnboarding($this->owner, [
'organization_name' => 'Transfer Org',
'industry' => 'banking',
'appointment_mode' => 'hybrid',
'branch_name' => 'Main',
'timezone' => 'UTC',
]);
$this->branch = Branch::query()->where('organization_id', $this->organization->id)->firstOrFail();
$this->queue = ServiceQueue::create([
'owner_ref' => $this->owner->public_id,
'organization_id' => $this->organization->id,
'branch_id' => $this->branch->id,
'name' => 'Consultation',
'prefix' => 'A',
'strategy' => 'fifo',
'is_active' => true,
]);
$this->lab = ServiceQueue::create([
'owner_ref' => $this->owner->public_id,
'organization_id' => $this->organization->id,
'branch_id' => $this->branch->id,
'name' => 'Lab',
'prefix' => 'L',
'strategy' => 'fifo',
'is_active' => true,
]);
$this->counter = Counter::create([
'owner_ref' => $this->owner->public_id,
'organization_id' => $this->organization->id,
'branch_id' => $this->branch->id,
'name' => 'Desk 1',
'status' => 'available',
'is_active' => true,
]);
$this->counter->serviceQueues()->attach($this->queue->id);
$engine = app(QueueEngine::class);
$this->ticket = $engine->issueTicket($this->queue, $this->owner->public_id, ['source' => 'staff']);
$engine->callTicket($this->ticket, $this->counter, $this->owner->public_id);
$engine->startServing($this->ticket->fresh(), $this->owner->public_id);
$this->ticket = $this->ticket->fresh();
}
public function test_free_console_shows_transfer_as_pro_feature(): void
{
$this->actingAs($this->owner)
->get(route('qms.console.show', $this->counter))
->assertOk()
->assertSee('Hand off to another queue')
->assertSee('Pro')
->assertSee('Upgrade to Pro')
->assertDontSee('name="action" value="transfer"', false);
}
public function test_free_plan_cannot_transfer_via_console(): void
{
$this->actingAs($this->owner)
->post(route('qms.console.action', $this->counter), [
'action' => 'transfer',
'ticket_id' => $this->ticket->id,
'to_queue_id' => $this->lab->id,
'reason' => 'Lab tests',
])
->assertRedirect(route('qms.pro.index'))
->assertSessionHas('error');
$this->assertSame($this->queue->id, $this->ticket->fresh()->service_queue_id);
}
public function test_pro_plan_can_transfer_via_console(): void
{
$this->organization->update([
'settings' => array_merge($this->organization->settings ?? [], [
'plan' => 'pro',
'plan_expires_at' => now()->addMonth()->toIso8601String(),
'pro_billed_branches' => 1,
]),
]);
$this->actingAs($this->owner)
->post(route('qms.console.action', $this->counter), [
'action' => 'transfer',
'ticket_id' => $this->ticket->id,
'to_queue_id' => $this->lab->id,
'reason' => 'Lab tests',
])
->assertRedirect()
->assertSessionHas('success');
$this->assertSame($this->lab->id, $this->ticket->fresh()->service_queue_id);
$this->assertSame('waiting', $this->ticket->fresh()->status);
}
public function test_pro_console_shows_handoff_form(): void
{
$this->organization->update([
'settings' => array_merge($this->organization->settings ?? [], [
'plan' => 'pro',
'plan_expires_at' => now()->addMonth()->toIso8601String(),
'pro_billed_branches' => 1,
]),
]);
$this->actingAs($this->owner)
->get(route('qms.console.show', $this->counter))
->assertOk()
->assertSee('Hand off')
->assertSee('Lab')
->assertDontSee('Upgrade to Pro →');
}
}