feat: duplicate an accommodation booking into a new draft

addresses #869f6z44f
This commit is contained in:
fromme committed 2026-09-28 08:55:01 +02:00
1 parent 2aa98b81fe
commit 29f295abf6
9 files changed
+470

No files matched your search

@@ -1121,6 +1121,57 @@ class AccommodationBookingServiceTest extends TestCase
self::assertSame(['total' => 1000], $ctx->priceBreakdown);
}
public function testDuplicatePersistsACopyAndLeavesTheOriginalAlone(): void
{
$booking = (new AccommodationBooking())
->setGroupName('Skiclub Nord')
->setPaxCount(30);
$booking->setStatus(AccommodationBookingStatus::Confirmed);
$persisted = null;
$entityManager = $this->createMock(EntityManagerInterface::class);
$entityManager->expects(self::once())
->method('persist')
->willReturnCallback(function (object $entity) use (&$persisted): void { $persisted = $entity; });
$entityManager->expects(self::once())->method('flush');
$service = $this->createServiceWithAccommodation(entityManager: $entityManager);
$copy = $service->duplicate($booking);
self::assertSame($persisted, $copy);
self::assertNotSame($booking, $copy);
self::assertSame(30, $copy->getPaxCount());
self::assertSame(AccommodationBookingStatus::Draft, $copy->getStatus());
self::assertSame(AccommodationBookingStatus::Confirmed, $booking->getStatus());
self::assertSame('Skiclub Nord', $booking->getGroupName());
}
public function testDuplicateMarksTheCopyByName(): void
{
$booking = (new AccommodationBooking())->setGroupName('Skiclub Nord');
$copy = $this->createServiceWithAccommodation()->duplicate($booking);
self::assertSame('Skiclub Nord (Kopie)', $copy->getGroupName());
}
public function testDuplicateNeverRecomputesThePrice(): void
{
// The copy has to show what the original was quoted at, not today's catalog prices.
$booking = new AccommodationBooking();
$booking->setPriceSnapshot(['total' => 500000], 480000, 'CHF', 1);
$breakdownCalculator = $this->createMock(AccommodationBookingBreakdownCalculator::class);
$breakdownCalculator->expects(self::never())->method('computeCurrent');
$copy = $this->createServiceWithAccommodation(breakdownCalculator: $breakdownCalculator)->duplicate($booking);
self::assertSame(['total' => 500000], $copy->getPriceBreakdown());
self::assertSame(480000, $copy->getTotalPrice());
self::assertSame('CHF', $copy->getPricingCurrency());
}
private function createBookingWithContactData(): AccommodationBooking
{
return (new AccommodationBooking())