feat: extended price mismatch diagnostics in logs

This commit is contained in:
Björn Fromme
2026-03-18 15:24:52 +01:00
parent 02ff28acdd
commit ca7d0b6965
3 changed files with 244 additions and 0 deletions
@@ -0,0 +1,78 @@
<?php
declare(strict_types=1);
namespace App\Tests\Service;
use App\BusProNet\Model\BookingResponse;
use App\BusProNet\Model\Insurance;
use App\BusProNet\Model\PriceItem;
use App\BusProNet\Model\Travel;
use App\Form\Model\BookingDto;
use App\Form\Model\ParticipantDto;
use App\Form\Model\RoomSelectionDto;
use App\Service\BookingPriceCalculatorService;
use App\Service\BookingPriceMismatchDiagnosticsService;
use PHPUnit\Framework\TestCase;
class BookingPriceMismatchDiagnosticsServiceTest extends TestCase
{
public function testBuildDiagnosticsProvidesDeltaBreakdown(): void
{
$priceCalculator = $this->createMock(BookingPriceCalculatorService::class);
$priceCalculator->method('getPricingBreakdown')->willReturn([
'rooms' => [
['roomId' => 74, 'totalPrice' => 444.0],
],
'services' => [
[
'groupName' => 'Reiseversicherungen',
'groupTotal' => 69.5,
'services' => [
['subType' => 'RRV', 'totalPrice' => 115.0],
],
],
],
'grandTotal' => 513.5,
]);
$service = new BookingPriceMismatchDiagnosticsService($priceCalculator);
$bookingDto = new BookingDto(new Travel(), 197136);
$roomSelection = new RoomSelectionDto();
$roomSelection->id = 74;
$roomSelection->quantity = 1;
$roomSelection->price = 444.0;
$roomSelection->capacity = 1;
$bookingDto->roomSelections = [$roomSelection];
$participant = new ParticipantDto();
$participant->index = 0;
$participant->assignedRoomId = 74;
$participant->bulkInsuranceBooking = false;
$insurance = new Insurance();
$insurance->id = '178926';
$insurance->price = 115.0;
$participant->insurance = $insurance;
$bookingDto->participants = [$participant];
$response = new BookingResponse(
status: 'möglich',
priceItems: [
new PriceItem(1, 'UNT', 'ZIM', 'Room', null, null, 1, '1', 329.0, 329.0, null),
new PriceItem(2, 'SON', 'SPA', 'Skipass', null, null, 1, '1', 49.9, 49.9, '186099'),
new PriceItem(3, 'SON', 'SON', 'Tax', null, null, 1, '1', 9.6, 9.6, '186098'),
new PriceItem(4, 'SON', 'SON', 'Card', null, null, 1, '1', 5.0, 5.0, '186097'),
new PriceItem(5, 'BEF', 'BUS', 'Bus', null, null, 1, '1', 5.0, 5.0, '186092'),
],
totalPrice: 398.5,
);
$diagnostics = $service->buildDiagnostics($bookingDto, $response);
$this->assertSame(115.0, $diagnostics['deltaBreakdown']['deltaTotal']);
$this->assertSame(115.0, $diagnostics['deltaBreakdown']['deltaRoom']);
$this->assertSame(0.0, $diagnostics['deltaBreakdown']['deltaService']);
$this->assertSame(115.0, $diagnostics['deltaBreakdown']['deltaInsurance']);
}
}