50 lines
1.5 KiB
PHP
50 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature\Api\Tenant;
|
|
|
|
use App\Models\Package;
|
|
use App\Models\TenantPackage;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Tests\Feature\Tenant\TenantTestCase;
|
|
|
|
class BillingPortalTest extends TenantTestCase
|
|
{
|
|
public function test_tenant_can_fetch_lemonsqueezy_portal_url(): void
|
|
{
|
|
config()->set('lemonsqueezy.base_url', 'https://lemonsqueezy.test');
|
|
|
|
$package = Package::factory()->reseller()->create();
|
|
TenantPackage::factory()->create([
|
|
'tenant_id' => $this->tenant->id,
|
|
'package_id' => $package->id,
|
|
'lemonsqueezy_subscription_id' => 'sub_123',
|
|
'active' => true,
|
|
]);
|
|
|
|
Http::fake([
|
|
'https://lemonsqueezy.test/subscriptions/sub_123' => Http::response([
|
|
'data' => [
|
|
'id' => 'sub_123',
|
|
'attributes' => [
|
|
'urls' => [
|
|
'customer_portal' => 'https://portal.example/overview',
|
|
],
|
|
],
|
|
],
|
|
], 200),
|
|
]);
|
|
|
|
$response = $this->authenticatedRequest('POST', '/api/v1/tenant/billing/portal');
|
|
|
|
$response->assertOk();
|
|
$response->assertJsonPath('url', 'https://portal.example/overview');
|
|
}
|
|
|
|
public function test_portal_returns_404_when_no_active_subscription(): void
|
|
{
|
|
$response = $this->authenticatedRequest('POST', '/api/v1/tenant/billing/portal');
|
|
|
|
$response->assertNotFound();
|
|
}
|
|
}
|