fix: properly handle 'veg' services in booking edit flow

This commit is contained in:
Björn Fromme
2026-04-29 11:59:39 +02:00
parent 287c299c41
commit c0c8ad515c
9 changed files with 89 additions and 4 deletions
@@ -109,6 +109,49 @@ class BookingDataProcessorTest extends TestCase
$this->assertEquals('1', $service['@zuordnung']);
}
public function testVegServiceIsIncludedInUpdatePayload(): void
{
$formData = $this->createCompleteFormData();
$vegService = $this->createMockService(194672);
$formData->travel->additionalServices[194672] = $vegService;
$formData->participants[0]->veg = $vegService;
$result = $this->processor->createUpdateRequestPayload($formData);
$this->assertNotEmpty($result['zusatzleistungen']['zusatzleistung']);
$vegPayload = null;
foreach ($result['zusatzleistungen']['zusatzleistung'] as $service) {
if (194672 === $service['@idleistung']) {
$vegPayload = $service;
break;
}
}
$this->assertNotNull($vegPayload);
$this->assertSame(1, $vegPayload['@anzahl']);
$this->assertSame('1', $vegPayload['@zuordnung']);
}
public function testVegSelectionIsRestoredWhenHydratingBookingDto(): void
{
$booking = $this->createMockBooking();
$travel = $this->createMockTravel();
$vegService = $this->createMockService(194672);
$vegService->subType = 'VEG';
$vegService->mapping = [0];
$booking->additionalServices[194672] = $vegService;
$travel->additionalServices[194672] = $vegService;
$dto = $this->processor->createBookingDtoFromBooking($booking, $travel);
$this->assertNotNull($dto->participants[0]->veg);
$this->assertSame(194672, $dto->participants[0]->veg?->id);
}
public function testTransportationServicesProcessing(): void
{
$formData = $this->createFormDataWithTransportation();
@@ -47,17 +47,23 @@ class BookingEditDraftManagerMutabilityTest extends TestCase
public function testDraftSkipsAdditionalServicesWhenImmutable(): void
{
$originalService = $this->createService(10, 'Original');
$originalVeg = $this->createService(11, 'Original Veg');
$participant = new ParticipantDto();
$participant->additionalServices = [$originalService];
$participant->courses = [];
$participant->board = [];
$participant->veg = $originalVeg;
$participant->rentals = [];
$participant->skiPass = null;
$participant->rentalInsurance = null;
$travel = $this->createTravel(
additionalServicesMutable: false,
additionalServices: [10 => $originalService, 99 => $this->createService(99, 'Draft Added')],
additionalServices: [
10 => $originalService,
11 => $originalVeg,
99 => $this->createService(99, 'Draft Added'),
],
);
$dto = $this->createBookingDto($travel, [$participant]);
@@ -69,6 +75,7 @@ class BookingEditDraftManagerMutabilityTest extends TestCase
'additionalServices' => [99],
'courses' => [99],
'board' => [99],
'veg' => 99,
'rentals' => [99],
'skiPass' => 99,
'rentalInsurance' => 99,
@@ -83,6 +90,7 @@ class BookingEditDraftManagerMutabilityTest extends TestCase
$this->assertSame([$originalService], $participant->additionalServices);
$this->assertSame([], $participant->courses);
$this->assertSame([], $participant->board);
$this->assertSame($originalVeg, $participant->veg);
$this->assertSame([], $participant->rentals);
$this->assertNull($participant->skiPass);
$this->assertNull($participant->rentalInsurance);
@@ -91,16 +99,18 @@ class BookingEditDraftManagerMutabilityTest extends TestCase
public function testDraftAppliesAdditionalServicesWhenMutable(): void
{
$originalService = $this->createService(10, 'Original');
$originalVeg = $this->createService(11, 'Original Veg');
$draftService = $this->createService(99, 'Draft Added');
$participant = new ParticipantDto();
$participant->additionalServices = [$originalService];
$participant->courses = [];
$participant->veg = $originalVeg;
$participant->skiPass = null;
$travel = $this->createTravel(
additionalServicesMutable: true,
additionalServices: [10 => $originalService, 99 => $draftService],
additionalServices: [10 => $originalService, 11 => $originalVeg, 99 => $draftService],
);
$dto = $this->createBookingDto($travel, [$participant]);
@@ -111,6 +121,7 @@ class BookingEditDraftManagerMutabilityTest extends TestCase
'services' => [
'additionalServices' => [99],
'courses' => [99],
'veg' => 99,
'skiPass' => 99,
],
],
@@ -124,6 +135,7 @@ class BookingEditDraftManagerMutabilityTest extends TestCase
$this->assertSame(99, $participant->additionalServices[0]->id);
$this->assertCount(1, $participant->courses);
$this->assertSame(99, $participant->courses[0]->id);
$this->assertSame($draftService, $participant->veg);
$this->assertInstanceOf(Service::class, $participant->skiPass);
$skiPass = $participant->skiPass;
$this->assertNotNull($skiPass);
@@ -32,6 +32,7 @@ class BookingEditSubmitGuardTest extends TestCase
$workingParticipant = new ParticipantDto();
$workingParticipant->index = 0;
$workingParticipant->additionalServices = [$this->createService(99)];
$workingParticipant->veg = $this->createService(88);
$workingParticipant->transportationOutbound = $this->createService(88);
$workingParticipant->pickup = $this->createPickup(77);
@@ -41,6 +42,7 @@ class BookingEditSubmitGuardTest extends TestCase
$baselineParticipant = new ParticipantDto();
$baselineParticipant->index = 0;
$baselineParticipant->additionalServices = [$this->createService(10)];
$baselineParticipant->veg = $this->createService(11);
$baselineParticipant->transportationOutbound = $this->createService(20);
$baselineParticipant->pickup = $this->createPickup(30);
@@ -58,6 +60,7 @@ class BookingEditSubmitGuardTest extends TestCase
$this->assertTrue($changed);
$this->assertSame([10], array_map(static fn (Service $s) => $s->id, $workingParticipant->additionalServices));
$this->assertSame(11, $workingParticipant->veg?->id);
$this->assertSame(20, $workingParticipant->transportationOutbound?->id);
$this->assertSame(30, $workingParticipant->pickup?->id);
}