Files
ladill-pos/tests/Feature/PosProTest.php
T
isaaccladandCursor d66e656b9c
Deploy Ladill POS / deploy (push) Successful in 35s
Add Business tier and Paystack prepaid billing for POS.
Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-30 01:55:38 +00:00

82 lines
2.6 KiB
PHP

<?php
namespace Tests\Feature;
use App\Models\Pos\ProSubscription;
use App\Models\User;
use App\Services\Pos\SubscriptionService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Http;
use Tests\TestCase;
class PosProTest extends TestCase
{
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
config([
'billing.api_url' => 'https://ladill.com/api/billing',
'billing.api_key' => 'pos-billing-key',
'pos.pro.enabled' => true,
'pos.pro.price_minor' => 7900,
'pos.plans.pro.price_minor' => 7900,
'pos.plans.enterprise.price_minor' => 24900,
]);
}
private function user(): User
{
return User::factory()->create(['public_id' => 'usr_'.uniqid()]);
}
public function test_subscribe_charges_wallet_and_activates(): void
{
Http::fake(['*/debit' => Http::response(['id' => 1], 201)]);
$user = $this->user();
$svc = app(SubscriptionService::class);
[$ok] = $svc->subscribe($user);
$this->assertTrue($ok);
$this->assertTrue($svc->isPro($user));
Http::assertSent(fn ($r) => str_contains($r->url(), '/debit') && $r['service'] === 'pos');
}
public function test_free_user_cannot_use_restaurant_mode(): void
{
$this->assertFalse(app(SubscriptionService::class)->canUseRestaurantMode($this->user()));
}
public function test_subscribe_enterprise_charges_wallet_and_activates(): void
{
Http::fake(['*/debit' => Http::response(['id' => 1], 201)]);
$user = $this->user();
$svc = app(SubscriptionService::class);
[$ok] = $svc->subscribeEnterprise($user);
$this->assertTrue($ok);
$this->assertTrue($svc->isEnterprise($user));
$sub = ProSubscription::where('user_id', $user->id)->first();
$this->assertSame('enterprise', $sub->plan);
$this->assertSame(24900, $sub->price_minor);
}
public function test_renew_suspends_after_grace_when_unpaid(): void
{
Http::fake(['*/debit' => Http::response(['balance_minor' => 0], 402)]);
$user = $this->user();
$sub = ProSubscription::create([
'user_id' => $user->id, 'status' => 'active', 'price_minor' => 7900,
'auto_renew' => true, 'started_at' => now()->subDays(40),
'current_period_end' => now()->subDays(5),
]);
app(SubscriptionService::class)->renewIfDue($sub->fresh());
$this->assertSame('past_due', $sub->fresh()->status);
}
}