Files
myep/tests/Service/BookingPriceMismatchAnalyzerTest.php
T

79 lines
2.9 KiB
PHP

<?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\BookingPricingAssembler;
use App\Service\BookingPriceMismatchAnalyzer;
use PHPUnit\Framework\TestCase;
class BookingPriceMismatchAnalyzerTest extends TestCase
{
public function testBuildDiagnosticsProvidesDeltaBreakdown(): void
{
$pricingAssembler = $this->createMock(BookingPricingAssembler::class);
$pricingAssembler->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 BookingPriceMismatchAnalyzer($pricingAssembler);
$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']);
}
}