feat: inquiry bookings

This commit is contained in:
Björn Fromme
2026-03-16 11:59:10 +01:00
parent 2d9cb2c0b9
commit 023ecdebc9
11 changed files with 360 additions and 4 deletions
@@ -184,4 +184,103 @@ class TravelParserTest extends TestCase
$this->assertSame('Service with empty description', $service->label);
$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"?>
<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>
<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->assertNull($travel->status); // No status_hin node should result in null
}
}
+164
View File
@@ -0,0 +1,164 @@
<?php
declare(strict_types=1);
namespace App\Tests\Service;
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;
use App\Service\ParticipantEligibilityService;
use App\Service\TravelDataService;
use PHPUnit\Framework\TestCase;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Session\Session;
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
class BookingServiceStatusTest extends TestCase
{
private BookingService $bookingService;
private TravelDataService $travelDataService;
protected function setUp(): void
{
$this->travelDataService = $this->createMock(TravelDataService::class);
$priceCalculator = $this->createMock(BookingPriceCalculatorService::class);
$participantEligibility = $this->createMock(ParticipantEligibilityService::class);
$this->bookingService = new BookingService(
$this->travelDataService,
$priceCalculator,
$participantEligibility
);
}
public function testStartFreshBookingWithFreiStatus(): void
{
$travel = $this->createTravelWithStatus('Frei', 5);
$this->travelDataService
->method('getTravelData')
->willReturn($travel);
$request = $this->createRequestWithSession();
$bookingDto = $this->bookingService->startFreshBooking($request, 123, 456);
$this->assertSame('F', $bookingDto->bookingStatus);
$this->assertCount(1, $bookingDto->roomSelections);
}
public function testStartFreshBookingWithFreiStatusAndNoRoomsThrowsException(): void
{
$travel = $this->createTravelWithStatus('Frei', 0);
$this->travelDataService
->method('getTravelData')
->willReturn($travel);
$request = $this->createRequestWithSession();
$this->expectException(NoRoomsAvailableException::class);
$this->bookingService->startFreshBooking($request, 123, 456);
}
public function testStartFreshBookingWithAnfrageStatus(): void
{
$travel = $this->createTravelWithStatus('Anfrage', 5);
$this->travelDataService
->method('getTravelData')
->willReturn($travel);
$request = $this->createRequestWithSession();
$bookingDto = $this->bookingService->startFreshBooking($request, 123, 456);
$this->assertSame('A', $bookingDto->bookingStatus);
$this->assertCount(1, $bookingDto->roomSelections);
}
public function testStartFreshBookingWithAnfrageStatusAndNoRoomsAllowsBooking(): void
{
$travel = $this->createTravelWithStatus('Anfrage', 0);
$this->travelDataService
->method('getTravelData')
->willReturn($travel);
$request = $this->createRequestWithSession();
$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
{
$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');
$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;
$travel->rooms = [1 => $room];
return $travel;
}
private function createRequestWithSession(): Request
{
$session = new Session(new MockArraySessionStorage());
$request = new Request();
$request->setSession($session);
return $request;
}
}