Add Care Pro billing, renewal, and scheduler.
Deploy Ladill Care / deploy (push) Successful in 35s

Organizations can subscribe from wallet, expire correctly on free tier, and renew nightly via care:pro-renew.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
isaacclad
2026-06-30 01:07:23 +00:00
co-authored by Cursor
parent cd415e918f
commit 4bc485dfea
10 changed files with 403 additions and 4 deletions
+103
View File
@@ -0,0 +1,103 @@
<?php
namespace Tests\Feature;
use App\Http\Middleware\EnsurePlatformSession;
use App\Models\Branch;
use App\Models\Member;
use App\Models\Organization;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Facades\Http;
use Tests\TestCase;
class CareProTest extends TestCase
{
use RefreshDatabase;
protected User $owner;
protected Organization $organization;
protected function setUp(): void
{
parent::setUp();
$this->withoutMiddleware(EnsurePlatformSession::class);
config(['billing.api_url' => 'https://billing.test']);
$this->owner = User::create([
'public_id' => 'care-owner-001',
'name' => 'Owner',
'email' => 'owner@example.com',
]);
$this->organization = Organization::create([
'owner_ref' => $this->owner->public_id,
'name' => 'Care Org',
'slug' => 'care-org',
'settings' => ['onboarded' => true, 'facility_type' => 'clinic'],
]);
Member::create([
'owner_ref' => $this->owner->public_id,
'organization_id' => $this->organization->id,
'user_ref' => $this->owner->public_id,
'role' => 'hospital_admin',
]);
Branch::create([
'owner_ref' => $this->owner->public_id,
'organization_id' => $this->organization->id,
'name' => 'HQ',
'is_active' => true,
]);
}
public function test_pro_page_renders_for_free_organization(): void
{
$this->actingAs($this->owner)
->get(route('care.pro.index'))
->assertOk()
->assertSee('Ladill Care Pro')
->assertSee('GHS 199')
->assertSee('Upgrade to Pro');
}
public function test_subscribe_upgrades_organization(): void
{
Http::fake([
'billing.test/can-afford*' => Http::response(['affordable' => true]),
'billing.test/debit' => Http::response(['ok' => true]),
]);
$this->actingAs($this->owner)
->post(route('care.pro.subscribe'))
->assertRedirect(route('care.pro.index'))
->assertSessionHas('success');
$this->assertSame('pro', $this->organization->fresh()->settings['plan']);
}
public function test_pro_renew_extends_subscription_when_wallet_charges(): void
{
$this->organization->update([
'settings' => [
'onboarded' => true,
'facility_type' => 'clinic',
'plan' => 'pro',
'auto_renew' => true,
'plan_expires_at' => now()->subDay()->toIso8601String(),
],
]);
Http::fake([
'billing.test/debit' => Http::response(['ok' => true]),
]);
$this->artisan('care:pro-renew')->assertSuccessful();
$settings = $this->organization->fresh()->settings;
$this->assertSame('pro', $settings['plan']);
$this->assertTrue(now()->parse($settings['plan_expires_at'])->isFuture());
}
}