feat: cap rooms sharing a contingent per booking

This commit is contained in:
fromme committed 2026-11-11 16:35:49 +01:00
1 parent 5942ecf340
commit 3d94505e8d
18 files changed
+671 -19

No files matched your search

+68
View File
@@ -0,0 +1,68 @@
<?php
declare(strict_types=1);
namespace App\Tests\BpnConnect;
use App\BpnConnect\Exception\BpnConnectException;
use App\BpnConnect\RoomsClient;
use PHPUnit\Framework\TestCase;
use Psr\Log\NullLogger;
use Symfony\Component\HttpClient\MockHttpClient;
use Symfony\Component\HttpClient\Response\MockResponse;
class RoomsClientTest extends TestCase
{
public function testGetContingentPoolsQueriesTheHotelAndMapsEachRoomTypeToItsPool(): void
{
$requests = [];
$http = new MockHttpClient(function (string $method, string $url) use (&$requests): MockResponse {
$requests[] = [$method, $url];
return $this->jsonResponse([
'meta' => ['hotel_id' => 163113, 'count' => 3, 'execution_time_ms' => 3],
'data' => [
['room_type_id' => 27, 'pool_room_type_id' => 27],
['room_type_id' => 2366, 'pool_room_type_id' => 2366],
['room_type_id' => 2367, 'pool_room_type_id' => 2366],
],
]);
});
$pools = $this->client($http)->getContingentPools(163113);
self::assertSame([['GET', 'https://bpn-connect.test/api/v1/rooms/contingent-pools?hotelId=163113']], $requests);
self::assertSame([27 => 27, 2366 => 2366, 2367 => 2366], $pools);
}
public function testAnUnknownHotelYieldsNoPools(): void
{
$http = new MockHttpClient($this->jsonResponse(['meta' => ['hotel_id' => 1, 'count' => 0], 'data' => []]));
self::assertSame([], $this->client($http)->getContingentPools(1));
}
public function testAFailedRequestThrows(): void
{
$http = new MockHttpClient(new MockResponse('', ['http_code' => 500]));
$this->expectException(BpnConnectException::class);
$this->client($http)->getContingentPools(163113);
}
/**
* @param array<string, mixed> $payload
*/
private function jsonResponse(array $payload): MockResponse
{
return new MockResponse(json_encode($payload, JSON_THROW_ON_ERROR), [
'response_headers' => ['content-type' => 'application/json'],
]);
}
private function client(MockHttpClient $http): RoomsClient
{
return new RoomsClient($http, new NullLogger(), 'https://bpn-connect.test', 'secret');
}
}