feat: add bookable flag to product export rooms
This commit is contained in:
1 parent
2b27b9809d
commit
0ff312c0c0
10 files changed
+126
-28
No files matched your search
@@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\BusProNet\Model;
|
||||
|
||||
use App\BusProNet\Constants;
|
||||
use App\BusProNet\Model\Room;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class RoomTest extends TestCase
|
||||
{
|
||||
#[DataProvider('bookableStateProvider')]
|
||||
public function testIsBookableState(?string $status, ?int $available, bool $expected): void
|
||||
{
|
||||
self::assertSame($expected, Room::isBookableState($status, $available));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return iterable<string, array{?string, ?int, 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];
|
||||
}
|
||||
}
|
||||
@@ -59,7 +59,7 @@ class TripCatalogTest extends TestCase
|
||||
self::assertSame(500.0, $hotelOne['priceFrom'], 'the cheapest room with places left; the stopped room does not count');
|
||||
self::assertSame(['Skipass', 'Bus', 'Halbpension', 'Programm'], $hotelOne['includes']);
|
||||
self::assertSame(['neu'], $hotelOne['flags']);
|
||||
self::assertSame('auf Anfrage', $result['results'][2]['availability']);
|
||||
self::assertSame('ausgebucht', $result['results'][2]['availability'], 'a room on request is sold out');
|
||||
self::assertSame('2026-10-08T06:00:00+00:00', $result['dataAsOf']);
|
||||
self::assertSame(1, count($this->catalog([$this->row('VTH', 2, '2026-12-05', 'HOT1', [$this->room(1)]), $this->row('VTH', 3, '2027-01-09', 'HOT1', [$this->room(1)])])->search(new TripCriteria(limit: 1))['results']));
|
||||
}
|
||||
@@ -78,6 +78,28 @@ class TripCatalogTest extends TestCase
|
||||
self::assertSame(['VTH2'], array_column($this->catalog($rows)->search(new TripCriteria(persons: 2))['results'], 'dateCode'));
|
||||
}
|
||||
|
||||
public function testRoomsOnRequestOrWithoutRoomsLeftAreListedAsSoldOut(): void
|
||||
{
|
||||
$rows = [
|
||||
// The room on request has rooms left but is sold out: its 6 places and lower price do not count.
|
||||
$this->row('VTH', 2, '2026-12-05', 'HOT1', [$this->room(400, available: 1, maxPax: 2), $this->room(300, available: 3, maxPax: 2, status: 'Anfrage')]),
|
||||
$this->row('VTH', 3, '2027-01-09', 'HOT1', [$this->room(500, available: 0), $this->room(450, status: 'Anfrage')]),
|
||||
];
|
||||
$catalog = $this->catalog($rows);
|
||||
|
||||
$results = $catalog->search(new TripCriteria())['results'];
|
||||
self::assertSame(['VTH2', 'VTH3'], array_column($results, 'dateCode'), 'sold-out dates stay listed, as on the website');
|
||||
self::assertSame([400.0, 450.0], array_column($results, 'priceFrom'));
|
||||
self::assertSame(['frei', 'ausgebucht'], array_column($results, 'availability'));
|
||||
self::assertSame([], $catalog->search(new TripCriteria(persons: 3))['results']);
|
||||
|
||||
$trip = $catalog->get('VTH');
|
||||
self::assertNotNull($trip);
|
||||
self::assertSame(['frei', 'ausgebucht'], array_column($trip['dates'][0]['hotels'][0]['rooms'], 'availability'));
|
||||
self::assertTrue($trip['dates'][0]['hotels'][0]['bookable']);
|
||||
self::assertFalse($trip['dates'][1]['hotels'][0]['bookable']);
|
||||
}
|
||||
|
||||
public function testTheTravelPeriodContainsTheTripAndPricesApplyToTheAbPrice(): void
|
||||
{
|
||||
$rows = [$this->row('VTH', 2, '2026-12-05', 'HOT1', [$this->room(450), $this->room(700)])];
|
||||
|
||||
@@ -69,12 +69,14 @@ class ProductExportBuilderTest extends TestCase
|
||||
'price' => 229.5,
|
||||
'available' => 24,
|
||||
'status' => 'Frei',
|
||||
'bookable' => true,
|
||||
'boardCode' => 'Lt. Auss.',
|
||||
'boardBusProId' => 2,
|
||||
], $rooms[0]);
|
||||
|
||||
// Buchungsstop rooms reach the consumer: "ausgebucht" is its call.
|
||||
self::assertSame('Buchungsstop', $rooms[1]['status']);
|
||||
self::assertFalse($rooms[1]['bookable']);
|
||||
self::assertSame(3, $rooms[1]['maxPax'], 'MaxPax is read despite its casing');
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user