HEX
Server: LiteSpeed
System: Linux s1049.use1.mysecurecloudhost.com 4.18.0-477.27.2.lve.el8.x86_64 #1 SMP Wed Oct 11 12:32:56 UTC 2023 x86_64
User: xedaptot (3356)
PHP: 8.3.31
Disabled: NONE
Upload Files
File: /home/xedaptot/be.naniguide.com/tests/Unit/Models/PaymentGatewayTest.php
<?php

namespace Tests\Unit\Models;

use Tests\TestCase;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use App\Model\PaymentGateway;

/**
 * PaymentGateway is now persistence-only — gateway-service resolution +
 * checkout-URL orchestration + capability checks live on BillingManager
 * (covered by Tests\Unit\Library\BillingManagerTest).
 *
 * This file keeps a couple of model-only sanity checks: factories build,
 * scopes filter, gatewayData JSON round-trips.
 */
class PaymentGatewayTest extends TestCase
{
    use DatabaseTransactions;

    public function test_factory_builds_stripe_gateway_row()
    {
        $gw = PaymentGateway::factory()->stripe()->create();

        $this->assertSame('stripe', $gw->type);
        $this->assertSame(PaymentGateway::STATUS_ACTIVE, $gw->status);
        $this->assertNotEmpty($gw->getGatewayData('publishable_key'));
        $this->assertNotEmpty($gw->getGatewayData('secret_key'));
    }

    public function test_active_scope_excludes_inactive()
    {
        $active = PaymentGateway::factory()->stripe()->create(['status' => PaymentGateway::STATUS_ACTIVE]);
        $inactive = PaymentGateway::factory()->offline()->create(['status' => PaymentGateway::STATUS_INACTIVE]);

        $ids = PaymentGateway::active()->pluck('id')->all();

        $this->assertContains($active->id, $ids);
        $this->assertNotContains($inactive->id, $ids);
    }

    public function test_global_scope_excludes_customer_owned()
    {
        $global = PaymentGateway::factory()->stripe()->create(['customer_id' => null]);
        $owned  = PaymentGateway::factory()->stripe()->create(['customer_id' => 999999]);

        $ids = PaymentGateway::global()->pluck('id')->all();

        $this->assertContains($global->id, $ids);
        $this->assertNotContains($owned->id, $ids);
    }

    public function test_gateway_data_json_round_trip()
    {
        $gw = PaymentGateway::factory()->stripe()->create();
        $gw->savePaymentGateway('My Stripe', 'desc', ['publishable_key' => 'pk_x', 'secret_key' => 'sk_x']);

        $reloaded = PaymentGateway::find($gw->id);
        $this->assertSame('pk_x', $reloaded->getGatewayData('publishable_key'));
        $this->assertSame('sk_x', $reloaded->getGatewayData('secret_key'));
    }
}