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
@@ -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