feat: stop booking flow when BusPro is unreachable

This commit is contained in:
fromme committed 2026-11-11 19:51:52 +01:00
1 parent ac23baf625
commit 55378b2bbc
9 files changed
+249 -43

No files matched your search

@@ -10,6 +10,7 @@ use App\BusProNet\Model\CrmSelectionGroup;
use App\BusProNet\Model\Room;
use App\BusProNet\Model\Travel;
use App\Controller\Booking\Create\Step2Controller;
use App\Exception\BookingBackendUnavailableException;
use App\Form\Model\BookingDto;
use App\Form\Model\ParticipantDto;
use App\Form\Model\RoomSelectionDto;
@@ -184,6 +185,66 @@ class Step2ControllerTest extends TestCase
$this->assertCount(6, $bookingDto->participants, 'Two rooms for three people each yield six participants');
}
public function testSendsCustomerBackToStep1WhenBusProIsUnreachableOnOpeningTheStep(): void
{
$bookingDto = $this->createBookingDto($this->createTravel([$this->createRoom(1409, 'Einzelzimmer', minPax: 1)]));
$travelDataService = $this->createMock(TravelDataProvider::class);
$travelDataService->expects($this->once())
->method('enrichWithFreshAvailabilities')
->with($bookingDto->travel, true, true)
->willThrowException(new BookingBackendUnavailableException());
$bookingService = $this->createMock(BookingConfigurator::class);
$bookingService->expects($this->never())->method('reconcileRoomSelections');
$bookingSessionService = $this->createStub(BookingSessionManager::class);
$bookingSessionService->method('getOrCreateBookingCreateDto')->willReturn($bookingDto);
$controller = $this->createController(
$bookingService,
$bookingSessionService,
$this->createStub(LoggerInterface::class),
$travelDataService,
);
$response = $controller->index(Request::create('/bookings/create/participants', 'GET'));
$this->assertInstanceOf(RedirectResponse::class, $response);
$this->assertSame('/app_booking_create_step_1', $response->getTargetUrl());
$this->assertSame(
[['error', 'Unser Buchungssystem ist gerade nicht erreichbar. Deine Zimmerauswahl bleibt gespeichert, bitte versuche es in ein paar Minuten erneut.']],
$controller->flashes
);
}
public function testDoesNotRequireAReachableBusProWhenTheStepIsSubmitted(): void
{
$bookingDto = $this->createBookingDto($this->createTravel([$this->createRoom(1409, 'Einzelzimmer', minPax: 1)]));
$travelDataService = $this->createMock(TravelDataProvider::class);
$travelDataService->expects($this->once())
->method('enrichWithFreshAvailabilities')
->with($bookingDto->travel, true, false);
$bookingService = $this->createStub(BookingConfigurator::class);
$bookingService->method('reconcileRoomSelections')->willReturn([]);
$bookingSessionService = $this->createStub(BookingSessionManager::class);
$bookingSessionService->method('getOrCreateBookingCreateDto')->willReturn($bookingDto);
$controller = $this->createController(
$bookingService,
$bookingSessionService,
$this->createStub(LoggerInterface::class),
$travelDataService,
);
$controller->index(Request::create('/bookings/create/participants', 'POST'));
$this->assertSame([], $controller->flashes);
}
public function testEndsASplitTheTravelDateDoesNotOffer(): void
{
$bookingDto = $this->createSplitBookingDto($this->createTravel([$this->createRoom(1409, 'Einzelzimmer', minPax: 1)]));
@@ -245,6 +306,7 @@ class Step2ControllerTest extends TestCase
BookingConfigurator $bookingService,
BookingSessionManager $bookingSessionService,
LoggerInterface $logger,
?TravelDataProvider $travelDataService = null,
): TestableStep2Controller {
$form = $this->createStub(FormInterface::class);
$form->method('isSubmitted')->willReturn(false);
@@ -253,7 +315,7 @@ class Step2ControllerTest extends TestCase
$bookingService,
$bookingSessionService,
$this->createStub(BookingCreateContextFactory::class),
$this->createStub(TravelDataProvider::class),
$travelDataService ?? $this->createStub(TravelDataProvider::class),
$this->createStub(RoomAssigner::class),
$this->createStub(ParticipantDataPrefiller::class),
$logger,