Add Queue demo:seed for ticket walkthroughs.
Deploy Ladill Queue / deploy (push) Successful in 1m53s

Seed branches, queues, counters, and tickets with plan-aware limits and reset.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
isaacclad
2026-07-17 10:03:46 +00:00
co-authored by Cursor
parent 17d888fdf7
commit f15857d76f
3 changed files with 787 additions and 0 deletions
+93
View File
@@ -0,0 +1,93 @@
<?php
namespace Tests\Feature;
use App\Models\Branch;
use App\Models\Organization;
use App\Models\ServiceQueue;
use App\Models\Ticket;
use App\Models\User;
use App\Services\Qms\PlanService;
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()));
}
}