Files
ladill-events/tests/Feature/EventsProTest.php
T
isaaccladandCursor 4c87c786da
Deploy Ladill Events / deploy (push) Successful in 42s
Add Events Pro/Business and BYO ticket gateways.
Cut ticket checkouts off Ladill Pay, settle to merchant gateways at 0% platform fee, and mirror Invoice freemium pricing (GHS 49 / 149).

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-07-15 01:26:28 +00:00

79 lines
2.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));
}
}