Files
ladill-queue/tests/Feature/DemoSeedCommandTest.php
T
isaaccladandCursor 8ff100a55b
Deploy Ladill Queue / deploy (push) Successful in 1m3s
Wire Queue demo seeder to shared DemoWorld
Org name, branches, ticket customers, and staff Members now come from
DemoWorld so Queue continuity matches Care/Frontdesk across the suite.
Also resolve organization by owner_ref when metadata.queue.organization_id
is missing, and skip reseed-on-login for DemoWorld staff emails.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-17 13:35:17 +00:00

129 lines
5.2 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\Branch;
use App\Models\Member;
use App\Models\Organization;
use App\Models\ServiceQueue;
use App\Models\Ticket;
use App\Models\User;
use App\Services\Qms\PlanService;
use App\Support\DemoWorld;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Artisan;
use Tests\TestCase;
class DemoSeedCommandTest extends TestCase
{
use RefreshDatabase;
public function test_free_seed_respects_branch_and_queue_caps(): void
{
$user = User::create([
'public_id' => 'demo-queue-free',
'name' => 'Demo Free',
'email' => 'demo-free@ladill.com',
'password' => bcrypt('password'),
]);
$exit = Artisan::call('demo:seed', ['identity' => $user->email, '--plan' => 'free']);
$this->assertSame(0, $exit);
$org = Organization::owned($user->public_id)->first();
$this->assertNotNull($org);
$this->assertSame('free', app(PlanService::class)->planKey($org));
$this->assertSame(1, Branch::query()->where('organization_id', $org->id)->whereNull('deleted_at')->count());
$this->assertLessThanOrEqual(5, ServiceQueue::query()->where('organization_id', $org->id)->whereNull('deleted_at')->count());
$this->assertGreaterThan(0, Ticket::query()->where('organization_id', $org->id)->whereNull('deleted_at')->count());
$this->assertTrue((bool) data_get($org->settings, 'onboarded'));
}
public function test_pro_seed_is_multi_branch_and_reset_is_tenant_scoped(): void
{
$target = User::create([
'public_id' => 'demo-queue-pro',
'name' => 'Demo Pro',
'email' => 'demo-pro@ladill.com',
'password' => bcrypt('password'),
]);
$other = User::create([
'public_id' => 'other-queue-owner',
'name' => 'Other',
'email' => 'other-queue@example.com',
'password' => bcrypt('password'),
]);
Artisan::call('demo:seed', ['identity' => $other->email, '--plan' => 'free']);
$otherOrgId = Organization::owned($other->public_id)->value('id');
Artisan::call('demo:seed', ['identity' => $target->public_id, '--plan' => 'pro']);
$org = Organization::owned($target->public_id)->first();
$this->assertSame('pro', app(PlanService::class)->planKey($org));
$this->assertGreaterThanOrEqual(2, Branch::query()->where('organization_id', $org->id)->whereNull('deleted_at')->count());
$this->assertGreaterThan(0, \App\Models\QueueRule::query()->where('owner_ref', $target->public_id)->count());
Artisan::call('demo:seed', [
'identity' => $target->email,
'--plan' => 'pro',
'--reset' => true,
]);
$this->assertDatabaseHas('queue_organizations', ['id' => $otherOrgId, 'owner_ref' => $other->public_id]);
$this->assertSame('pro', app(PlanService::class)->planKey(Organization::owned($target->public_id)->first()));
}
public function test_idempotent_without_reset(): void
{
$user = User::create([
'public_id' => 'demo-queue-idem',
'name' => 'Demo',
'email' => 'demo-idem@ladill.com',
'password' => bcrypt('password'),
]);
Artisan::call('demo:seed', ['identity' => $user->email, '--plan' => 'enterprise']);
$org = Organization::owned($user->public_id)->first();
$branches = Branch::query()->where('organization_id', $org->id)->whereNull('deleted_at')->count();
$tickets = Ticket::query()->where('organization_id', $org->id)->whereNull('deleted_at')->count();
Artisan::call('demo:seed', ['identity' => $user->email, '--plan' => 'enterprise']);
$this->assertSame($branches, Branch::query()->where('organization_id', $org->id)->whereNull('deleted_at')->count());
$this->assertSame($tickets, Ticket::query()->where('organization_id', $org->id)->whereNull('deleted_at')->count());
$this->assertSame('enterprise', app(PlanService::class)->planKey($org->fresh()));
}
public function test_demo_world_continuity_and_staff_roles(): void
{
$user = User::create([
'public_id' => 'demo-world-queue-id',
'name' => 'Ladill Demo (Pro)',
'email' => 'demo-pro@ladill.com',
'password' => bcrypt('password'),
]);
$exit = Artisan::call('demo:seed', ['identity' => $user->email, '--plan' => 'pro']);
$this->assertSame(0, $exit);
$org = Organization::owned($user->public_id)->firstOrFail();
$this->assertSame(DemoWorld::business('pro')['name'], $org->name);
$ama = DemoWorld::personByKey('ama-mensah');
$this->assertNotNull($ama);
$this->assertTrue(
Ticket::query()
->where('owner_ref', $user->public_id)
->where('customer_phone', $ama['phone'])
->exists()
);
$this->assertTrue(
Member::query()
->where('owner_ref', $user->public_id)
->where('user_ref', 'demo-pro-receptionist@ladill.com')
->where('role', 'receptionist')
->exists()
);
}
}