Deploy Ladill POS / deploy (push) Successful in 2m34s
Seed locations, products, and cash sales within Free caps and Pro multi-site data. Co-authored-by: Cursor <cursoragent@cursor.com>
108 lines
3.9 KiB
PHP
108 lines
3.9 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\Pos\ProSubscription;
|
|
use App\Models\PosLocation;
|
|
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());
|
|
}
|
|
}
|