Files
ladill-woo-manager/tests/Feature/DemoSeedCommandTest.php
T
isaaccladandCursor 9744f0fe01
Deploy Ladill Woo Manager / deploy (push) Successful in 47s
Seed DemoWorld business and customer continuity for Woo Manager demos
Store site names now reference the DemoWorld business identity for the
active plan, and order customers use DemoWorld people (name, email,
phone) instead of generic "Demo Customer N" placeholders. Staff logins
skip the login reseed.

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

97 lines
3.7 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\User;
use App\Models\Woo\ProSubscription;
use App\Models\WooOrder;
use App\Models\WooProduct;
use App\Models\WooStore;
use App\Support\DemoWorld;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Tests\TestCase;
class DemoSeedCommandTest extends TestCase
{
use RefreshDatabase;
public function test_free_plan_seeds_one_store_within_product_limit(): void
{
$user = User::factory()->create(['email' => 'demo-free@ladill.com']);
$this->artisan('demo:seed', ['identity' => $user->email, '--plan' => 'free'])
->assertSuccessful();
$this->assertDatabaseMissing('woo_pro_subscriptions', ['user_id' => $user->id]);
$stores = WooStore::query()->where('user_id', $user->id)->get();
$this->assertCount(1, $stores);
$this->assertSame(WooStore::STATUS_ACTIVE, $stores->first()->status);
$productCount = WooProduct::query()->where('woo_store_id', $stores->first()->id)->count();
$this->assertLessThanOrEqual(20, $productCount);
$this->assertGreaterThan(0, $productCount);
$this->assertGreaterThan(0, WooOrder::query()->where('woo_store_id', $stores->first()->id)->count());
$this->assertGreaterThan(0, $stores->first()->categories()->count());
}
public function test_pro_plan_assigns_subscription_and_multiple_stores(): void
{
$user = User::factory()->create(['public_id' => 'woo-demo-pro-001']);
$this->artisan('demo:seed', ['identity' => 'woo-demo-pro-001', '--plan' => 'pro'])
->assertSuccessful();
$sub = ProSubscription::query()->where('user_id', $user->id)->first();
$this->assertNotNull($sub);
$this->assertSame(ProSubscription::PLAN_PRO, $sub->plan);
$this->assertTrue($sub->entitled());
$this->assertCount(2, WooStore::query()->where('user_id', $user->id)->get());
$this->assertGreaterThan(20, WooProduct::query()
->whereIn('woo_store_id', WooStore::query()->where('user_id', $user->id)->pluck('id'))
->count());
}
public function test_idempotent_without_reset_and_reset_reseeds(): void
{
$user = User::factory()->create(['email' => 'demo-pro@ladill.com']);
$this->artisan('demo:seed', ['identity' => $user->email, '--plan' => 'enterprise'])
->assertSuccessful();
$firstCount = WooStore::query()->where('user_id', $user->id)->count();
$this->assertSame(3, $firstCount);
$this->artisan('demo:seed', ['identity' => $user->email, '--plan' => 'enterprise'])
->assertSuccessful();
$this->assertSame(3, WooStore::query()->where('user_id', $user->id)->count());
$this->artisan('demo:seed', [
'identity' => $user->email,
'--plan' => 'free',
'--reset' => true,
])->assertSuccessful();
$this->assertCount(1, WooStore::query()->where('user_id', $user->id)->get());
$this->assertDatabaseMissing('woo_pro_subscriptions', ['user_id' => $user->id]);
}
public function test_pro_plan_uses_demo_world_business_and_customer_continuity(): void
{
$user = User::factory()->create(['email' => 'demo-pro@ladill.com']);
$this->artisan('demo:seed', ['identity' => $user->email, '--plan' => 'pro'])
->assertSuccessful();
$store = WooStore::query()->where('user_id', $user->id)->first();
$this->assertStringContainsString(DemoWorld::business('pro')['name'], $store->site_name);
$firstPerson = DemoWorld::people(1)[0];
$this->assertDatabaseHas('woo_orders', [
'woo_store_id' => $store->id,
'customer_name' => DemoWorld::fullName($firstPerson),
'customer_email' => $firstPerson['email'],
]);
}
}