Files
portal/app/tests/Feature/Billing/OnlineTopupServiceTest.php
T

47 lines
1.8 KiB
PHP

<?php
declare(strict_types=1);
use App\Models\LegalEntity;
use App\Models\PaymentGateway;
use App\Models\SaasTransaction;
use App\Models\Tenant;
use App\Services\Billing\Gateway\CreatePaymentResult;
use App\Services\Billing\Gateway\PaymentGatewayDriver;
use App\Services\Billing\OnlineTopupService;
use Illuminate\Foundation\Testing\DatabaseTransactions;
uses(DatabaseTransactions::class);
it('создаёт saas_transactions(pending) и возвращает confirmation_url', function () {
$tenant = Tenant::factory()->create();
// legal_entities.legal_entity_id NOT NULL REFERENCES legal_entities(id)
$legalEntity = LegalEntity::create([
'code' => 'test_le_' . uniqid(), 'name' => 'ООО Тест', 'legal_form' => 'OOO',
'inn' => '7700000000',
]);
$gw = PaymentGateway::create([
'code' => 'yookassa_' . uniqid(), 'name' => 'ЮKassa', 'driver' => 'yookassa',
'legal_entity_id' => $legalEntity->id, 'config' => '', 'is_active' => true,
'accepts_methods' => ['card', 'sbp'], 'min_amount_rub' => '100.00',
]);
$fakeDriver = Mockery::mock(PaymentGatewayDriver::class);
$fakeDriver->shouldReceive('createPayment')->once()
->andReturn(new CreatePaymentResult('pay_abc', 'https://yoomoney.ru/checkout/pay_abc'));
$service = new OnlineTopupService($fakeDriver);
$res = $service->start($tenant->id, '500.00', $gw, 'https://liderra.ru/billing', userId: 7);
expect($res->confirmationUrl)->toBe('https://yoomoney.ru/checkout/pay_abc');
// postgres superuser = BYPASSRLS, поэтому SET LOCAL не нужен
$tx = SaasTransaction::where('gateway_payment_id', 'pay_abc')->firstOrFail();
expect($tx->status)->toBe('pending')
->and($tx->tenant_id)->toBe($tenant->id)
->and($tx->amount_rub)->toBe('500.00')
->and($tx->type)->toBe('topup');
});