feat: cap rooms sharing a contingent per booking
This commit is contained in:
1 parent
5942ecf340
commit
3d94505e8d
18 files changed
+671
-19
No files matched your search
@@ -8,15 +8,81 @@ use App\BusProNet\Model\Room;
|
||||
use App\BusProNet\Model\Travel;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Model\RoomSelectionDto;
|
||||
use App\Model\RoomContingentPool;
|
||||
use App\Service\RoomContingentPoolResolver;
|
||||
use App\Validator\Constraints\RoomSelection;
|
||||
use App\Validator\Constraints\RoomSelectionValidator;
|
||||
use Symfony\Component\Validator\Test\ConstraintValidatorTestCase;
|
||||
|
||||
class RoomSelectionValidatorTest extends ConstraintValidatorTestCase
|
||||
{
|
||||
/** @var list<RoomContingentPool> */
|
||||
private array $sharedPools = [];
|
||||
|
||||
protected function createValidator(): RoomSelectionValidator
|
||||
{
|
||||
return new RoomSelectionValidator();
|
||||
$poolResolver = $this->createStub(RoomContingentPoolResolver::class);
|
||||
$poolResolver->method('findSharedPools')->willReturnCallback(fn (): array => $this->sharedPools);
|
||||
|
||||
return new RoomSelectionValidator($poolResolver);
|
||||
}
|
||||
|
||||
public function testRoomsSharingAContingentMayNotTogetherExceedIt(): void
|
||||
{
|
||||
$bookingDto = $this->createBookingDto([
|
||||
['id' => 2366, 'code' => '8erSudel', 'quantity' => 1],
|
||||
['id' => 2367, 'code' => '8erSudel', 'quantity' => 1],
|
||||
]);
|
||||
$this->shareContingent($bookingDto, [2366, 2367], available: 1);
|
||||
|
||||
$this->validator->validate($bookingDto, new RoomSelection());
|
||||
|
||||
$this->buildViolation('Diese Zimmer teilen sich ein Kontingent, von dem nur noch {{ available }} verfügbar ist: {{ rooms }}. Bitte reduziere deine Auswahl.')
|
||||
->setParameter('{{ available }}', '1')
|
||||
->setParameter('{{ rooms }}', 'Zimmer 2366, Zimmer 2367')
|
||||
->assertRaised();
|
||||
}
|
||||
|
||||
public function testRoomsSharingAContingentPassWhileTheyFit(): void
|
||||
{
|
||||
$bookingDto = $this->createBookingDto([
|
||||
['id' => 2366, 'code' => '8erSudel', 'quantity' => 1],
|
||||
['id' => 2367, 'code' => '8erSudel', 'quantity' => 1],
|
||||
]);
|
||||
$this->shareContingent($bookingDto, [2366, 2367], available: 2);
|
||||
|
||||
$this->validator->validate($bookingDto, new RoomSelection());
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
public function testAnUnselectedRoomOfASharedContingentDoesNotCount(): void
|
||||
{
|
||||
$bookingDto = $this->createBookingDto([
|
||||
['id' => 2366, 'code' => '8erSudel', 'quantity' => 1],
|
||||
['id' => 2367, 'code' => '8erSudel', 'quantity' => 0],
|
||||
]);
|
||||
$this->shareContingent($bookingDto, [2366, 2367], available: 1);
|
||||
|
||||
$this->validator->validate($bookingDto, new RoomSelection());
|
||||
|
||||
$this->assertNoViolation();
|
||||
}
|
||||
|
||||
/**
|
||||
* @param list<int> $roomIds
|
||||
*/
|
||||
private function shareContingent(BookingDto $bookingDto, array $roomIds, int $available): void
|
||||
{
|
||||
$rooms = [];
|
||||
foreach ($bookingDto->travel->rooms as $room) {
|
||||
if (in_array($room->id, $roomIds, true)) {
|
||||
$room->available = $available;
|
||||
$rooms[$room->id] = $room;
|
||||
}
|
||||
}
|
||||
|
||||
$this->sharedPools = [new RoomContingentPool($rooms)];
|
||||
}
|
||||
|
||||
public function testNoRoomSelectedFailsValidation(): void
|
||||
@@ -141,6 +207,7 @@ class RoomSelectionValidatorTest extends ConstraintValidatorTestCase
|
||||
$room = new Room();
|
||||
$room->id = $data['id'];
|
||||
$room->code = $data['code'];
|
||||
$room->label = 'Zimmer '.$data['id'];
|
||||
$room->available = 10;
|
||||
$room->status = 'Frei';
|
||||
$travel->rooms[] = $room;
|
||||
|
||||
Reference in new issue
Block a user