'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())); $this->assertTrue((bool) data_get(Organization::owned($target->public_id)->first()?->settings, 'onboarded')); $this->assertSame( $org->id, Organization::owned($target->public_id)->value('id'), 'Reset must keep the organization row so login never flashes onboarding', ); } public function test_reset_keeps_organization_onboarded_mid_wipe(): void { $user = User::create([ 'public_id' => 'demo-queue-mid-reset', 'name' => 'Demo Mid', 'email' => 'demo-mid@ladill.com', 'password' => bcrypt('password'), ]); Artisan::call('demo:seed', ['identity' => $user->email, '--plan' => 'free']); $orgId = (int) Organization::owned($user->public_id)->value('id'); $this->assertGreaterThan(0, $orgId); app(\App\Services\Qms\DemoSeeder::class)->resetForOwner($user->public_id); $org = Organization::query()->find($orgId); $this->assertNotNull($org); $this->assertTrue((bool) data_get($org->settings, 'onboarded')); $this->assertTrue(app(\App\Services\Qms\OrganizationResolver::class)->isOnboarded($user)); $this->assertSame(0, Branch::query()->where('organization_id', $orgId)->whereNull('deleted_at')->count()); } 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() ); } }