fix: use correct amount of rooms to calculate rooms pricing
This commit is contained in:
@@ -5,6 +5,7 @@ declare(strict_types=1);
|
||||
namespace App\Tests\Service;
|
||||
|
||||
use App\BusProNet\Model\Room;
|
||||
use App\BusProNet\Model\Booking;
|
||||
use App\BusProNet\Model\Service;
|
||||
use App\BusProNet\Model\Travel;
|
||||
use App\Form\Model\BookingDto;
|
||||
@@ -71,14 +72,14 @@ class BookingPriceCalculatorServiceTest extends TestCase
|
||||
// Test the calculation
|
||||
$result = $this->service->calculateRoomPricing($bookingDto);
|
||||
|
||||
// Expected: 2 rooms × 2 participants/room × €100 = €400 total
|
||||
// Expected: 2 rooms × €100 = €200 total
|
||||
$this->assertCount(1, $result);
|
||||
$this->assertEquals(1, $result[0]['roomId']);
|
||||
$this->assertEquals('Double Room', $result[0]['label']);
|
||||
$this->assertEquals(2, $result[0]['quantity']); // 2 rooms
|
||||
$this->assertEquals(4, $result[0]['participantCount']); // 4 participants total
|
||||
$this->assertEquals(100.0, $result[0]['unitPrice']); // €100 per participant
|
||||
$this->assertEquals(400.0, $result[0]['totalPrice']); // €400 total
|
||||
$this->assertEquals(2, $result[0]['participantCount']); // billed units follow selected room count
|
||||
$this->assertEquals(100.0, $result[0]['unitPrice']); // €100 per room
|
||||
$this->assertEquals(200.0, $result[0]['totalPrice']); // €200 total
|
||||
}
|
||||
|
||||
public function testCalculateRoomPricingWithSingleRoomSelection(): void
|
||||
@@ -103,14 +104,14 @@ class BookingPriceCalculatorServiceTest extends TestCase
|
||||
// Test the calculation
|
||||
$result = $this->service->calculateRoomPricing($bookingDto);
|
||||
|
||||
// Expected: 1 room × 3 participants/room × €150 = €450 total
|
||||
// Expected: 1 room × €150 = €150 total
|
||||
$this->assertCount(1, $result);
|
||||
$this->assertEquals(2, $result[0]['roomId']);
|
||||
$this->assertEquals('Triple Room', $result[0]['label']);
|
||||
$this->assertEquals(1, $result[0]['quantity']); // 1 room
|
||||
$this->assertEquals(3, $result[0]['participantCount']); // 3 participants total
|
||||
$this->assertEquals(150.0, $result[0]['unitPrice']); // €150 per participant
|
||||
$this->assertEquals(450.0, $result[0]['totalPrice']); // €450 total
|
||||
$this->assertEquals(1, $result[0]['participantCount']); // billed units follow selected room count
|
||||
$this->assertEquals(150.0, $result[0]['unitPrice']); // €150 per room
|
||||
$this->assertEquals(150.0, $result[0]['totalPrice']); // €150 total
|
||||
}
|
||||
|
||||
public function testCalculateRoomPricingWithMultipleRoomTypes(): void
|
||||
@@ -146,8 +147,8 @@ class BookingPriceCalculatorServiceTest extends TestCase
|
||||
$result = $this->service->calculateRoomPricing($bookingDto);
|
||||
|
||||
// Expected:
|
||||
// - Single: 1 room × 1 participant × €80 = €80
|
||||
// - Double: 2 rooms × 2 participants × €120 = €480
|
||||
// - Single: 1 room × €80 = €80
|
||||
// - Double: 2 rooms × €120 = €240
|
||||
$this->assertCount(2, $result);
|
||||
|
||||
// Single room result
|
||||
@@ -162,9 +163,9 @@ class BookingPriceCalculatorServiceTest extends TestCase
|
||||
$doubleResult = $result[1];
|
||||
$this->assertEquals(2, $doubleResult['roomId']);
|
||||
$this->assertEquals(2, $doubleResult['quantity']);
|
||||
$this->assertEquals(4, $doubleResult['participantCount']);
|
||||
$this->assertEquals(2, $doubleResult['participantCount']);
|
||||
$this->assertEquals(120.0, $doubleResult['unitPrice']);
|
||||
$this->assertEquals(480.0, $doubleResult['totalPrice']);
|
||||
$this->assertEquals(240.0, $doubleResult['totalPrice']);
|
||||
}
|
||||
|
||||
public function testCalculateRoomPricingSkipsRoomsWithNullPrice(): void
|
||||
@@ -215,6 +216,36 @@ class BookingPriceCalculatorServiceTest extends TestCase
|
||||
$this->assertEmpty($result);
|
||||
}
|
||||
|
||||
public function testCalculateRoomPricingInEditModeUsesStoredIndividualPrices(): void
|
||||
{
|
||||
$travel = new Travel();
|
||||
$bookingDto = new BookingDto($travel, 2);
|
||||
|
||||
$participantA = new ParticipantDto();
|
||||
$participantA->assignedRoomId = 10;
|
||||
$participantB = new ParticipantDto();
|
||||
$participantB->assignedRoomId = 10;
|
||||
$bookingDto->participants = [$participantA, $participantB];
|
||||
|
||||
$booking = new Booking();
|
||||
$room = new Room();
|
||||
$room->id = 10;
|
||||
$room->label = 'Stored Room';
|
||||
$room->mapping = [0, 1];
|
||||
$room->individualPrice = [0 => 200.0, 1 => 220.0];
|
||||
$room->totalCount = 1;
|
||||
$booking->rooms = [$room];
|
||||
$bookingDto->booking = $booking;
|
||||
|
||||
$result = $this->service->calculateRoomPricing($bookingDto);
|
||||
|
||||
$this->assertCount(1, $result);
|
||||
$this->assertEquals(10, $result[0]['roomId']);
|
||||
$this->assertEquals(2, $result[0]['participantCount']);
|
||||
$this->assertEquals(210.0, $result[0]['unitPrice']);
|
||||
$this->assertEquals(420.0, $result[0]['totalPrice']);
|
||||
}
|
||||
|
||||
public function testCalculateIndividualParticipantPriceWithRoomAndServices(): void
|
||||
{
|
||||
// Create test room
|
||||
|
||||
Reference in New Issue
Block a user