fix: reconcile assigned family insurance rate on updated participant
This commit is contained in:
@@ -728,6 +728,54 @@ class ParticipantEditDtoTest extends TestCase
|
||||
$this->assertCount(1, $insuranceViolations);
|
||||
}
|
||||
|
||||
public function testDependentWithoutInsurancePassesWhenApplicantHasFamilyInsurance(): void
|
||||
{
|
||||
$applicant = $this->createAdultParticipant('[email protected]');
|
||||
$applicant->insurance = $this->createMockInsurance(familyInsurance: true);
|
||||
|
||||
$dependent = $this->createAdultParticipant('[email protected]');
|
||||
$dependent->insurance = null;
|
||||
|
||||
$bookingDto = $this->createBookingDtoWithParticipants([$applicant, $dependent]);
|
||||
|
||||
$wrapper = new ParticipantEditDto(
|
||||
participant: $bookingDto->participants[1],
|
||||
bookingContext: $bookingDto,
|
||||
);
|
||||
|
||||
$violations = $this->validator->validate($wrapper, null, ['strict_required']);
|
||||
$insuranceViolations = array_filter(
|
||||
iterator_to_array($violations),
|
||||
fn ($v) => 'participant.insurance' === $v->getPropertyPath()
|
||||
);
|
||||
|
||||
$this->assertCount(0, $insuranceViolations);
|
||||
}
|
||||
|
||||
public function testDependentWithoutInsuranceFailsWhenApplicantHasNonFamilyInsurance(): void
|
||||
{
|
||||
$applicant = $this->createAdultParticipant('[email protected]');
|
||||
$applicant->insurance = $this->createMockInsurance(familyInsurance: false);
|
||||
|
||||
$dependent = $this->createAdultParticipant('[email protected]');
|
||||
$dependent->insurance = null;
|
||||
|
||||
$bookingDto = $this->createBookingDtoWithParticipants([$applicant, $dependent]);
|
||||
|
||||
$wrapper = new ParticipantEditDto(
|
||||
participant: $bookingDto->participants[1],
|
||||
bookingContext: $bookingDto,
|
||||
);
|
||||
|
||||
$violations = $this->validator->validate($wrapper, null, ['strict_required']);
|
||||
$insuranceViolations = array_filter(
|
||||
iterator_to_array($violations),
|
||||
fn ($v) => 'participant.insurance' === $v->getPropertyPath()
|
||||
);
|
||||
|
||||
$this->assertCount(1, $insuranceViolations);
|
||||
}
|
||||
|
||||
private function createBookingDtoWithParticipants(array $participants): BookingDto
|
||||
{
|
||||
$travel = new Travel();
|
||||
@@ -821,12 +869,13 @@ class ParticipantEditDtoTest extends TestCase
|
||||
return $service;
|
||||
}
|
||||
|
||||
private function createMockInsurance(): Insurance
|
||||
private function createMockInsurance(bool $familyInsurance = false): Insurance
|
||||
{
|
||||
$insurance = new Insurance();
|
||||
$insurance->id = '1';
|
||||
$insurance->label = 'Test Insurance';
|
||||
$insurance->price = 10.0;
|
||||
$insurance->familyInsurance = $familyInsurance;
|
||||
|
||||
return $insurance;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user