feat: edit selected accommodation of bookings in draft

This commit is contained in:
Björn Fromme
2026-08-20 12:34:44 +02:00
parent c1f0cda479
commit 3db1850e4f
8 changed files with 554 additions and 5 deletions
@@ -11,6 +11,7 @@ use App\Entity\Groups\AccommodationBooking;
use App\Entity\Groups\AccommodationPrice;
use App\Enum\Groups\AccommodationBookingOrigin;
use App\Enum\Groups\AccommodationBookingStatus;
use App\Enum\Groups\AdditionalServiceType;
use App\Form\Model\AccommodationBookingDto;
use App\Model\AccommodationBookingQueryParams;
use App\Repository\Groups\AccommodationPriceRepository;
@@ -859,6 +860,76 @@ class AccommodationBookingServiceTest extends TestCase
self::assertSame(1, $booking->getPricingVersion());
}
public function testChangeAccommodationSwapsTheHouseAndDropsTheBookedServices(): void
{
$entityManager = $this->createMock(EntityManagerInterface::class);
$entityManager->expects(self::once())->method('flush');
$service = $this->createServiceWithAccommodation(entityManager: $entityManager);
$booking = $this->draftWithServices();
$newAccommodation = (new Accommodation())->setName('Berghaus')->setCalendarCode('BERG');
$service->changeAccommodation($booking, $newAccommodation);
self::assertSame($newAccommodation, $booking->getAccommodation());
// The services belong to the old house's catalog and would carry its prices along.
self::assertNull($booking->getBoardServiceLabel());
self::assertNull($booking->getBoardServicePrice());
self::assertNull($booking->getBoardServiceOriginalId());
self::assertSame([], $booking->getAdditionalServices());
self::assertNull($booking->getTotalPrice(), 'the frozen price belonged to the old house');
}
public function testChangeAccommodationNoOpsForANonDraft(): void
{
$entityManager = $this->createMock(EntityManagerInterface::class);
$entityManager->expects(self::never())->method('flush');
$service = $this->createServiceWithAccommodation(entityManager: $entityManager);
$booking = $this->draftWithServices();
$booking->setStatus(AccommodationBookingStatus::Open);
$oldAccommodation = $booking->getAccommodation();
$service->changeAccommodation($booking, (new Accommodation())->setName('Berghaus'));
self::assertSame($oldAccommodation, $booking->getAccommodation());
self::assertSame('Vollpension', $booking->getBoardServiceLabel());
self::assertCount(1, $booking->getAdditionalServices());
}
public function testChangeAccommodationNoOpsWhenTheHouseIsUnchanged(): void
{
$entityManager = $this->createMock(EntityManagerInterface::class);
$entityManager->expects(self::never())->method('flush');
$service = $this->createServiceWithAccommodation(entityManager: $entityManager);
$booking = $this->draftWithServices();
$accommodation = $booking->getAccommodation();
self::assertNotNull($accommodation);
$service->changeAccommodation($booking, $accommodation);
self::assertSame('Vollpension', $booking->getBoardServiceLabel());
self::assertCount(1, $booking->getAdditionalServices());
}
private function draftWithServices(): AccommodationBooking
{
$booking = new AccommodationBooking();
$booking->setStatus(AccommodationBookingStatus::Draft);
$booking->setAccommodation((new Accommodation())->setName('Seehaus')->setCalendarCode('SEE'));
$booking->setBoardServiceLabel('Vollpension');
$booking->setBoardServicePrice(4500);
$booking->setBoardServiceOriginalId(7);
$booking->addAdditionalServiceSnapshot('Bettwäsche', 1200, AdditionalServiceType::Flat, 12);
$booking->setPriceSnapshot(['total' => 12345], 12345, 'EUR', 1);
return $booking;
}
/**
* @param AccommodationPrice[] $prices
*/