fix: refresh live room availability during create flow
This commit is contained in:
1 parent
a73e8a593f
commit
cdce7d57e0
26 files changed
+1976
-54
No files matched your search
@@ -82,6 +82,39 @@ class TravelTest extends TestCase
|
||||
$this->assertCount(2, $result);
|
||||
}
|
||||
|
||||
public function testGetAvailableRoomsExcludesSoldOutRooms(): void
|
||||
{
|
||||
$travel = new Travel();
|
||||
|
||||
$availableRoom = new \App\BusProNet\Model\Room();
|
||||
$availableRoom->id = 1;
|
||||
$availableRoom->label = 'Doppelzimmer';
|
||||
$availableRoom->available = 2;
|
||||
$availableRoom->status = 'Frei';
|
||||
|
||||
$soldOutRoom = new \App\BusProNet\Model\Room();
|
||||
$soldOutRoom->id = 2;
|
||||
$soldOutRoom->label = 'Einzelzimmer';
|
||||
$soldOutRoom->available = 0;
|
||||
$soldOutRoom->status = 'Frei';
|
||||
|
||||
$requestRoom = new \App\BusProNet\Model\Room();
|
||||
$requestRoom->id = 3;
|
||||
$requestRoom->label = 'Familienzimmer';
|
||||
$requestRoom->available = 1;
|
||||
$requestRoom->status = 'Anfrage';
|
||||
|
||||
$travel->rooms = [$availableRoom, $soldOutRoom, $requestRoom];
|
||||
|
||||
$result = $travel->getAvailableRooms();
|
||||
|
||||
$this->assertSame([
|
||||
1 => $availableRoom,
|
||||
3 => $requestRoom,
|
||||
], $result);
|
||||
$this->assertArrayNotHasKey(2, $result);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that services are sorted by subType.
|
||||
*/
|
||||
|
||||
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\BusProNet\XmlLoader;
|
||||
|
||||
use App\BusProNet\Model\BaseData;
|
||||
use App\BusProNet\Model\Room;
|
||||
use App\BusProNet\Model\Travel;
|
||||
use App\BusProNet\XmlLoader\HotelLoader;
|
||||
use App\BusProNet\XmlLoader\TravelLoader;
|
||||
use App\BusProNet\XmlParser\TravelParser;
|
||||
use League\Flysystem\FilesystemOperator;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Cache\Adapter\ArrayAdapter;
|
||||
|
||||
class TravelLoaderTest extends TestCase
|
||||
{
|
||||
public function testPatchRoomAvailabilitiesAppliesLiveRoomDataToMatchingRooms(): void
|
||||
{
|
||||
$loader = $this->createLoader();
|
||||
|
||||
$travel = new Travel();
|
||||
|
||||
$patchedRoom = new Room();
|
||||
$patchedRoom->id = 1;
|
||||
$patchedRoom->available = 2;
|
||||
$patchedRoom->status = 'Frei';
|
||||
$patchedRoom->price = 100.0;
|
||||
|
||||
$otherRoom = new Room();
|
||||
$otherRoom->id = 2;
|
||||
$otherRoom->available = 1;
|
||||
$otherRoom->status = 'Frei';
|
||||
$otherRoom->price = 150.0;
|
||||
|
||||
$travel->rooms = [$patchedRoom, $otherRoom];
|
||||
|
||||
$liveRoom = new Room();
|
||||
$liveRoom->id = 1;
|
||||
$liveRoom->available = 0;
|
||||
$liveRoom->status = 'Anfrage';
|
||||
$liveRoom->price = 110.0;
|
||||
$liveRoom->label = 'Live room';
|
||||
$liveRoom->category = 'Live category';
|
||||
|
||||
$loader->patchRoomAvailabilities($travel, new BaseData([
|
||||
1 => $liveRoom,
|
||||
]));
|
||||
|
||||
$this->assertSame(0, $travel->rooms[0]->available);
|
||||
$this->assertSame('Anfrage', $travel->rooms[0]->status);
|
||||
$this->assertSame(110.0, $travel->rooms[0]->price);
|
||||
$this->assertSame('Live room', $travel->rooms[0]->label);
|
||||
$this->assertSame('Live category', $travel->rooms[0]->category);
|
||||
|
||||
$this->assertSame(1, $travel->rooms[1]->available);
|
||||
$this->assertSame('Frei', $travel->rooms[1]->status);
|
||||
$this->assertSame(150.0, $travel->rooms[1]->price);
|
||||
}
|
||||
|
||||
private function createLoader(): TravelLoader
|
||||
{
|
||||
return new TravelLoader(
|
||||
$this->createMock(HotelLoader::class),
|
||||
$this->createMock(TravelParser::class),
|
||||
'https://example.com',
|
||||
new ArrayAdapter(),
|
||||
$this->createMock(FilesystemOperator::class),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\BusProNet\XmlParser;
|
||||
|
||||
use App\BusProNet\Constants;
|
||||
use App\BusProNet\Model\Room;
|
||||
use App\BusProNet\XmlParser\AvailabilitiesParser;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\DomCrawler\Crawler;
|
||||
|
||||
class AvailabilitiesParserTest extends TestCase
|
||||
{
|
||||
private AvailabilitiesParser $parser;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->parser = new AvailabilitiesParser();
|
||||
}
|
||||
|
||||
public function testParseRoomsNormalizesHotelAvailabilityStatuses(): void
|
||||
{
|
||||
$xml = <<<'XML'
|
||||
<ergebnis>
|
||||
<unterbringungen>
|
||||
<unterbringung id_zimmer="1" bezeichnung="Room 1" kategorie="A" verpflegung="Board" frei="1" status="buchbar" preis="749,00" />
|
||||
<unterbringung id_zimmer="2" bezeichnung="Room 2" kategorie="B" verpflegung="Board" frei="-900" status="anfrage" preis="849,00" />
|
||||
<unterbringung id_zimmer="3" bezeichnung="Room 3" kategorie="C" verpflegung="Board" frei="0" status="stopp" preis="949,00" />
|
||||
</unterbringungen>
|
||||
</ergebnis>
|
||||
XML;
|
||||
|
||||
$rooms = $this->parser->parseRooms(new Crawler($xml))->getItems();
|
||||
|
||||
$this->assertContainsOnlyInstancesOf(Room::class, $rooms);
|
||||
$this->assertSame(Constants::STATUS_AVAILABLE, $rooms[1]->status);
|
||||
$this->assertSame(Constants::STATUS_ON_REQUEST, $rooms[2]->status);
|
||||
$this->assertSame(Constants::STATUS_BLOCKED, $rooms[3]->status);
|
||||
}
|
||||
|
||||
public function testParseRoomsLogsUnrecognizedStatus(): void
|
||||
{
|
||||
$logger = $this->createMock(LoggerInterface::class);
|
||||
$logger->expects($this->once())
|
||||
->method('warning')
|
||||
->with(
|
||||
'Unrecognized room availability status from BusProNet XML',
|
||||
['status' => 'foo']
|
||||
);
|
||||
|
||||
$parser = new AvailabilitiesParser($logger);
|
||||
|
||||
$xml = <<<'XML'
|
||||
<ergebnis>
|
||||
<unterbringungen>
|
||||
<unterbringung id_zimmer="1" bezeichnung="Room 1" kategorie="A" verpflegung="Board" frei="1" status="foo" preis="749,00" />
|
||||
</unterbringungen>
|
||||
</ergebnis>
|
||||
XML;
|
||||
|
||||
$rooms = $parser->parseRooms(new Crawler($xml))->getItems();
|
||||
|
||||
$this->assertSame('foo', $rooms[1]->status);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user