Files
famous-ly4-ev/app-modules/booking/tests/Unit/BookingServiceTest.php
T
Nyan Lin Paing 5b68f4fa38 Add Booking module: model, create/read/cancel API, Filament resource (T4.1-T4.7)
- Booking model with booking_vehicle_options line items (supports mixing
  vehicle options like front_seat + back_seat in one booking), price
  snapshot, status machine, and driver/car assignment fields
- BookingService: front-seat max, disabled-option toggles, duplicate-option
  and whole-vehicle-exclusivity guards
- CreateBookingAction, CancelBookingAction, AssignDriverAction
- BookingRefGenerator: sequential EVB-AAAAA1-style refs via row lock
- POST/GET/cancel booking API endpoints (Sanctum, ownership + admin policy)
- BookingPlugin + Filament BookingResource: list, detail view, Cancel and
  Assign Driver actions (shared between table and detail page)
- domain.md updated for multi-vehicle-option bookings (§2) and driver/
  vehicle assignment (§5a)
2026-08-08 21:43:15 +07:00

93 lines
3.3 KiB
PHP

<?php
use Modules\Booking\Data\VehicleSelectionData;
use Modules\Booking\Exceptions\InvalidVehicleSelectionException;
use Modules\Booking\Services\BookingService;
use Modules\Shared\Enums\VehicleOption;
test('a normal single-option selection of each vehicle option passes', function () {
config([
'booking.back_seat_enabled' => true,
'booking.whole_vehicle_enabled' => true,
]);
$service = new BookingService;
foreach (VehicleOption::cases() as $option) {
expect(fn () => $service->validateSelections([new VehicleSelectionData($option)]))
->not->toThrow(InvalidVehicleSelectionException::class);
}
});
test('front seat and back seat can be selected together in one booking', function () {
config(['booking.back_seat_enabled' => true]);
$service = new BookingService;
expect(fn () => $service->validateSelections([
new VehicleSelectionData(VehicleOption::FrontSeat, 1),
new VehicleSelectionData(VehicleOption::BackSeat, 2),
]))->not->toThrow(InvalidVehicleSelectionException::class);
});
test('requesting more front seats than the configured max is rejected', function () {
config(['booking.front_seat_max_per_booking' => 1]);
$service = new BookingService;
expect(fn () => $service->validateSelections([new VehicleSelectionData(VehicleOption::FrontSeat, 2)]))
->toThrow(InvalidVehicleSelectionException::class);
});
test('requesting front seats up to the configured max passes', function () {
config(['booking.front_seat_max_per_booking' => 2]);
$service = new BookingService;
expect(fn () => $service->validateSelections([new VehicleSelectionData(VehicleOption::FrontSeat, 2)]))
->not->toThrow(InvalidVehicleSelectionException::class);
});
test('back seat is rejected when disabled via config', function () {
config(['booking.back_seat_enabled' => false]);
$service = new BookingService;
expect(fn () => $service->validateSelections([new VehicleSelectionData(VehicleOption::BackSeat)]))
->toThrow(InvalidVehicleSelectionException::class);
});
test('whole vehicle is rejected when disabled via config', function () {
config(['booking.whole_vehicle_enabled' => false]);
$service = new BookingService;
expect(fn () => $service->validateSelections([new VehicleSelectionData(VehicleOption::WholeVehicle)]))
->toThrow(InvalidVehicleSelectionException::class);
});
test('the same vehicle option cannot be selected twice in one booking', function () {
config(['booking.back_seat_enabled' => true]);
$service = new BookingService;
expect(fn () => $service->validateSelections([
new VehicleSelectionData(VehicleOption::BackSeat, 1),
new VehicleSelectionData(VehicleOption::BackSeat, 1),
]))->toThrow(InvalidVehicleSelectionException::class);
});
test('whole vehicle cannot be combined with another vehicle option', function () {
config([
'booking.back_seat_enabled' => true,
'booking.whole_vehicle_enabled' => true,
]);
$service = new BookingService;
expect(fn () => $service->validateSelections([
new VehicleSelectionData(VehicleOption::WholeVehicle),
new VehicleSelectionData(VehicleOption::BackSeat),
]))->toThrow(InvalidVehicleSelectionException::class);
});