Files
ladill-frontdesk/tests/Feature/DemoSeedCommandTest.php
T
isaaccladandCursor 0bdf435328
Deploy Ladill Frontdesk / deploy (push) Successful in 2m6s
Add Frontdesk demo:seed for visitor walkthroughs.
Seed orgs, branches, kiosks, hosts, and visits with plan-aware caps and reset.

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

107 lines
4.4 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\Branch;
use App\Models\Device;
use App\Models\Host;
use App\Models\Organization;
use App\Models\User;
use App\Models\Visit;
use App\Models\Visitor;
use App\Models\WatchlistEntry;
use App\Services\Frontdesk\PlanService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Str;
use Tests\TestCase;
class DemoSeedCommandTest extends TestCase
{
use RefreshDatabase;
public function test_free_plan_caps_branch_and_kiosk_with_visit_history(): void
{
$user = User::create([
'public_id' => (string) Str::uuid(),
'name' => 'Demo Free',
'email' => 'demo-free@ladill.com',
]);
$this->artisan('demo:seed', [
'identity' => $user->email,
'--plan' => 'free',
])->assertSuccessful();
$org = Organization::query()->where('owner_ref', $user->public_id)->firstOrFail();
$this->assertSame('free', app(PlanService::class)->planKey($org));
$this->assertTrue((bool) ($org->settings['onboarded'] ?? false));
$this->assertSame(1, Branch::query()->where('organization_id', $org->id)->count());
$this->assertSame(1, Device::query()->where('organization_id', $org->id)->where('type', 'kiosk')->count());
$this->assertGreaterThan(0, Host::query()->where('organization_id', $org->id)->count());
$this->assertGreaterThan(0, Visitor::query()->where('organization_id', $org->id)->count());
$this->assertSame(40, Visit::query()->where('organization_id', $org->id)->count());
}
public function test_pro_plan_uses_org_settings_and_multi_branch(): void
{
$user = User::create([
'public_id' => (string) Str::uuid(),
'name' => 'Demo Pro',
'email' => 'demo-pro@ladill.com',
]);
$this->artisan('demo:seed', [
'identity' => $user->public_id,
'--plan' => 'pro',
])->assertSuccessful();
$org = Organization::query()->where('owner_ref', $user->public_id)->firstOrFail();
$this->assertSame('pro', app(PlanService::class)->planKey($org));
$this->assertNotEmpty($org->settings['plan_expires_at'] ?? null);
$this->assertGreaterThanOrEqual(3, (int) ($org->settings['billed_branches'] ?? 0));
$this->assertGreaterThan(1, Branch::query()->where('organization_id', $org->id)->count());
$this->assertGreaterThan(1, Device::query()->where('organization_id', $org->id)->where('type', 'kiosk')->count());
$this->assertGreaterThan(40, Visit::query()->where('organization_id', $org->id)->count());
$this->assertGreaterThan(0, WatchlistEntry::query()->where('organization_id', $org->id)->count());
}
public function test_idempotent_and_reset_only_touches_owner_data(): void
{
$user = User::create([
'public_id' => (string) Str::uuid(),
'name' => 'Demo Enterprise',
'email' => 'demo-enterprise@ladill.com',
]);
$other = User::create([
'public_id' => (string) Str::uuid(),
'name' => 'Other',
'email' => 'other@example.com',
]);
$otherOrg = Organization::create([
'owner_ref' => $other->public_id,
'name' => 'Other Org',
'slug' => 'other-org',
'settings' => ['onboarded' => true, 'plan' => 'free'],
]);
$this->artisan('demo:seed', ['identity' => $user->email, '--plan' => 'enterprise'])->assertSuccessful();
$org = Organization::query()->where('owner_ref', $user->public_id)->firstOrFail();
$firstVisits = Visit::query()->where('organization_id', $org->id)->count();
$this->artisan('demo:seed', ['identity' => $user->email, '--plan' => 'enterprise'])->assertSuccessful();
$this->assertSame($firstVisits, Visit::query()->where('organization_id', $org->id)->count());
$this->artisan('demo:seed', [
'identity' => $user->email,
'--plan' => 'free',
'--reset' => true,
])->assertSuccessful();
$this->assertNotNull(Organization::query()->find($otherOrg->id));
$fresh = Organization::query()->where('owner_ref', $user->public_id)->firstOrFail();
$this->assertSame('free', app(PlanService::class)->planKey($fresh));
$this->assertSame(1, Branch::query()->where('organization_id', $fresh->id)->count());
$this->assertSame(40, Visit::query()->where('organization_id', $fresh->id)->count());
}
}