Deploy Ladill Queue / deploy (push) Successful in 42s
Organizations can upgrade from wallet with plan expiry enforcement and nightly qms:pro-renew charges. Co-authored-by: Cursor <cursoragent@cursor.com>
89 lines
2.7 KiB
PHP
89 lines
2.7 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Http\Middleware\EnsurePlatformSession;
|
|
use App\Models\Organization;
|
|
use App\Models\User;
|
|
use App\Services\Qms\OrganizationResolver;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Tests\TestCase;
|
|
|
|
class QmsProTest 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' => 'queue-owner-001',
|
|
'name' => 'Owner',
|
|
'email' => 'owner@example.com',
|
|
'password' => bcrypt('password'),
|
|
]);
|
|
|
|
$this->organization = app(OrganizationResolver::class)->completeOnboarding($this->owner, [
|
|
'organization_name' => 'Queue Org',
|
|
'industry' => 'retail',
|
|
'appointment_mode' => 'hybrid',
|
|
'branch_name' => 'Main',
|
|
'timezone' => 'UTC',
|
|
]);
|
|
}
|
|
|
|
public function test_pro_page_renders_for_free_organization(): void
|
|
{
|
|
$this->actingAs($this->owner)
|
|
->get(route('qms.pro.index'))
|
|
->assertOk()
|
|
->assertSee('Ladill Queue Pro')
|
|
->assertSee('GHS 99')
|
|
->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('qms.pro.subscribe'))
|
|
->assertRedirect(route('qms.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' => array_merge($this->organization->settings ?? [], [
|
|
'plan' => 'pro',
|
|
'auto_renew' => true,
|
|
'plan_expires_at' => now()->subDay()->toIso8601String(),
|
|
]),
|
|
]);
|
|
|
|
Http::fake([
|
|
'billing.test/debit' => Http::response(['ok' => true]),
|
|
]);
|
|
|
|
$this->artisan('qms:pro-renew')->assertSuccessful();
|
|
|
|
$settings = $this->organization->fresh()->settings;
|
|
$this->assertSame('pro', $settings['plan']);
|
|
$this->assertTrue(now()->parse($settings['plan_expires_at'])->isFuture());
|
|
}
|
|
}
|