Deploy Ladill Give / deploy (push) Successful in 1m0s
Co-authored-by: Cursor <cursoragent@cursor.com>
52 lines
2.3 KiB
PHP
52 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace Tests\Feature;
|
|
|
|
use App\Models\PaymentGatewaySetting;
|
|
use App\Models\User;
|
|
use App\Services\Payments\MerchantGatewayService;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Http;
|
|
use Tests\TestCase;
|
|
|
|
class PaymentGatewayPolicyTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_free_cannot_activate_saved_owner_gateway_but_pro_can(): void
|
|
{
|
|
config(['billing.api_url' => 'https://ladill.com/api/billing', 'billing.api_key' => 'give-test']);
|
|
$owner = User::factory()->create(['public_id' => 'usr_give_policy']);
|
|
$setting = PaymentGatewaySetting::create([
|
|
'owner_ref' => $owner->public_id, 'provider' => 'paystack',
|
|
'public_key' => 'pk_test_saved', 'secret_key' => 'sk_test_saved', 'is_active' => true,
|
|
]);
|
|
|
|
Http::fakeSequence()
|
|
->push(['data' => ['effective_plan' => 'free', 'features' => []]])
|
|
->push(['data' => ['effective_plan' => 'enterprise', 'features' => ['custom_payment_gateway']]])
|
|
->push(['data' => ['effective_plan' => 'enterprise', 'features' => ['custom_payment_gateway']]]);
|
|
$this->assertFalse(app(MerchantGatewayService::class)->shouldUseOwnerGateway($owner));
|
|
|
|
$setting->update(['is_active' => false]);
|
|
$this->assertFalse(app(MerchantGatewayService::class)->shouldUseOwnerGateway($owner));
|
|
$setting->update(['is_active' => true]);
|
|
$this->assertTrue(app(MerchantGatewayService::class)->shouldUseOwnerGateway($owner));
|
|
}
|
|
|
|
public function test_invalid_pro_credentials_fall_back_to_ladill_pay(): void
|
|
{
|
|
config(['billing.api_url' => 'https://ladill.com/api/billing', 'billing.api_key' => 'give-test']);
|
|
Http::fake(['*/suite-entitlements*' => Http::response(['data' => [
|
|
'effective_plan' => 'pro', 'features' => ['custom_payment_gateway'],
|
|
]])]);
|
|
$owner = User::factory()->create(['public_id' => 'usr_give_invalid']);
|
|
PaymentGatewaySetting::create([
|
|
'owner_ref' => $owner->public_id, 'provider' => 'paystack',
|
|
'public_key' => 'bad', 'secret_key' => 'bad', 'is_active' => true,
|
|
]);
|
|
|
|
$this->assertFalse(app(MerchantGatewayService::class)->shouldUseOwnerGateway($owner));
|
|
}
|
|
}
|