29 lines
1.1 KiB
PHP
29 lines
1.1 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
use Modules\Payment\Models\Payment;
|
||
|
|
use Modules\Payment\Models\Refund;
|
||
|
|
|
||
|
|
test('refundable balance is the full amount when nothing has been refunded yet', function () {
|
||
|
|
$payment = Payment::factory()->completed()->create(['amount' => 15000]);
|
||
|
|
|
||
|
|
expect($payment->refundableBalance())->toBe('15000.00');
|
||
|
|
});
|
||
|
|
|
||
|
|
test('refundable balance subtracts only completed refunds', function () {
|
||
|
|
$payment = Payment::factory()->completed()->create(['amount' => 15000]);
|
||
|
|
|
||
|
|
Refund::factory()->completed()->for($payment)->create(['amount' => 5000]);
|
||
|
|
Refund::factory()->failed()->for($payment)->create(['amount' => 3000]);
|
||
|
|
Refund::factory()->for($payment)->create(['amount' => 2000]); // default state is Pending
|
||
|
|
|
||
|
|
expect($payment->refundableBalance())->toBe('10000.00');
|
||
|
|
});
|
||
|
|
|
||
|
|
test('refundable balance reaches zero once fully refunded', function () {
|
||
|
|
$payment = Payment::factory()->completed()->create(['amount' => 15000]);
|
||
|
|
|
||
|
|
Refund::factory()->completed()->for($payment)->create(['amount' => 15000]);
|
||
|
|
|
||
|
|
expect($payment->refundableBalance())->toBe('0.00');
|
||
|
|
});
|