46 lines
1.5 KiB
PHP
46 lines
1.5 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Tests\Feature\Payment;
|
|
|
|
use App\Enums\TransactionStatus;
|
|
use App\Http\Controllers\Api\Admin\Transaction\AdminTransactionController;
|
|
use App\Models\Customer;
|
|
use App\Models\Transaction;
|
|
use Illuminate\Foundation\Testing\RefreshDatabase;
|
|
use Illuminate\Support\Facades\Mail;
|
|
use Tests\TestCase;
|
|
|
|
class AdminTransactionApproveTest extends TestCase
|
|
{
|
|
use RefreshDatabase;
|
|
|
|
public function test_approving_the_same_manual_deposit_twice_credits_the_customer_only_once(): void
|
|
{
|
|
Mail::fake();
|
|
|
|
$customer = Customer::factory()->create(['total' => 0, 'credit' => 0, 'total_pending' => 100_000]);
|
|
$transaction = Transaction::create([
|
|
'uuid' => (string) \Illuminate\Support\Str::uuid(),
|
|
'public_code' => 'DEP-TEST-0001',
|
|
'trans' => 'DEP-TEST-0001',
|
|
'amount' => 100_000,
|
|
'customer_id' => $customer->id,
|
|
'type' => 'manual',
|
|
'status' => TransactionStatus::PENDING->value,
|
|
]);
|
|
|
|
$controller = app(AdminTransactionController::class);
|
|
|
|
$first = $controller->approve($transaction->uuid);
|
|
$second = $controller->approve($transaction->uuid);
|
|
|
|
$this->assertSame(200, $first->getStatusCode());
|
|
// Second call finds the transaction no longer PENDING → treated as not-approvable.
|
|
$this->assertSame(404, $second->getStatusCode());
|
|
|
|
$this->assertSame(100_000, (int) $customer->fresh()->total);
|
|
}
|
|
}
|