27 lines
1.1 KiB
PHP
27 lines
1.1 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
use Modules\Booking\Enums\BookingStatus;
|
||
|
|
use Modules\Booking\Models\Booking;
|
||
|
|
use Modules\Payment\Enums\PaymentStatus;
|
||
|
|
use Modules\Payment\Events\PaymentCompleted;
|
||
|
|
use Modules\Payment\Listeners\MarkBookingPaid;
|
||
|
|
use Modules\Payment\Models\Payment;
|
||
|
|
|
||
|
|
test('flips a pending_payment booking to confirmed', function () {
|
||
|
|
$booking = Booking::factory()->create(['status' => BookingStatus::PendingPayment]);
|
||
|
|
$payment = Payment::factory()->completed()->create(['booking_id' => $booking->id]);
|
||
|
|
|
||
|
|
(new MarkBookingPaid)->handle(new PaymentCompleted($payment));
|
||
|
|
|
||
|
|
expect($booking->refresh()->status)->toBe(BookingStatus::Confirmed);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('does not touch a booking that already moved on for another reason', function () {
|
||
|
|
$booking = Booking::factory()->create(['status' => BookingStatus::Cancelled]);
|
||
|
|
$payment = Payment::factory()->completed()->create(['booking_id' => $booking->id, 'status' => PaymentStatus::Completed]);
|
||
|
|
|
||
|
|
(new MarkBookingPaid)->handle(new PaymentCompleted($payment));
|
||
|
|
|
||
|
|
expect($booking->refresh()->status)->toBe(BookingStatus::Cancelled);
|
||
|
|
});
|