Files
ladill-woo-manager/tests/Feature/DemoSeedCommandTest.php
T
isaaccladandCursor 62901eaea3
Deploy Ladill Woo Manager / deploy (push) Successful in 2m24s
Add Woo Manager demo:seed for store walkthroughs.
Seed stores, products, and orders within Free caps and paid-tier volume.

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

78 lines
3.0 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 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]);
}
}