Files
ladill-pos/tests/Feature/DemoSeedCommandTest.php
T
isaaccladandCursor 022f18084a
Deploy Ladill POS / deploy (push) Successful in 56s
Seed DemoWorld staff and customer continuity for POS demo data
Replace ad-hoc demo-cashier-{id} accounts with DemoWorld staff who hold
a pos role, mirrored locally by email until SSO remaps to public_id.
Sales for the first named customers now use DemoWorld people (name +
phone) instead of generic "Cash Customer N" labels, and staff logins
skip the login reseed so mid-demo state survives.

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

133 lines
4.8 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\Pos\ProSubscription;
use App\Models\PosLocation;
use App\Models\PosMember;
use App\Models\PosProduct;
use App\Models\PosSale;
use App\Models\User;
use App\Services\Pos\SubscriptionService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Artisan;
use Tests\TestCase;
class DemoSeedCommandTest extends TestCase
{
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
config([
'pos.pro.enabled' => true,
'billing.api_url' => 'https://billing.test',
'billing.api_key' => 'test-key',
'pos.free.max_locations' => 1,
'pos.free.max_products' => 50,
]);
}
public function test_free_seed_respects_location_and_product_caps(): void
{
$user = User::create([
'public_id' => 'demo-pos-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);
$this->assertSame(1, PosLocation::owned($user->public_id)->count());
$this->assertLessThanOrEqual(50, PosProduct::owned($user->public_id)->count());
$this->assertGreaterThan(0, PosProduct::owned($user->public_id)->count());
$this->assertGreaterThan(0, PosSale::owned($user->public_id)->where('payment_method', 'cash')->count());
$this->assertSame('free', app(SubscriptionService::class)->planKey($user));
$this->assertNull(ProSubscription::where('user_id', $user->id)->first());
}
public function test_pro_seed_multi_location_and_reset_is_tenant_scoped(): void
{
$target = User::create([
'public_id' => 'demo-pos-pro',
'name' => 'Demo Pro',
'email' => 'demo-pro@ladill.com',
'password' => bcrypt('password'),
]);
$other = User::create([
'public_id' => 'other-pos-owner',
'name' => 'Other',
'email' => 'other-pos@example.com',
'password' => bcrypt('password'),
]);
PosLocation::create([
'owner_ref' => $other->public_id,
'name' => 'Keep Branch',
'currency' => 'GHS',
'is_default' => true,
]);
Artisan::call('demo:seed', ['identity' => $target->public_id, '--plan' => 'pro']);
$this->assertTrue(app(SubscriptionService::class)->isPro($target));
$this->assertGreaterThanOrEqual(2, PosLocation::owned($target->public_id)->count());
$this->assertGreaterThan(50, PosProduct::owned($target->public_id)->count());
Artisan::call('demo:seed', [
'identity' => $target->email,
'--plan' => 'enterprise',
'--reset' => true,
]);
$this->assertDatabaseHas('pos_locations', ['owner_ref' => $other->public_id, 'name' => 'Keep Branch']);
$this->assertSame('enterprise', ProSubscription::where('user_id', $target->id)->value('plan'));
$this->assertGreaterThanOrEqual(4, PosLocation::owned($target->public_id)->count());
}
public function test_idempotent_without_reset(): void
{
$user = User::create([
'public_id' => 'demo-pos-idem',
'name' => 'Demo',
'email' => 'demo-idem-pos@ladill.com',
'password' => bcrypt('password'),
]);
Artisan::call('demo:seed', ['identity' => $user->email, '--plan' => 'free']);
$products = PosProduct::owned($user->public_id)->count();
$sales = PosSale::owned($user->public_id)->count();
Artisan::call('demo:seed', ['identity' => $user->email, '--plan' => 'free']);
$this->assertSame($products, PosProduct::owned($user->public_id)->count());
$this->assertSame($sales, PosSale::owned($user->public_id)->count());
}
public function test_pro_seed_provisions_demo_world_cashier_and_named_customer(): void
{
$user = User::create([
'public_id' => 'demo-pos-pro-staff',
'name' => 'Demo Pro',
'email' => 'demo-pro@ladill.com',
'password' => bcrypt('password'),
]);
Artisan::call('demo:seed', ['identity' => $user->email, '--plan' => 'pro']);
$this->assertDatabaseHas('users', ['email' => 'demo-pro-cashier@ladill.com']);
$this->assertTrue(
PosMember::owned($user->public_id)
->where('user_ref', 'demo-pro-cashier@ladill.com')
->where('role', PosMember::ROLE_CASHIER)
->exists()
);
$this->assertTrue(
PosSale::owned($user->public_id)->where('customer_name', 'Ama Mensah')->exists()
);
}
}