Only expose completed refunds in booking API responses
PHP Tests / php-tests (push) Waiting to run

BookingController's eager load now constrains the refunds relation to
status completed only (a new eagerLoads() layering that onto the
existing EAGER_LOADS list, applied uniformly across
index/show/store/cancel). A pending or failed refund attempt isn't
customer-facing — staff still track those via Filament's Refunds
resource, which loads the relation unconstrained.
This commit is contained in:
Nyan Lin Paing
2026-09-03 21:48:22 +07:00
parent 47be71c2cf
commit 37f9dc1905
3 changed files with 45 additions and 9 deletions
@@ -115,6 +115,22 @@ test('cancelling a confirmed booking returns the refund it created', function ()
expect($response->json('data.refunds.0.completed_at'))->not->toBeNull();
});
test('a pending or failed refund is not returned — only completed refunds are exposed', function () {
$booking = Booking::factory()->create(['user_id' => $this->owner->id, 'status' => BookingStatus::Cancelled, 'price' => 15000]);
$payment = Payment::factory()->completed()->create([
'booking_id' => $booking->id,
'gateway' => PaymentMethod::KbzMiniApp,
'amount' => 15000,
]);
$booking->refunds()->create(['payment_id' => $payment->id, 'status' => RefundStatus::Pending, 'amount' => 15000, 'reason' => 'Booking cancellation']);
$booking->refunds()->create(['payment_id' => $payment->id, 'status' => RefundStatus::Failed, 'amount' => 15000, 'reason' => 'Booking cancellation']);
$this->withHeader('Authorization', "Bearer {$this->token}")
->getJson("/api/v1/bookings/{$booking->booking_ref}")
->assertSuccessful()
->assertJsonPath('data.refunds', []);
});
test('cancelling a pending_payment booking returns an empty refunds list — no money moved yet', function () {
$booking = Booking::factory()->create(['user_id' => $this->owner->id, 'status' => BookingStatus::PendingPayment]);