feat: stop booking flow when BusPro is unreachable
This commit is contained in:
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,
|
||||
|
||||
@@ -13,6 +13,7 @@ use App\BusProNet\Model\Travel;
|
||||
use App\BusProNet\Service\BookingStatusRuleRegistry;
|
||||
use App\BusProNet\Service\StatusRule\Selection1473StatusRule;
|
||||
use App\BusProNet\XmlLoader\AgencyLoader;
|
||||
use App\Exception\BookingBackendUnavailableException;
|
||||
use App\Exception\NoRoomsAvailableException;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Model\ParticipantDto;
|
||||
@@ -69,6 +70,28 @@ class BookingConfiguratorStatusTest extends TestCase
|
||||
$this->assertCount(1, $bookingDto->roomSelections);
|
||||
}
|
||||
|
||||
public function testStartFreshBookingRequiresAReachableBusPro(): void
|
||||
{
|
||||
$travel = $this->createTravelWithRooms([
|
||||
['status' => Constants::STATUS_AVAILABLE, 'available' => 5],
|
||||
]);
|
||||
|
||||
$this->travelDataService
|
||||
->method('getTravelData')
|
||||
->willReturn($travel);
|
||||
$this->travelDataService
|
||||
->method('getAvailabilityData')
|
||||
->willReturnCallback(function (int $dateId, bool $cached = false, bool $forceRefresh = false, bool $requireReachable = false): never {
|
||||
$this->assertTrue($requireReachable, 'Starting a booking must not fall back to export data silently');
|
||||
|
||||
throw new BookingBackendUnavailableException();
|
||||
});
|
||||
|
||||
$this->expectException(BookingBackendUnavailableException::class);
|
||||
|
||||
$this->bookingService->startFreshBooking($this->createRequestWithSession(), 123, 456);
|
||||
}
|
||||
|
||||
public function testStartFreshBookingWithFreiRoomsAndNoAvailabilityThrowsException(): void
|
||||
{
|
||||
$travel = $this->createTravelWithRooms([
|
||||
|
||||
@@ -5,8 +5,11 @@ declare(strict_types=1);
|
||||
namespace App\Tests\Service;
|
||||
|
||||
use App\BusProNet\Client\TravelClient;
|
||||
use App\BusProNet\Exception\ApiClientException;
|
||||
use App\BusProNet\Exception\TimeoutException;
|
||||
use App\BusProNet\Model\Travel;
|
||||
use App\BusProNet\XmlLoader\TravelLoader;
|
||||
use App\Exception\BookingBackendUnavailableException;
|
||||
use App\Exception\TravelNotFoundException;
|
||||
use App\Service\TravelDataProvider;
|
||||
use App\Service\TravelEnricher;
|
||||
@@ -14,6 +17,7 @@ use App\Service\TravelIndex;
|
||||
use App\Service\TravelSnapshotManager;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Cache\Adapter\ArrayAdapter;
|
||||
use Symfony\Contracts\Cache\CacheInterface;
|
||||
|
||||
class TravelDataProviderTest extends TestCase
|
||||
@@ -494,4 +498,48 @@ class TravelDataProviderTest extends TestCase
|
||||
|
||||
$this->assertSame($travel, $result);
|
||||
}
|
||||
|
||||
public function testGetAvailabilityDataReturnsNullWhenBusProIsUnreachable(): void
|
||||
{
|
||||
$this->travelClient = $this->createStub(TravelClient::class);
|
||||
$this->travelClient->method('getAvailabilities')->willThrowException(new TimeoutException('Stream timeout'));
|
||||
|
||||
$this->assertNull($this->service()->getAvailabilityData(4711));
|
||||
}
|
||||
|
||||
public function testGetAvailabilityDataThrowsWhenBusProIsUnreachableAndRequired(): void
|
||||
{
|
||||
$this->travelClient = $this->createStub(TravelClient::class);
|
||||
$this->travelClient->method('getAvailabilities')->willThrowException(new ApiClientException('Unable to open socket'));
|
||||
|
||||
$this->expectException(BookingBackendUnavailableException::class);
|
||||
|
||||
$this->service()->getAvailabilityData(4711, requireReachable: true);
|
||||
}
|
||||
|
||||
public function testGetAvailabilityDataDoesNotCacheAFailedConnection(): void
|
||||
{
|
||||
$this->travelClient = $this->createStub(TravelClient::class);
|
||||
$this->travelClient->method('getAvailabilities')->willThrowException(new ApiClientException('Unable to open socket'));
|
||||
|
||||
$cache = new ArrayAdapter();
|
||||
$this->cache = $cache;
|
||||
|
||||
$this->assertNull($this->service()->getAvailabilityData(4711, cached: true));
|
||||
$this->assertFalse($cache->hasItem('availability_4711'), 'The next call must ask BusPro again');
|
||||
}
|
||||
|
||||
public function testEnrichWithFreshAvailabilitiesThrowsWhenBusProIsUnreachableAndRequired(): void
|
||||
{
|
||||
$this->travelClient = $this->createStub(TravelClient::class);
|
||||
$this->travelClient->method('getAvailabilities')->willThrowException(new ApiClientException('Unable to open socket'));
|
||||
$this->cache = new ArrayAdapter();
|
||||
|
||||
$travel = new Travel();
|
||||
$travel->id = 4711;
|
||||
|
||||
$this->expectException(BookingBackendUnavailableException::class);
|
||||
|
||||
$this->service()->enrichWithFreshAvailabilities($travel, requireReachable: true);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user