Files
ladill-events/tests/Feature/EventsProTest.php
T
isaacclad b73b071cb1
Deploy Ladill Events / deploy (push) Successful in 46s
Gate payment gateway behind Pro and Business plans.
Free accounts can no longer connect or use Paystack/Flutterwave/Hubtel;
settings show an upgrade path and checkout requires a paid subscription.
2026-07-15 21:04:03 +00:00

107 lines
3.5 KiB
PHP

<?php
namespace Tests\Feature;
use App\Http\Middleware\EnsurePlatformSession;
use App\Models\Events\ProSubscription;
use App\Models\User;
use App\Services\Events\SubscriptionService;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Http;
use Tests\TestCase;
class EventsProTest extends TestCase
{
use RefreshDatabase;
protected function setUp(): void
{
parent::setUp();
$this->withoutMiddleware(EnsurePlatformSession::class);
config([
'billing.api_url' => 'https://ladill.com/api/billing',
'billing.api_key' => 'events-billing-key',
'events.pro.enabled' => true,
'events.pro.price_minor' => 4900,
'events.plans.pro.price_minor' => 4900,
'events.plans.enterprise.price_minor' => 14900,
'events.pro.period_days' => 30,
'events.pro.grace_days' => 3,
'events.free.max_live_events' => 2,
'events.free.max_tickets_per_month' => 100,
]);
}
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_ends_with(parse_url($r->url(), PHP_URL_PATH) ?: '', '/debit')
&& $r['amount_minor'] === 4900
&& $r['service'] === 'events');
}
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(14900, $sub->price_minor);
}
public function test_free_user_is_gated_to_event_limit(): void
{
$user = $this->user();
$svc = app(SubscriptionService::class);
$this->assertTrue($svc->canCreateEvent($user));
$this->assertSame(0, $svc->liveEventCount($user));
}
public function test_free_user_cannot_use_payment_gateway(): void
{
$user = $this->user();
$svc = app(SubscriptionService::class);
$this->assertFalse($svc->canUsePaymentGateway($user));
$this->assertFalse(app(\App\Services\Payments\MerchantGatewayService::class)->isConfigured($user));
}
public function test_pro_user_can_use_payment_gateway_when_configured(): void
{
Http::fake(['*/debit' => Http::response(['id' => 1], 201)]);
$user = $this->user();
$svc = app(SubscriptionService::class);
$svc->subscribe($user);
\App\Models\PaymentGatewaySetting::create([
'owner_ref' => $user->public_id,
'provider' => \App\Models\PaymentGatewaySetting::PROVIDER_PAYSTACK,
'public_key' => 'pk_test',
'secret_key' => 'sk_test',
'is_active' => true,
]);
$this->assertTrue($svc->canUsePaymentGateway($user));
$this->assertTrue(app(\App\Services\Payments\MerchantGatewayService::class)->isConfigured($user));
}
}