fix: always adopt outbound pickup price for inbound when set

This commit is contained in:
fromme committed 2026-09-28 16:33:36 +02:00
1 parent 29f295abf6
commit 0c6126010f
5 files changed
+203 -20

No files matched your search

@@ -5,6 +5,8 @@ declare(strict_types=1);
namespace App\Tests\Service;
use App\BusProNet\Model\Insurance;
use App\BusProNet\Model\Pickup;
use App\BusProNet\Model\Service;
use App\BusProNet\Model\Travel;
use App\Form\Model\BookingDto;
use App\Form\Model\ParticipantDto;
@@ -311,6 +313,94 @@ class BookingPricingAssemblerTest extends TestCase
return $participant;
}
public function testBoardingSurchargeIsChargedForBothBusLegs(): void
{
// Travel 12939: two participants boarding and returning at point 18 (€17,90),
// which BusPro bills as two TRA positions of €35,80.
$bookingDto = $this->createBusBookingDto('BUS', 'BUS');
$group = $this->findServiceGroup($this->assembler->calculateServicePricing($bookingDto), 'Beförderung');
$this->assertNotNull($group, 'Transportation group should exist');
$this->assertEqualsWithDelta(71.6, $group['groupTotal'], 0.001, 'Both legs are charged at €17,90 per participant');
}
public function testBoardingSurchargeSkipsTheReturnLegWhenItIsNotByBus(): void
{
$bookingDto = $this->createBusBookingDto('BUS', 'PKW');
$group = $this->findServiceGroup($this->assembler->calculateServicePricing($bookingDto), 'Beförderung');
$this->assertEqualsWithDelta(35.8, $group['groupTotal'], 0.001, 'Only the outbound leg is charged');
}
public function testBoardingSurchargeSkipsTheOutboundLegWhenItIsNotByBus(): void
{
$bookingDto = $this->createBusBookingDto('PKW', 'BUS');
$group = $this->findServiceGroup($this->assembler->calculateServicePricing($bookingDto), 'Beförderung');
$this->assertEqualsWithDelta(35.8, $group['groupTotal'], 0.001, 'Only the return leg is charged');
}
public function testBoardingSurchargeTotalMatchesTheSumOfTheParticipantTotals(): void
{
$bookingDto = $this->createBusBookingDto('BUS', 'BUS');
$group = $this->findServiceGroup($this->assembler->calculateServicePricing($bookingDto), 'Beförderung');
$participantCalculator = new ParticipantPricingCalculator(new RoomPricingCalculator());
$participantTotal = array_sum($participantCalculator->calculateAllParticipantIndividualPrices($bookingDto));
$this->assertEqualsWithDelta($group['groupTotal'], $participantTotal, 0.001, 'Summary and per-participant totals must agree');
}
private function createBusBookingDto(string $outboundSubType, string $inboundSubType): BookingDto
{
$travel = new Travel();
$travel->insurances = [];
$bookingDto = new BookingDto($travel, 2);
$bookingDto->participants = [];
foreach ([0, 1] as $index) {
$participant = new ParticipantDto();
$participant->index = $index;
$participant->transportationOutbound = $this->createTransportationService(203222, 'Bus-Hinfahrt', $outboundSubType);
$participant->transportationInbound = $this->createTransportationService(203235, 'Bus-Rückfahrt', $inboundSubType);
$participant->pickup = $this->createBoardingPoint(18, 17.9);
$participant->dropOff = $this->createBoardingPoint(18, 17.9);
$bookingDto->participants[] = $participant;
}
return $bookingDto;
}
private function createTransportationService(int $id, string $label, string $subType): Service
{
$service = new Service();
$service->id = $id;
$service->label = $label;
$service->subType = $subType;
$service->price = 0.0;
return $service;
}
private function createBoardingPoint(int $id, float $price): Pickup
{
$pickup = new Pickup();
$pickup->id = $id;
$pickup->city = 'Teststadt';
$pickup->price = $price;
$pickup->priceOutbound = $price;
$pickup->priceInbound = $price;
return $pickup;
}
private function createAssembler(ParticipantEligibilityChecker $eligibilityChecker): BookingPricingAssembler
{
$roomPricingCalculator = new RoomPricingCalculator();