Deploy Ladill Queue / deploy (push) Successful in 2m27s
Monthly Pro/Enterprise stays on wallet; 6/12/24 month plans checkout via Paystack. Co-authored-by: Cursor <cursoragent@cursor.com>
203 lines
6.5 KiB
PHP
203 lines
6.5 KiB
PHP
<?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 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_three_tier_pricing(): void
|
|
{
|
|
$this->actingAs($this->owner)
|
|
->get(route('qms.pro.index'))
|
|
->assertOk()
|
|
->assertSee('Choose your Queue plan')
|
|
->assertSee('GHS 99')
|
|
->assertSee('GHS 299')
|
|
->assertSee('Upgrade to Pro')
|
|
->assertSee('Enterprise');
|
|
}
|
|
|
|
public function test_sidebar_shows_upgrade_to_pro_on_dashboard(): void
|
|
{
|
|
$this->actingAs($this->owner)
|
|
->get(route('qms.dashboard'))
|
|
->assertOk()
|
|
->assertSee('Upgrade to Pro');
|
|
}
|
|
|
|
public function test_sidebar_shows_upgrade_for_operator_without_settings_access(): void
|
|
{
|
|
$operator = User::create([
|
|
'public_id' => 'queue-operator-001',
|
|
'name' => 'Operator',
|
|
'email' => 'operator@example.com',
|
|
'password' => bcrypt('password'),
|
|
]);
|
|
|
|
Member::create([
|
|
'owner_ref' => $this->organization->owner_ref,
|
|
'organization_id' => $this->organization->id,
|
|
'user_ref' => $operator->public_id,
|
|
'role' => 'queue_operator',
|
|
]);
|
|
|
|
$this->actingAs($operator)
|
|
->get(route('qms.dashboard'))
|
|
->assertOk()
|
|
->assertSee('Upgrade to Pro')
|
|
->assertDontSee(route('qms.settings.edit'));
|
|
}
|
|
|
|
public function test_subscribe_upgrades_organization_to_pro(): 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_subscribe_enterprise_requires_multiple_branches(): 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-enterprise'))
|
|
->assertRedirect(route('qms.pro.index'))
|
|
->assertSessionHas('error');
|
|
|
|
Branch::create([
|
|
'owner_ref' => $this->organization->owner_ref,
|
|
'organization_id' => $this->organization->id,
|
|
'name' => 'Second',
|
|
'is_active' => true,
|
|
]);
|
|
|
|
$this->actingAs($this->owner)
|
|
->post(route('qms.pro.subscribe-enterprise'))
|
|
->assertRedirect(route('qms.pro.index'))
|
|
->assertSessionHas('success');
|
|
|
|
$settings = $this->organization->fresh()->settings;
|
|
$this->assertSame('enterprise', $settings['plan']);
|
|
$this->assertSame(2, $settings['enterprise_billed_branches']);
|
|
}
|
|
|
|
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());
|
|
}
|
|
|
|
public function test_enterprise_renew_charges_per_active_branch(): void
|
|
{
|
|
Branch::create([
|
|
'owner_ref' => $this->organization->owner_ref,
|
|
'organization_id' => $this->organization->id,
|
|
'name' => 'Second',
|
|
'is_active' => true,
|
|
]);
|
|
|
|
$this->organization->update([
|
|
'settings' => array_merge($this->organization->settings ?? [], [
|
|
'plan' => 'enterprise',
|
|
'auto_renew' => true,
|
|
'enterprise_billed_branches' => 2,
|
|
'plan_expires_at' => now()->subDay()->toIso8601String(),
|
|
]),
|
|
]);
|
|
|
|
Http::fake([
|
|
'billing.test/debit' => function ($request) {
|
|
$this->assertSame(59800, (int) $request['amount_minor']);
|
|
|
|
return Http::response(['ok' => true]);
|
|
},
|
|
]);
|
|
|
|
$this->artisan('qms:pro-renew')->assertSuccessful();
|
|
|
|
$settings = $this->organization->fresh()->settings;
|
|
$this->assertSame('enterprise', $settings['plan']);
|
|
$this->assertSame(2, $settings['enterprise_billed_branches']);
|
|
}
|
|
|
|
public function test_prepaid_checkout_redirects_to_paystack(): void
|
|
{
|
|
Http::fake([
|
|
'billing.test/plan-checkout' => Http::response([
|
|
'checkout_url' => 'https://checkout.paystack.test/pay',
|
|
'reference' => 'SAP-QUEUE-TEST',
|
|
], 201),
|
|
]);
|
|
|
|
$this->actingAs($this->owner)
|
|
->post(route('qms.pro.subscribe-prepaid'), [
|
|
'plan' => 'pro',
|
|
'months' => 12,
|
|
])
|
|
->assertRedirect('https://checkout.paystack.test/pay');
|
|
}
|
|
}
|