feat: correct determination of inquiry status and conditional voucher field display

This commit is contained in:
Björn Fromme
2025-11-25 16:41:25 +01:00
parent f33e55f201
commit ecc4741f56
19 changed files with 468 additions and 193 deletions
+95 -53
View File
@@ -4,9 +4,9 @@ declare(strict_types=1);
namespace App\Tests\Service;
use App\BusProNet\Constants;
use App\BusProNet\Model\Room;
use App\BusProNet\Model\Travel;
use App\Exception\BookingNotPossibleException;
use App\Exception\NoRoomsAvailableException;
use App\Service\BookingPriceCalculatorService;
use App\Service\BookingService;
@@ -35,9 +35,11 @@ class BookingServiceStatusTest extends TestCase
);
}
public function testStartFreshBookingWithFreiStatus(): void
public function testStartFreshBookingWithFreiRooms(): void
{
$travel = $this->createTravelWithStatus('Frei', 5);
$travel = $this->createTravelWithRooms([
['status' => Constants::STATUS_AVAILABLE, 'available' => 5],
]);
$this->travelDataService
->method('getTravelData')
@@ -51,9 +53,11 @@ class BookingServiceStatusTest extends TestCase
$this->assertCount(1, $bookingDto->roomSelections);
}
public function testStartFreshBookingWithFreiStatusAndNoRoomsThrowsException(): void
public function testStartFreshBookingWithFreiRoomsAndNoAvailabilityThrowsException(): void
{
$travel = $this->createTravelWithStatus('Frei', 0);
$travel = $this->createTravelWithRooms([
['status' => Constants::STATUS_AVAILABLE, 'available' => 0],
]);
$this->travelDataService
->method('getTravelData')
@@ -66,9 +70,11 @@ class BookingServiceStatusTest extends TestCase
$this->bookingService->startFreshBooking($request, 123, 456);
}
public function testStartFreshBookingWithAnfrageStatus(): void
public function testStartFreshBookingWithAnfrageRooms(): void
{
$travel = $this->createTravelWithStatus('Anfrage', 5);
$travel = $this->createTravelWithRooms([
['status' => Constants::STATUS_ON_REQUEST, 'available' => 5],
]);
$this->travelDataService
->method('getTravelData')
@@ -82,9 +88,69 @@ class BookingServiceStatusTest extends TestCase
$this->assertCount(1, $bookingDto->roomSelections);
}
public function testStartFreshBookingWithAnfrageStatusAndNoRoomsAllowsBooking(): void
public function testStartFreshBookingWithAnfrageRoomsAndNoAvailabilityThrowsException(): void
{
$travel = $this->createTravelWithStatus('Anfrage', 0);
$travel = $this->createTravelWithRooms([
['status' => Constants::STATUS_ON_REQUEST, 'available' => 0],
]);
$this->travelDataService
->method('getTravelData')
->willReturn($travel);
$request = $this->createRequestWithSession();
$this->expectException(NoRoomsAvailableException::class);
$this->bookingService->startFreshBooking($request, 123, 456);
}
public function testStartFreshBookingWithMixedRoomsUsesFreeStatus(): void
{
// When both Frei and Anfrage rooms with availability exist, booking status should be 'F'
$travel = $this->createTravelWithRooms([
['status' => Constants::STATUS_AVAILABLE, 'available' => 5],
['status' => Constants::STATUS_ON_REQUEST, 'available' => 3],
]);
$this->travelDataService
->method('getTravelData')
->willReturn($travel);
$request = $this->createRequestWithSession();
$bookingDto = $this->bookingService->startFreshBooking($request, 123, 456);
$this->assertSame('F', $bookingDto->bookingStatus);
$this->assertCount(2, $bookingDto->roomSelections);
}
public function testStartFreshBookingWithNoBookableRoomsThrowsException(): void
{
// Rooms exist but all have 0 availability
$travel = $this->createTravelWithRooms([
['status' => Constants::STATUS_AVAILABLE, 'available' => 0],
['status' => Constants::STATUS_ON_REQUEST, 'available' => 0],
]);
$this->travelDataService
->method('getTravelData')
->willReturn($travel);
$request = $this->createRequestWithSession();
$this->expectException(NoRoomsAvailableException::class);
$this->bookingService->startFreshBooking($request, 123, 456);
}
public function testStartFreshBookingWithApiRestrictionsForcesInquiry(): void
{
// Even with Frei rooms, if API says only 'A' allowed, booking status should be 'A'
$travel = $this->createTravelWithRooms([
['status' => Constants::STATUS_AVAILABLE, 'available' => 5],
]);
$travel->allowedBookingStatus = ['A']; // API restricts to inquiry only
$this->travelDataService
->method('getTravelData')
@@ -95,60 +161,36 @@ class BookingServiceStatusTest extends TestCase
$bookingDto = $this->bookingService->startFreshBooking($request, 123, 456);
$this->assertSame('A', $bookingDto->bookingStatus);
$this->assertCount(1, $bookingDto->roomSelections);
}
public function testStartFreshBookingWithBuchungsstopThrowsException(): void
{
$travel = $this->createTravelWithStatus('Buchungsstop', 5);
$this->travelDataService
->method('getTravelData')
->willReturn($travel);
$request = $this->createRequestWithSession();
$this->expectException(BookingNotPossibleException::class);
$this->expectExceptionMessage('Für diese Reise ist aktuell keine Buchung möglich');
$this->bookingService->startFreshBooking($request, 123, 456);
}
public function testStartFreshBookingWithBuchungsstopAndNoRoomsThrowsException(): void
{
$travel = $this->createTravelWithStatus('Buchungsstop', 0);
$this->travelDataService
->method('getTravelData')
->willReturn($travel);
$request = $this->createRequestWithSession();
$this->expectException(BookingNotPossibleException::class);
$this->bookingService->startFreshBooking($request, 123, 456);
}
private function createTravelWithStatus(string $status, int $availability): Travel
/**
* @param array<array{status: string, available: int}> $roomsConfig
*/
private function createTravelWithRooms(array $roomsConfig): Travel
{
$travel = new Travel();
$travel->id = 123;
$travel->hotelId = 456;
$travel->status = $status;
$travel->dateFrom = new \DateTimeImmutable('2030-01-01');
$travel->dateTo = new \DateTimeImmutable('2030-01-06');
$travel->allowedBookingStatus = []; // Empty means no API restrictions
$room = new Room();
$room->id = 1;
$room->label = 'Test Room';
$room->price = 100.0;
$room->available = $availability;
$room->status = \App\BusProNet\Constants::STATUS_AVAILABLE;
$room->minPax = 2;
$room->category = 'A';
$room->boardId = 1;
$rooms = [];
foreach ($roomsConfig as $index => $config) {
$room = new Room();
$room->id = $index + 1;
$room->label = 'Test Room '.($index + 1);
$room->price = 100.0;
$room->available = $config['available'];
$room->status = $config['status'];
$room->minPax = 2;
$room->category = 'A';
$room->boardId = 1;
$travel->rooms = [1 => $room];
$rooms[$room->id] = $room;
}
$travel->rooms = $rooms;
return $travel;
}