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
@@ -185,81 +185,6 @@ class TravelParserTest extends TestCase
$this->assertNull($service->description); // Empty hinweis should result in null description
}
public function testParseTravelStatusFrei(): void
{
$xmlContent = '<?xml version="1.0" encoding="utf-8"?>
<reisen>
<reise id="1" idbuspro="2187" code="SSTMR">
<termin id="1" idbuspro="11946" termin="01.01.2030" bis="06.01.2030" reiseart="F">
<text>Test Travel</text>
<abpreis>659,00</abpreis>
<status_hin>Frei</status_hin>
<hotel id="1" idbuspro="157047">
<zimmer>
<preis zimmercode="4erDW" idbuspro_zimmer="95" zimmertext="4er Zimmer" MinPax="4" MaxPax="4" naechte="5" preis="689,00" status="Frei" verfuegbar="8" />
</zimmer>
</hotel>
</termin>
</reise>
</reisen>';
$crawler = new Crawler($xmlContent);
$travelNode = $crawler->filterXPath('//reise/termin')->first();
$travel = $this->parser->parse($travelNode);
$this->assertSame('Frei', $travel->status);
}
public function testParseTravelStatusAnfrage(): void
{
$xmlContent = '<?xml version="1.0" encoding="utf-8"?>
<reisen>
<reise id="1" idbuspro="2187" code="SSTMR">
<termin id="1" idbuspro="11946" termin="01.01.2030" bis="06.01.2030" reiseart="F">
<text>Test Travel</text>
<abpreis>659,00</abpreis>
<status_hin>Anfrage</status_hin>
<hotel id="1" idbuspro="157047">
<zimmer>
<preis zimmercode="4erDW" idbuspro_zimmer="95" zimmertext="4er Zimmer" MinPax="4" MaxPax="4" naechte="5" preis="689,00" status="Frei" verfuegbar="0" />
</zimmer>
</hotel>
</termin>
</reise>
</reisen>';
$crawler = new Crawler($xmlContent);
$travelNode = $crawler->filterXPath('//reise/termin')->first();
$travel = $this->parser->parse($travelNode);
$this->assertSame('Anfrage', $travel->status);
}
public function testParseTravelStatusBuchungsstop(): void
{
$xmlContent = '<?xml version="1.0" encoding="utf-8"?>
<reisen>
<reise id="1" idbuspro="2187" code="SSTMR">
<termin id="1" idbuspro="11946" termin="01.01.2030" bis="06.01.2030" reiseart="F">
<text>Test Travel</text>
<abpreis>659,00</abpreis>
<status_hin>Buchungsstop</status_hin>
<hotel id="1" idbuspro="157047">
<zimmer>
<preis zimmercode="4erDW" idbuspro_zimmer="95" zimmertext="4er Zimmer" MinPax="4" MaxPax="4" naechte="5" preis="689,00" status="Frei" verfuegbar="5" />
</zimmer>
</hotel>
</termin>
</reise>
</reisen>';
$crawler = new Crawler($xmlContent);
$travelNode = $crawler->filterXPath('//reise/termin')->first();
$travel = $this->parser->parse($travelNode);
$this->assertSame('Buchungsstop', $travel->status);
}
public function testParseTravelWithoutStatus(): void
{
$xmlContent = '<?xml version="1.0" encoding="utf-8"?>
+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;
}