feat: offer rooms on request by Anf code suffix
This commit is contained in:
1 parent
2936d8947a
commit
0b0286787b
11 files changed
+204
-41
No files matched your search
@@ -12,22 +12,28 @@ use PHPUnit\Framework\TestCase;
|
||||
class RoomTest extends TestCase
|
||||
{
|
||||
#[DataProvider('bookableStateProvider')]
|
||||
public function testIsBookableState(?string $status, ?int $available, bool $expected): void
|
||||
public function testIsBookableState(?string $status, ?int $available, ?string $code, bool $expected): void
|
||||
{
|
||||
self::assertSame($expected, Room::isBookableState($status, $available));
|
||||
self::assertSame($expected, Room::isBookableState($status, $available, $code));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return iterable<string, array{?string, ?int, bool}>
|
||||
* @return iterable<string, array{?string, ?int, ?string, bool}>
|
||||
*/
|
||||
public static function bookableStateProvider(): iterable
|
||||
{
|
||||
yield 'free with rooms left' => [Constants::STATUS_AVAILABLE, 3, true];
|
||||
yield 'free but sold out' => [Constants::STATUS_AVAILABLE, 0, false];
|
||||
yield 'free without a count' => [Constants::STATUS_AVAILABLE, null, false];
|
||||
yield 'on request with rooms left' => [Constants::STATUS_ON_REQUEST, 5, false];
|
||||
yield 'on request and sold out' => [Constants::STATUS_ON_REQUEST, 0, false];
|
||||
yield 'booking stop' => [Constants::STATUS_BLOCKED, 5, false];
|
||||
yield 'no status' => [null, 5, false];
|
||||
yield 'free with rooms left' => [Constants::STATUS_AVAILABLE, 3, '2erDW', true];
|
||||
yield 'free but sold out' => [Constants::STATUS_AVAILABLE, 0, '2erDW', false];
|
||||
yield 'free without a count' => [Constants::STATUS_AVAILABLE, null, '2erDW', false];
|
||||
yield 'free with the on-request suffix' => [Constants::STATUS_AVAILABLE, 3, '6erSDAnf', true];
|
||||
yield 'on request with rooms left' => [Constants::STATUS_ON_REQUEST, 5, '2erDW', false];
|
||||
yield 'on request and sold out' => [Constants::STATUS_ON_REQUEST, 0, '2erDW', false];
|
||||
yield 'on request without a code' => [Constants::STATUS_ON_REQUEST, 5, null, false];
|
||||
yield 'on request by code with rooms left' => [Constants::STATUS_ON_REQUEST, 1, '6erSDAnf', true];
|
||||
yield 'on request by code and sold out' => [Constants::STATUS_ON_REQUEST, 0, '6erSDAnf', false];
|
||||
yield 'on request, marker not a suffix' => [Constants::STATUS_ON_REQUEST, 1, 'Anf6erSD', false];
|
||||
yield 'on request, marker in another case' => [Constants::STATUS_ON_REQUEST, 1, '6erSDANF', false];
|
||||
yield 'booking stop with the on-request suffix' => [Constants::STATUS_BLOCKED, 5, '6erSDAnf', false];
|
||||
yield 'no status' => [null, 5, '2erDW', false];
|
||||
}
|
||||
}
|
||||
@@ -100,6 +100,27 @@ class TripCatalogTest extends TestCase
|
||||
self::assertFalse($trip['dates'][1]['hotels'][0]['bookable']);
|
||||
}
|
||||
|
||||
public function testRoomsOnRequestByCodeAreListedOnRequest(): void
|
||||
{
|
||||
$rows = [
|
||||
// The office sells the suffixed room on request on purpose; the plain one stays sold out.
|
||||
$this->row('VTH', 2, '2026-12-05', 'HOT1', [$this->room(2000, available: 1, maxPax: 6, status: 'Anfrage', code: '6erSDAnf'), $this->room(300, status: 'Anfrage')]),
|
||||
// A free room makes the date free, whatever else is on request.
|
||||
$this->row('VTH', 3, '2027-01-09', 'HOT1', [$this->room(2000, available: 1, maxPax: 6, status: 'Anfrage', code: '6erSDAnf'), $this->room(500)]),
|
||||
];
|
||||
$catalog = $this->catalog($rows);
|
||||
|
||||
$results = $catalog->search(new TripCriteria())['results'];
|
||||
self::assertSame(['auf Anfrage', 'frei'], array_column($results, 'availability'));
|
||||
self::assertSame([2000.0, 500.0], array_column($results, 'priceFrom'));
|
||||
self::assertSame(['VTH2', 'VTH3'], array_column($catalog->search(new TripCriteria(persons: 6))['results'], 'dateCode'), 'its places count');
|
||||
|
||||
$trip = $catalog->get('VTH');
|
||||
self::assertNotNull($trip);
|
||||
self::assertSame(['auf Anfrage', 'ausgebucht'], array_column($trip['dates'][0]['hotels'][0]['rooms'], 'availability'));
|
||||
self::assertTrue($trip['dates'][0]['hotels'][0]['bookable']);
|
||||
}
|
||||
|
||||
public function testTheTravelPeriodContainsTheTripAndPricesApplyToTheAbPrice(): void
|
||||
{
|
||||
$rows = [$this->row('VTH', 2, '2026-12-05', 'HOT1', [$this->room(450), $this->room(700)])];
|
||||
|
||||
@@ -137,6 +137,41 @@ class BookingConfiguratorStatusTest extends TestCase
|
||||
$this->assertSame([1], array_keys($bookingDto->roomSelections));
|
||||
}
|
||||
|
||||
public function testStartFreshBookingOffersRoomsOnRequestByCode(): void
|
||||
{
|
||||
$travel = $this->createTravelWithRooms([
|
||||
['status' => Constants::STATUS_AVAILABLE, 'available' => 5],
|
||||
['status' => Constants::STATUS_ON_REQUEST, 'available' => 3],
|
||||
['status' => Constants::STATUS_ON_REQUEST, 'available' => 1, 'code' => '6erSDAnf'],
|
||||
['status' => Constants::STATUS_ON_REQUEST, 'available' => 0, 'code' => '6erSDAnf'],
|
||||
]);
|
||||
|
||||
$this->travelDataService
|
||||
->method('getTravelData')
|
||||
->willReturn($travel);
|
||||
|
||||
$bookingDto = $this->bookingService->startFreshBooking($this->createRequestWithSession(), 123, 456);
|
||||
|
||||
$this->assertSame('F', $bookingDto->bookingStatus);
|
||||
$this->assertSame([1, 3], array_keys($bookingDto->roomSelections));
|
||||
}
|
||||
|
||||
public function testStartFreshBookingWithOnlyRoomsOnRequestByCodeStaysFinalUntilSelected(): void
|
||||
{
|
||||
$travel = $this->createTravelWithRooms([
|
||||
['status' => Constants::STATUS_ON_REQUEST, 'available' => 1, 'code' => '6erSDAnf'],
|
||||
]);
|
||||
|
||||
$this->travelDataService
|
||||
->method('getTravelData')
|
||||
->willReturn($travel);
|
||||
|
||||
$bookingDto = $this->bookingService->startFreshBooking($this->createRequestWithSession(), 123, 456);
|
||||
|
||||
$this->assertSame('F', $bookingDto->bookingStatus);
|
||||
$this->assertSame([1], array_keys($bookingDto->roomSelections));
|
||||
}
|
||||
|
||||
public function testStartFreshBookingWithNoBookableRoomsThrowsException(): void
|
||||
{
|
||||
// Rooms exist but all have 0 availability
|
||||
@@ -206,6 +241,28 @@ class BookingConfiguratorStatusTest extends TestCase
|
||||
$this->assertSame('O', $bookingDto->bookingStatus);
|
||||
}
|
||||
|
||||
public function testRoomSelectionSwitchesToInquiryForRoomOnRequestByCode(): void
|
||||
{
|
||||
$bookingDto = $this->startOnRequestByCodeBooking();
|
||||
|
||||
$this->selectRoom($bookingDto, 2);
|
||||
$this->bookingService->updateBookingStatusFromRoomSelection($bookingDto);
|
||||
|
||||
$this->assertSame('A', $bookingDto->bookingStatus);
|
||||
}
|
||||
|
||||
public function testRoomSelectionRevertsInquiryWhenRoomOnRequestByCodeIsDeselected(): void
|
||||
{
|
||||
$bookingDto = $this->startOnRequestByCodeBooking();
|
||||
|
||||
$this->selectRoom($bookingDto, 2);
|
||||
$this->bookingService->updateBookingStatusFromRoomSelection($bookingDto);
|
||||
$this->selectRoom($bookingDto, 1);
|
||||
$this->bookingService->updateBookingStatusFromRoomSelection($bookingDto);
|
||||
|
||||
$this->assertSame('F', $bookingDto->bookingStatus);
|
||||
}
|
||||
|
||||
public function testRoomSelectionClearsInquiryFromStep3Fallback(): void
|
||||
{
|
||||
$bookingDto = $this->startMixedRoomsBooking();
|
||||
@@ -305,7 +362,7 @@ class BookingConfiguratorStatusTest extends TestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<array{status: string, available: int}> $roomsConfig
|
||||
* @param array<array{status: string, available: int, code?: string}> $roomsConfig
|
||||
*/
|
||||
private function createTravelWithRooms(array $roomsConfig, array $selectionGroups = []): Travel
|
||||
{
|
||||
@@ -325,6 +382,7 @@ class BookingConfiguratorStatusTest extends TestCase
|
||||
$room->price = 100.0;
|
||||
$room->available = $config['available'];
|
||||
$room->status = $config['status'];
|
||||
$room->code = $config['code'] ?? 'DZ';
|
||||
$room->minPax = 2;
|
||||
$room->category = 'A';
|
||||
$room->boardId = 1;
|
||||
@@ -369,6 +427,20 @@ class BookingConfiguratorStatusTest extends TestCase
|
||||
return $this->bookingService->startFreshBooking($this->createRequestWithSession(), 123, 456);
|
||||
}
|
||||
|
||||
/**
|
||||
* Starts a booking on a travel with a free room (id 1) and a room on request by code (id 2).
|
||||
*/
|
||||
private function startOnRequestByCodeBooking(): BookingDto
|
||||
{
|
||||
$travel = $this->createTravelWithRooms([
|
||||
['status' => Constants::STATUS_AVAILABLE, 'available' => 5],
|
||||
['status' => Constants::STATUS_ON_REQUEST, 'available' => 1, 'code' => '6erSDAnf'],
|
||||
]);
|
||||
$this->travelDataService->method('getTravelData')->willReturn($travel);
|
||||
|
||||
return $this->bookingService->startFreshBooking($this->createRequestWithSession(), 123, 456);
|
||||
}
|
||||
|
||||
private function selectRoom(BookingDto $bookingDto, int $roomId): void
|
||||
{
|
||||
foreach ($bookingDto->roomSelections as $roomSelection) {
|
||||
|
||||
Reference in new issue
Block a user