Add industry packages that provision workflow stages on onboarding.
Deploy Ladill Queue / deploy (push) Successful in 1m39s
Deploy Ladill Queue / deploy (push) Successful in 1m39s
Queue Core stays generic; selecting Healthcare, Banking, Restaurant, and other industries installs departments, stages (queues), service points, workflows, terminology, and announcement profiles without code changes per vertical. Care-linked orgs skip stage materialization so Care remains the clinical provisioner. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -33,21 +33,32 @@ class DisplayVoiceTest extends TestCase
|
||||
$resolver = app(OrganizationResolver::class);
|
||||
$org = $resolver->completeOnboarding($user, [
|
||||
'organization_name' => 'Test Org',
|
||||
'industry' => 'retail',
|
||||
'industry' => 'custom',
|
||||
'appointment_mode' => 'hybrid',
|
||||
'branch_name' => 'Main',
|
||||
'timezone' => 'UTC',
|
||||
]);
|
||||
$branch = Branch::first();
|
||||
$queue = ServiceQueue::create([
|
||||
'owner_ref' => $user->public_id,
|
||||
'organization_id' => $org->id,
|
||||
'branch_id' => $branch->id,
|
||||
'name' => 'Reception',
|
||||
'prefix' => 'A',
|
||||
'strategy' => 'fifo',
|
||||
'is_active' => true,
|
||||
]);
|
||||
$queue = ServiceQueue::query()
|
||||
->where('organization_id', $org->id)
|
||||
->where('branch_id', $branch->id)
|
||||
->orderBy('id')
|
||||
->first();
|
||||
|
||||
if (! $queue) {
|
||||
$queue = ServiceQueue::create([
|
||||
'owner_ref' => $user->public_id,
|
||||
'organization_id' => $org->id,
|
||||
'branch_id' => $branch->id,
|
||||
'name' => 'Reception',
|
||||
'prefix' => 'A',
|
||||
'strategy' => 'fifo',
|
||||
'is_active' => true,
|
||||
]);
|
||||
} else {
|
||||
$queue->update(['name' => 'Reception', 'prefix' => 'A']);
|
||||
$queue = $queue->fresh();
|
||||
}
|
||||
|
||||
return [$user, $org, $branch, $queue];
|
||||
}
|
||||
|
||||
@@ -0,0 +1,209 @@
|
||||
<?php
|
||||
|
||||
namespace Tests\Feature;
|
||||
|
||||
use App\Models\Branch;
|
||||
use App\Models\Counter;
|
||||
use App\Models\ServiceQueue;
|
||||
use App\Models\User;
|
||||
use App\Models\Workflow;
|
||||
use App\Services\Qms\Industry\IndustryPackageInstaller;
|
||||
use App\Services\Qms\Industry\IndustryPackageRegistry;
|
||||
use App\Services\Qms\OrganizationResolver;
|
||||
use App\Services\Qms\QueueEngine;
|
||||
use App\Services\Qms\VoiceAnnouncementService;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Tests\TestCase;
|
||||
|
||||
class IndustryPackageTest extends TestCase
|
||||
{
|
||||
use RefreshDatabase;
|
||||
|
||||
public function test_registry_lists_core_packages(): void
|
||||
{
|
||||
$registry = app(IndustryPackageRegistry::class);
|
||||
|
||||
$this->assertTrue($registry->has('healthcare'));
|
||||
$this->assertTrue($registry->has('banking'));
|
||||
$this->assertTrue($registry->has('restaurant'));
|
||||
$this->assertTrue($registry->has('custom'));
|
||||
$this->assertSame('Healthcare', $registry->get('healthcare')->label());
|
||||
$this->assertSame('patient', $registry->get('healthcare')->ticketEntity());
|
||||
$this->assertSame('order', $registry->get('restaurant')->ticketEntity());
|
||||
}
|
||||
|
||||
public function test_onboarding_banking_provisions_stages_and_workflow(): void
|
||||
{
|
||||
$user = User::create([
|
||||
'public_id' => 'pkg-bank-owner',
|
||||
'name' => 'Bank Owner',
|
||||
'email' => 'bank-owner@example.com',
|
||||
'password' => bcrypt('password'),
|
||||
]);
|
||||
|
||||
$org = app(OrganizationResolver::class)->completeOnboarding($user, [
|
||||
'organization_name' => 'Ridge Bank',
|
||||
'industry' => 'banking',
|
||||
'appointment_mode' => 'hybrid',
|
||||
'branch_name' => 'Main Branch',
|
||||
'timezone' => 'UTC',
|
||||
]);
|
||||
|
||||
$this->assertSame('banking', data_get($org->settings, 'industry'));
|
||||
$this->assertSame('banking', data_get($org->settings, 'industry_package.key'));
|
||||
$this->assertSame('customer', data_get($org->settings, 'industry_package.ticket_entity'));
|
||||
|
||||
$branch = Branch::where('organization_id', $org->id)->first();
|
||||
$this->assertNotNull($branch);
|
||||
|
||||
$queues = ServiceQueue::where('organization_id', $org->id)->where('branch_id', $branch->id)->get();
|
||||
$this->assertGreaterThanOrEqual(3, $queues->count());
|
||||
$this->assertTrue($queues->contains(fn (ServiceQueue $q) => $q->prefix === 'T'));
|
||||
|
||||
$teller = $queues->firstWhere('prefix', 'T');
|
||||
$this->assertSame('shared_pool', $teller->routingMode());
|
||||
$this->assertGreaterThanOrEqual(1, $teller->counters()->count());
|
||||
|
||||
$workflow = Workflow::where('organization_id', $org->id)->where('industry_template', 'banking')->first();
|
||||
$this->assertNotNull($workflow);
|
||||
$this->assertGreaterThanOrEqual(3, $workflow->steps()->count());
|
||||
}
|
||||
|
||||
public function test_healthcare_uses_assigned_only_for_consultation(): void
|
||||
{
|
||||
$user = User::create([
|
||||
'public_id' => 'pkg-care-owner',
|
||||
'name' => 'Clinic Owner',
|
||||
'email' => 'clinic-owner@example.com',
|
||||
'password' => bcrypt('password'),
|
||||
]);
|
||||
|
||||
// Pro plan so all healthcare stages fit under queue caps.
|
||||
$org = app(OrganizationResolver::class)->completeOnboarding($user, [
|
||||
'organization_name' => 'Ridge Clinic',
|
||||
'industry' => 'custom',
|
||||
'appointment_mode' => 'hybrid',
|
||||
'branch_name' => 'Main',
|
||||
'timezone' => 'UTC',
|
||||
]);
|
||||
$org->update([
|
||||
'settings' => array_merge($org->settings ?? [], [
|
||||
'plan' => 'pro',
|
||||
'plan_expires_at' => now()->addMonth()->toIso8601String(),
|
||||
]),
|
||||
]);
|
||||
|
||||
$branch = Branch::where('organization_id', $org->id)->first();
|
||||
$result = app(IndustryPackageInstaller::class)->install($org->fresh(), $branch, 'healthcare');
|
||||
|
||||
$this->assertSame('healthcare', $result['package']);
|
||||
$this->assertGreaterThanOrEqual(5, $result['stages']);
|
||||
|
||||
$consultation = ServiceQueue::query()
|
||||
->where('organization_id', $org->id)
|
||||
->where('settings->stage_code', 'consultation')
|
||||
->first();
|
||||
|
||||
$this->assertNotNull($consultation);
|
||||
$this->assertSame('assigned_only', $consultation->routingMode());
|
||||
$this->assertSame('C', $consultation->prefix);
|
||||
}
|
||||
|
||||
public function test_package_install_is_idempotent(): void
|
||||
{
|
||||
$user = User::create([
|
||||
'public_id' => 'pkg-idem-owner',
|
||||
'name' => 'Idem Owner',
|
||||
'email' => 'idem@example.com',
|
||||
'password' => bcrypt('password'),
|
||||
]);
|
||||
|
||||
$org = app(OrganizationResolver::class)->completeOnboarding($user, [
|
||||
'organization_name' => 'Idem Org',
|
||||
'industry' => 'visitor',
|
||||
'appointment_mode' => 'hybrid',
|
||||
'branch_name' => 'Main',
|
||||
'timezone' => 'UTC',
|
||||
]);
|
||||
$branch = Branch::where('organization_id', $org->id)->first();
|
||||
$installer = app(IndustryPackageInstaller::class);
|
||||
|
||||
$first = $installer->install($org, $branch, 'visitor');
|
||||
$second = $installer->install($org->fresh(), $branch, 'visitor');
|
||||
|
||||
$this->assertSame($first['stages'], $second['stages']);
|
||||
$this->assertSame(
|
||||
ServiceQueue::where('organization_id', $org->id)->count(),
|
||||
ServiceQueue::where('organization_id', $org->id)->count(),
|
||||
);
|
||||
$this->assertSame(2, ServiceQueue::where('organization_id', $org->id)->count());
|
||||
}
|
||||
|
||||
public function test_industry_announcement_uses_package_copy(): void
|
||||
{
|
||||
$user = User::create([
|
||||
'public_id' => 'pkg-announce-owner',
|
||||
'name' => 'Announce Owner',
|
||||
'email' => 'announce@example.com',
|
||||
'password' => bcrypt('password'),
|
||||
]);
|
||||
|
||||
$org = app(OrganizationResolver::class)->completeOnboarding($user, [
|
||||
'organization_name' => 'Kitchen Co',
|
||||
'industry' => 'restaurant',
|
||||
'appointment_mode' => 'walk_in_only',
|
||||
'branch_name' => 'Main',
|
||||
'timezone' => 'UTC',
|
||||
]);
|
||||
|
||||
$queue = ServiceQueue::where('organization_id', $org->id)->where('prefix', 'U')->first()
|
||||
?? ServiceQueue::where('organization_id', $org->id)->first();
|
||||
$counter = $queue->counters()->first() ?? Counter::where('organization_id', $org->id)->first();
|
||||
|
||||
$ticket = app(QueueEngine::class)->issueTicket($queue, $user->public_id, [
|
||||
'source' => 'api',
|
||||
'customer_name' => 'Table 4',
|
||||
]);
|
||||
|
||||
$announcement = app(VoiceAnnouncementService::class)->announceCalled($ticket->fresh(['organization', 'serviceQueue']), $counter);
|
||||
|
||||
$this->assertStringContainsString($ticket->ticket_number, $announcement->message);
|
||||
$this->assertTrue(
|
||||
str_contains(strtolower($announcement->message), 'order')
|
||||
|| str_contains(strtolower($announcement->message), 'pickup')
|
||||
|| str_contains($announcement->message, $counter->displayDestination()),
|
||||
);
|
||||
}
|
||||
|
||||
public function test_care_integration_skips_stage_materialization(): void
|
||||
{
|
||||
$user = User::create([
|
||||
'public_id' => 'pkg-care-skip',
|
||||
'name' => 'Care Skip',
|
||||
'email' => 'care-skip@example.com',
|
||||
'password' => bcrypt('password'),
|
||||
]);
|
||||
|
||||
$org = app(OrganizationResolver::class)->completeOnboarding($user, [
|
||||
'organization_name' => 'Care Linked',
|
||||
'industry' => 'custom',
|
||||
'appointment_mode' => 'hybrid',
|
||||
'branch_name' => 'Main',
|
||||
'timezone' => 'UTC',
|
||||
]);
|
||||
$org->update([
|
||||
'settings' => array_merge($org->settings ?? [], [
|
||||
'integrations' => ['care_enabled' => true],
|
||||
]),
|
||||
]);
|
||||
$before = ServiceQueue::where('organization_id', $org->id)->count();
|
||||
$branch = Branch::where('organization_id', $org->id)->first();
|
||||
|
||||
$result = app(IndustryPackageInstaller::class)->install($org->fresh(), $branch, 'healthcare');
|
||||
|
||||
$this->assertSame('stages_managed_by_integration', $result['skipped_reason']);
|
||||
$this->assertSame(0, $result['stages']);
|
||||
$this->assertSame($before, ServiceQueue::where('organization_id', $org->id)->count());
|
||||
$this->assertSame('patient', data_get($org->fresh()->settings, 'industry_package.ticket_entity'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user