39 lines
1.5 KiB
PHP
39 lines
1.5 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
use Modules\Booking\Actions\CancelBookingAction;
|
||
|
|
use Modules\Booking\Enums\BookingStatus;
|
||
|
|
use Modules\Booking\Exceptions\BookingCannotBeCancelledException;
|
||
|
|
use Modules\Booking\Models\Booking;
|
||
|
|
|
||
|
|
test('it cancels a pending_payment booking', function () {
|
||
|
|
$booking = Booking::factory()->create(['status' => BookingStatus::PendingPayment]);
|
||
|
|
|
||
|
|
$cancelled = (new CancelBookingAction)->handle($booking);
|
||
|
|
|
||
|
|
expect($cancelled->status)->toBe(BookingStatus::Cancelled)
|
||
|
|
->and($booking->refresh()->status)->toBe(BookingStatus::Cancelled);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('it guards against cancelling a confirmed booking', function () {
|
||
|
|
$booking = Booking::factory()->create(['status' => BookingStatus::Confirmed]);
|
||
|
|
|
||
|
|
expect(fn () => (new CancelBookingAction)->handle($booking))
|
||
|
|
->toThrow(BookingCannotBeCancelledException::class);
|
||
|
|
|
||
|
|
expect($booking->refresh()->status)->toBe(BookingStatus::Confirmed);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('it guards against cancelling an already cancelled booking', function () {
|
||
|
|
$booking = Booking::factory()->create(['status' => BookingStatus::Cancelled]);
|
||
|
|
|
||
|
|
expect(fn () => (new CancelBookingAction)->handle($booking))
|
||
|
|
->toThrow(BookingCannotBeCancelledException::class);
|
||
|
|
});
|
||
|
|
|
||
|
|
test('it guards against cancelling an expired booking', function () {
|
||
|
|
$booking = Booking::factory()->create(['status' => BookingStatus::Expired]);
|
||
|
|
|
||
|
|
expect(fn () => (new CancelBookingAction)->handle($booking))
|
||
|
|
->toThrow(BookingCannotBeCancelledException::class);
|
||
|
|
});
|