Files
ladill-frontdesk/tests/Feature/DemoSeedCommandTest.php
T
isaaccladandCursor a28e8619a1
Deploy Ladill Frontdesk / deploy (push) Successful in 1m10s
Wire Frontdesk demo seeder to shared DemoWorld
Org name, branches, and visitors now come from DemoWorld so continuity
matches Care/Queue across the suite, plus Members for DemoWorld staff
with a frontdesk role. Also resolve organization by owner_ref when
metadata.frontdesk.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:52 +00:00

144 lines
5.7 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\Branch;
use App\Models\Device;
use App\Models\Host;
use App\Models\Member;
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 App\Support\DemoWorld;
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());
}
public function test_demo_world_continuity_and_staff_roles(): void
{
$user = User::create([
'public_id' => 'demo-world-frontdesk-id',
'name' => 'Ladill Demo (Pro)',
'email' => 'demo-pro@ladill.com',
]);
$this->artisan('demo:seed', [
'identity' => $user->email,
'--plan' => 'pro',
])->assertSuccessful();
$org = Organization::query()->where('owner_ref', $user->public_id)->firstOrFail();
$this->assertSame(DemoWorld::business('pro')['name'], $org->name);
$ama = DemoWorld::personByKey('ama-mensah');
$this->assertNotNull($ama);
$visitor = Visitor::query()
->where('organization_id', $org->id)
->where('phone', $ama['phone'])
->first();
$this->assertNotNull($visitor);
$this->assertSame($ama['email'], $visitor->email);
$this->assertSame(DemoWorld::companyNameForPerson($ama), $visitor->company);
$this->assertTrue(
Member::query()
->where('organization_id', $org->id)
->where('user_ref', 'demo-pro-receptionist@ladill.com')
->where('role', 'receptionist')
->exists()
);
}
}