fix: treat dates without price as unavailable

This commit is contained in:
Björn Fromme
2026-08-04 11:29:58 +02:00
parent 331c88c38e
commit 8ff13614d2
8 changed files with 407 additions and 23 deletions
@@ -9,22 +9,56 @@ use App\Controller\Api\ContingentController;
use App\Entity\Groups\AccommodationPrice;
use App\Repository\Groups\AccommodationPriceRepository;
use App\Repository\Groups\AccommodationRepository;
use App\Service\AccommodationPriceCoverage;
use App\Service\PriceTimelineBuilder;
use PHPUnit\Framework\TestCase;
use Psr\Log\LoggerInterface;
use Symfony\Contracts\Cache\CacheInterface;
class ContingentControllerTest extends TestCase
{
public function testEnrichEntryIncludesPricingMetadata(): void
{
$controller = new ContingentController(
$controller = $this->createController();
$price = $this->createPrice();
$result = $this->enrichEntry($controller, '2026-07-06', 'available', [$price], ['2026-07-06' => true]);
self::assertSame('available', $result['status']);
self::assertSame(4, $result['includedPax']);
self::assertSame(3, $result['minNights']);
self::assertSame(123.45, $result['pricePerNight']);
self::assertSame('EUR', $result['currency']);
}
public function testEnrichEntryBlocksDayWithoutPrice(): void
{
$controller = $this->createController();
$price = $this->createPrice();
$result = $this->enrichEntry($controller, '2026-08-01', 'OK', [$price], ['2026-07-06' => true]);
self::assertSame('BLOCKED', $result['status']);
self::assertNull($result['pricePerNight']);
self::assertNull($result['includedPax']);
self::assertNull($result['minNights']);
}
private function createController(): ContingentController
{
return new ContingentController(
$this->createMock(ContingentsClient::class),
$this->createMock(AccommodationRepository::class),
$this->createMock(AccommodationPriceRepository::class),
$this->createMock(CacheInterface::class),
new PriceTimelineBuilder(),
new AccommodationPriceCoverage($this->createMock(AccommodationPriceRepository::class)),
$this->createMock(LoggerInterface::class),
);
}
private function createPrice(): AccommodationPrice
{
$price = new AccommodationPrice();
$price->setDateFrom(new \DateTimeImmutable('2026-07-01'));
$price->setDateTo(new \DateTimeImmutable('2026-07-31'));
@@ -33,13 +67,24 @@ class ContingentControllerTest extends TestCase
$price->setPriceAdditionalPerson(1500);
$price->setMinNights(3);
return $price;
}
/**
* @param AccommodationPrice[] $prices
* @param array<string, true> $covered
*
* @return array<string, mixed>
*/
private function enrichEntry(
ContingentController $controller,
string $date,
string $status,
array $prices,
array $covered,
): array {
$method = new \ReflectionMethod($controller, 'enrichEntry');
$result = $method->invoke($controller, '2026-07-06', 'available', [$price], 'EUR');
self::assertSame(4, $result['includedPax']);
self::assertSame(3, $result['minNights']);
self::assertSame(123.45, $result['pricePerNight']);
self::assertSame('EUR', $result['currency']);
return $method->invoke($controller, $date, $status, $prices, $covered, 'EUR');
}
}