fix: incorrect rules around family insurances
addresses #869dr80qj
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Form\Service;
|
||||
|
||||
use App\BusProNet\Model\Insurance;
|
||||
use App\BusProNet\Model\Travel;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Model\ParticipantDto;
|
||||
use App\Form\Service\CreateFieldStateProvider;
|
||||
use App\Service\ParticipantEligibilityChecker;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
/**
|
||||
* Integration-level coverage for cross-participant field-state re-evaluation: proves the
|
||||
* dependent's 'insurance' field state actually flips when the applicant's insurance
|
||||
* selection changes, wiring FamilyInsuranceActiveCondition through the real
|
||||
* CreateFieldStateProvider composition rather than testing the condition in isolation.
|
||||
*/
|
||||
class CreateFieldStateProviderTest extends TestCase
|
||||
{
|
||||
private CreateFieldStateProvider $provider;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->provider = new CreateFieldStateProvider(new ParticipantEligibilityChecker());
|
||||
}
|
||||
|
||||
public function testDependentInsuranceFieldHidesWhenApplicantSelectsFamilyInsuranceThenReappearsAfterSwitch(): void
|
||||
{
|
||||
$travel = new Travel();
|
||||
$travel->dateFrom = new \DateTimeImmutable('+30 days');
|
||||
$travel->dateTo = new \DateTimeImmutable('+37 days');
|
||||
|
||||
$applicant = new ParticipantDto();
|
||||
$applicant->index = 0;
|
||||
// Baby age (0-2 years at travel date) is always eligible regardless of skipass availability
|
||||
$applicant->dateOfBirth = $travel->dateFrom->modify('-1 year');
|
||||
|
||||
$dependent = new ParticipantDto();
|
||||
$dependent->index = 1;
|
||||
$dependent->dateOfBirth = $travel->dateFrom->modify('-1 year');
|
||||
|
||||
$bookingDto = new BookingDto($travel, 1);
|
||||
$bookingDto->participants = [$applicant, $dependent];
|
||||
|
||||
$this->assertTrue(
|
||||
$this->provider->shouldIncludeField('insurance', $bookingDto, 1),
|
||||
'Dependent should see their own insurance field before the applicant selects family insurance'
|
||||
);
|
||||
|
||||
$familyInsurance = new Insurance();
|
||||
$familyInsurance->familyInsurance = true;
|
||||
$applicant->insurance = $familyInsurance;
|
||||
|
||||
$this->assertFalse(
|
||||
$this->provider->shouldIncludeField('insurance', $bookingDto, 1),
|
||||
'Dependent insurance field must be hidden once the applicant selects family insurance'
|
||||
);
|
||||
|
||||
$nonFamilyInsurance = new Insurance();
|
||||
$nonFamilyInsurance->familyInsurance = false;
|
||||
$applicant->insurance = $nonFamilyInsurance;
|
||||
|
||||
$this->assertTrue(
|
||||
$this->provider->shouldIncludeField('insurance', $bookingDto, 1),
|
||||
'Dependent insurance field must reappear once the applicant switches away from family insurance'
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user