update
This commit is contained in:
@@ -9,6 +9,7 @@ use App\Http\Controllers\Api\Admin\Transaction\AdminTransactionController;
|
||||
use App\Models\Customer;
|
||||
use App\Models\Transaction;
|
||||
use Illuminate\Foundation\Testing\RefreshDatabase;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
use Tests\TestCase;
|
||||
|
||||
@@ -33,8 +34,8 @@ class AdminTransactionApproveTest extends TestCase
|
||||
|
||||
$controller = app(AdminTransactionController::class);
|
||||
|
||||
$first = $controller->approve($transaction->uuid);
|
||||
$second = $controller->approve($transaction->uuid);
|
||||
$first = $controller->approve(new Request(), $transaction->uuid);
|
||||
$second = $controller->approve(new Request(), $transaction->uuid);
|
||||
|
||||
$this->assertSame(200, $first->getStatusCode());
|
||||
// Second call finds the transaction no longer PENDING → treated as not-approvable.
|
||||
@@ -42,4 +43,61 @@ class AdminTransactionApproveTest extends TestCase
|
||||
|
||||
$this->assertSame(100_000, (int) $customer->fresh()->total);
|
||||
}
|
||||
|
||||
/**
|
||||
* Khách khai 5tr nhưng sao kê chỉ về 4tr: số dư phải cộng theo số THỰC NHẬN, phần chênh
|
||||
* được ghi lại để kế toán đối chiếu. Trước đây luôn cộng theo số khách khai.
|
||||
*/
|
||||
public function test_approving_credits_the_received_amount_not_the_declared_one(): void
|
||||
{
|
||||
Mail::fake();
|
||||
|
||||
$customer = Customer::factory()->create(['total' => 0, 'credit' => 0, 'total_pending' => 5_000_000]);
|
||||
$transaction = Transaction::create([
|
||||
'uuid' => (string) \Illuminate\Support\Str::uuid(),
|
||||
'public_code' => 'DEP-TEST-0002',
|
||||
'trans' => 'DEP-TEST-0002',
|
||||
'amount' => 5_000_000,
|
||||
'customer_id' => $customer->id,
|
||||
'type' => 'manual',
|
||||
'status' => TransactionStatus::PENDING->value,
|
||||
]);
|
||||
|
||||
$request = Request::create('/', 'POST', ['received_amount' => 4_000_000]);
|
||||
|
||||
$response = app(AdminTransactionController::class)->approve($request, $transaction->uuid);
|
||||
|
||||
$this->assertSame(200, $response->getStatusCode());
|
||||
$this->assertSame(4_000_000, (int) $customer->fresh()->total);
|
||||
$this->assertSame(40_000, (int) $customer->fresh()->credit);
|
||||
$this->assertSame(0, (int) $customer->fresh()->total_pending);
|
||||
|
||||
$transaction->refresh();
|
||||
$this->assertSame(5_000_000, (int) $transaction->amount);
|
||||
$this->assertSame(4_000_000, (int) $transaction->received_amount);
|
||||
$this->assertStringContainsString('Lệch ' . number_format(1_000_000), (string) $transaction->note);
|
||||
}
|
||||
|
||||
/** Bỏ trống received_amount = tin số khách khai, giữ nguyên hành vi cũ. */
|
||||
public function test_approving_without_received_amount_credits_the_declared_amount(): void
|
||||
{
|
||||
Mail::fake();
|
||||
|
||||
$customer = Customer::factory()->create(['total' => 0, 'credit' => 0, 'total_pending' => 300_000]);
|
||||
$transaction = Transaction::create([
|
||||
'uuid' => (string) \Illuminate\Support\Str::uuid(),
|
||||
'public_code' => 'DEP-TEST-0003',
|
||||
'trans' => 'DEP-TEST-0003',
|
||||
'amount' => 300_000,
|
||||
'customer_id' => $customer->id,
|
||||
'type' => 'manual',
|
||||
'status' => TransactionStatus::PENDING->value,
|
||||
]);
|
||||
|
||||
app(AdminTransactionController::class)->approve(new Request(), $transaction->uuid);
|
||||
|
||||
$this->assertSame(300_000, (int) $customer->fresh()->total);
|
||||
$this->assertSame(300_000, (int) $transaction->fresh()->received_amount);
|
||||
$this->assertStringNotContainsString('Lệch', (string) $transaction->fresh()->note);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user