5b68f4fa38
- 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)
41 lines
1.3 KiB
PHP
41 lines
1.3 KiB
PHP
<?php
|
|
|
|
use Modules\Booking\Models\Booking;
|
|
use Modules\Booking\Services\BookingRefGenerator;
|
|
|
|
test('the first booking ref starts the sequence at AAAAA1', function () {
|
|
$ref = (new BookingRefGenerator)->generate();
|
|
|
|
expect($ref)->toBe('EVB-AAAAA1');
|
|
});
|
|
|
|
test('the ref increments digit by digit through the alphabet', function () {
|
|
Booking::factory()->create(['booking_ref' => 'EVB-AAAAA9']);
|
|
|
|
expect((new BookingRefGenerator)->generate())->toBe('EVB-AAAAAA');
|
|
});
|
|
|
|
test('the ref carries over into the next position once the alphabet is exhausted', function () {
|
|
Booking::factory()->create(['booking_ref' => 'EVB-AAAAZZ']);
|
|
|
|
expect((new BookingRefGenerator)->generate())->toBe('EVB-AAAB11');
|
|
});
|
|
|
|
test('generated refs are unique across repeated calls', function () {
|
|
$refs = [];
|
|
|
|
for ($i = 0; $i < 20; $i++) {
|
|
$ref = (new BookingRefGenerator)->generate();
|
|
Booking::factory()->create(['booking_ref' => $ref]);
|
|
$refs[] = $ref;
|
|
}
|
|
|
|
expect($refs)->toEqual(array_unique($refs));
|
|
});
|
|
|
|
test('an unrecognised existing ref format resets the sequence rather than throwing', function () {
|
|
Booking::factory()->create(['booking_ref' => 'LEGACY-2024-0001']);
|
|
|
|
expect((new BookingRefGenerator)->generate())->toBe('EVB-AAAAA1');
|
|
});
|