fix: incorrect rules around family insurances
addresses #869dr80qj
This commit is contained in:
@@ -425,6 +425,148 @@ class InsuranceManagerTest extends TestCase
|
||||
$this->assertNotNull($result[1]);
|
||||
}
|
||||
|
||||
public function testBatchAssignFamilyInsuranceToApplicantOnly(): void
|
||||
{
|
||||
$booking = $this->createFamilyBooking('2024-08-01', '2024-08-08');
|
||||
|
||||
// Tier matched by total price (300 + 0 = 300, fits 250–400 tier)
|
||||
$lowTierInsurance = $this->createInsurance([
|
||||
'id' => '1',
|
||||
'package' => false,
|
||||
'subType' => 'FAM',
|
||||
'familyInsurance' => true,
|
||||
'travelPriceFrom' => 0.0,
|
||||
'travelPriceTo' => 249.99,
|
||||
]);
|
||||
$correctTierInsurance = $this->createInsurance([
|
||||
'id' => '2',
|
||||
'package' => false,
|
||||
'subType' => 'FAM',
|
||||
'familyInsurance' => true,
|
||||
'travelPriceFrom' => 250.0,
|
||||
'travelPriceTo' => 400.0,
|
||||
]);
|
||||
|
||||
$availableInsurances = [$lowTierInsurance, $correctTierInsurance];
|
||||
// Individual prices: applicant 300, child 0 → total 300
|
||||
$participantPrices = [0 => 300.0, 1 => 0.0];
|
||||
|
||||
$result = $this->service->batchAssignInsuranceToParticipants(
|
||||
$availableInsurances,
|
||||
$correctTierInsurance,
|
||||
$booking,
|
||||
$participantPrices
|
||||
);
|
||||
|
||||
$this->assertCount(2, $result);
|
||||
$this->assertSame($correctTierInsurance, $result[0], 'Applicant should get tier matching total price');
|
||||
$this->assertNull($result[1], 'Non-applicant participants must be cleared for family insurance');
|
||||
}
|
||||
|
||||
public function testFamilyInsuranceIneligibleForNonApplicant(): void
|
||||
{
|
||||
$booking = $this->createFamilyBooking('2024-08-01', '2024-08-08');
|
||||
|
||||
$nonApplicant = $this->createParticipant('2015-01-01'); // child
|
||||
$nonApplicant->index = 1;
|
||||
|
||||
$familyInsurance = $this->createInsurance(['familyInsurance' => true]);
|
||||
|
||||
$result = $this->service->getEligibleInsurances([$familyInsurance], $nonApplicant, $booking, 500.0);
|
||||
|
||||
$this->assertEmpty($result, 'Family insurance must not be eligible for non-applicant participants');
|
||||
}
|
||||
|
||||
public function testNonFamilyInsuranceEligibleForFamilyBooking(): void
|
||||
{
|
||||
$booking = $this->createFamilyBooking('2024-08-01', '2024-08-08');
|
||||
|
||||
$adult = $this->createParticipant('1990-06-15');
|
||||
$adult->index = 0;
|
||||
$child = $this->createParticipant('2015-01-01');
|
||||
$child->index = 1;
|
||||
|
||||
$nonFamilyInsurance = $this->createInsurance(['familyInsurance' => false]);
|
||||
|
||||
$adultResult = $this->service->getEligibleInsurances([$nonFamilyInsurance], $adult, $booking, 500.0);
|
||||
$childResult = $this->service->getEligibleInsurances([$nonFamilyInsurance], $child, $booking, 500.0);
|
||||
|
||||
$this->assertNotEmpty($adultResult, 'Non-family insurance must be available in family bookings for adults');
|
||||
$this->assertNotEmpty($childResult, 'Non-family insurance must be available in family bookings for children');
|
||||
}
|
||||
|
||||
public function testFamilyInsuranceIneligibleForNonFamilyBooking(): void
|
||||
{
|
||||
// Two adults, no children — not a family booking
|
||||
$booking = $this->createBooking('2024-08-01', '2024-08-08');
|
||||
$adult1 = $this->createParticipant('1990-06-15');
|
||||
$adult1->index = 0;
|
||||
$adult2 = $this->createParticipant('1985-03-10');
|
||||
$adult2->index = 1;
|
||||
$booking->participants = [$adult1, $adult2];
|
||||
|
||||
$familyInsurance = $this->createInsurance(['familyInsurance' => true]);
|
||||
|
||||
$result = $this->service->getEligibleInsurances([$familyInsurance], $adult1, $booking, 500.0);
|
||||
|
||||
$this->assertEmpty($result, 'Family insurance must not be eligible when booking is not a family booking');
|
||||
}
|
||||
|
||||
public function testGetEligibleInsurancesForParticipantUsesTotalPriceForFamilyInsurance(): void
|
||||
{
|
||||
$booking = $this->createFamilyBooking('2024-08-01', '2024-08-08');
|
||||
$applicant = $booking->participants[0];
|
||||
|
||||
// Only matches the total booking price (450), not the individual price (300)
|
||||
$familyInsurance = $this->createInsurance([
|
||||
'familyInsurance' => true,
|
||||
'travelPriceFrom' => 400.01,
|
||||
'travelPriceTo' => 600.0,
|
||||
]);
|
||||
|
||||
$nonFamilyInsurance = $this->createInsurance([
|
||||
'familyInsurance' => false,
|
||||
'travelPriceFrom' => 0.0,
|
||||
'travelPriceTo' => 350.0,
|
||||
]);
|
||||
|
||||
$result = $this->service->getEligibleInsurancesForParticipant(
|
||||
[$familyInsurance, $nonFamilyInsurance],
|
||||
$applicant,
|
||||
$booking,
|
||||
300.0,
|
||||
450.0
|
||||
);
|
||||
|
||||
$ids = array_map(fn (Insurance $insurance) => spl_object_id($insurance), $result);
|
||||
|
||||
$this->assertContains(spl_object_id($familyInsurance), $ids, 'Family insurance must be evaluated against the total booking price');
|
||||
$this->assertContains(spl_object_id($nonFamilyInsurance), $ids, 'Non-family insurance must be evaluated against the individual price');
|
||||
}
|
||||
|
||||
public function testGetEligibleInsurancesForParticipantSkipsFamilyPricingWhenNoneAvailable(): void
|
||||
{
|
||||
$booking = $this->createFamilyBooking('2024-08-01', '2024-08-08');
|
||||
$applicant = $booking->participants[0];
|
||||
|
||||
$nonFamilyInsurance = $this->createInsurance([
|
||||
'familyInsurance' => false,
|
||||
'travelPriceFrom' => 0.0,
|
||||
'travelPriceTo' => 350.0,
|
||||
]);
|
||||
|
||||
$result = $this->service->getEligibleInsurancesForParticipant(
|
||||
[$nonFamilyInsurance],
|
||||
$applicant,
|
||||
$booking,
|
||||
300.0,
|
||||
450.0
|
||||
);
|
||||
|
||||
$this->assertCount(1, $result);
|
||||
$this->assertSame($nonFamilyInsurance, $result[0]);
|
||||
}
|
||||
|
||||
private function createParticipant(string $dateOfBirth): ParticipantDto
|
||||
{
|
||||
$participant = new ParticipantDto();
|
||||
@@ -442,6 +584,20 @@ class InsuranceManagerTest extends TestCase
|
||||
return $booking;
|
||||
}
|
||||
|
||||
private function createFamilyBooking(string $travelDateFrom, string $travelDateTo): BookingDto
|
||||
{
|
||||
$booking = $this->createBooking($travelDateFrom, $travelDateTo);
|
||||
|
||||
$adult = $this->createParticipant('1990-06-15'); // 34 years old
|
||||
$adult->index = 0;
|
||||
$child = $this->createParticipant('2015-01-01'); // 9 years old
|
||||
$child->index = 1;
|
||||
|
||||
$booking->participants = [$adult, $child];
|
||||
|
||||
return $booking;
|
||||
}
|
||||
|
||||
private function createTravel(string $dateFrom, string $dateTo): Travel
|
||||
{
|
||||
$travel = new Travel();
|
||||
|
||||
Reference in New Issue
Block a user