wip: insurance booking
This commit is contained in:
@@ -7,6 +7,7 @@ namespace App\Tests\Service;
|
||||
use App\BusProNet\Model\Insurance;
|
||||
use App\Form\Model\BookingCreateDto;
|
||||
use App\Form\Model\ParticipantDto;
|
||||
use App\Service\BookingPriceCalculatorService;
|
||||
use App\Service\InsuranceMatchingService;
|
||||
use Carbon\Carbon;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
@@ -14,10 +15,17 @@ use PHPUnit\Framework\TestCase;
|
||||
class InsuranceMatchingServiceTest extends TestCase
|
||||
{
|
||||
private InsuranceMatchingService $service;
|
||||
private BookingPriceCalculatorService $priceCalculator;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->service = new InsuranceMatchingService();
|
||||
// Mock the price calculator service
|
||||
$this->priceCalculator = $this->createMock(BookingPriceCalculatorService::class);
|
||||
$this->priceCalculator
|
||||
->method('calculateIndividualParticipantPriceExcludingInsurance')
|
||||
->willReturn(500.0); // Default test price
|
||||
|
||||
$this->service = new InsuranceMatchingService($this->priceCalculator);
|
||||
|
||||
// Set a fixed test date for consistent test results
|
||||
Carbon::setTestNow('2024-06-01 12:00:00');
|
||||
@@ -164,6 +172,7 @@ class InsuranceMatchingServiceTest extends TestCase
|
||||
public function testGetEligibleInsurancesHandlesParticipantWithoutBirthDate(): void
|
||||
{
|
||||
$participant = new ParticipantDto();
|
||||
$participant->index = 0; // Set participant index for price calculations
|
||||
$participant->dateOfBirth = null;
|
||||
$booking = $this->createBooking('2024-08-01', '2024-08-08');
|
||||
|
||||
@@ -239,6 +248,7 @@ class InsuranceMatchingServiceTest extends TestCase
|
||||
private function createParticipant(string $dateOfBirth): ParticipantDto
|
||||
{
|
||||
$participant = new ParticipantDto();
|
||||
$participant->index = 0; // Set participant index for price calculations
|
||||
$participant->dateOfBirth = new \DateTimeImmutable($dateOfBirth);
|
||||
|
||||
return $participant;
|
||||
|
||||
@@ -1,257 +0,0 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Service;
|
||||
|
||||
use App\BusProNet\Model\Insurance;
|
||||
use App\Service\InsuranceTypeResolver;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class InsuranceTypeResolverTest extends TestCase
|
||||
{
|
||||
private InsuranceTypeResolver $resolver;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->resolver = new InsuranceTypeResolver();
|
||||
}
|
||||
|
||||
public function testResolveTypeForIndividualTravelCancellationInsurance(): void
|
||||
{
|
||||
$insurance = new Insurance();
|
||||
$insurance->package = false;
|
||||
$insurance->subType = 'RRV';
|
||||
$insurance->familyInsurance = false;
|
||||
|
||||
$result = $this->resolver->resolveType($insurance);
|
||||
|
||||
$this->assertEquals(InsuranceTypeResolver::TRAVEL_CANCELLATION, $result);
|
||||
}
|
||||
|
||||
public function testResolveTypeForIndividualFamilyTravelCancellationInsurance(): void
|
||||
{
|
||||
$insurance = new Insurance();
|
||||
$insurance->package = false;
|
||||
$insurance->subType = 'RRV';
|
||||
$insurance->familyInsurance = true;
|
||||
|
||||
$result = $this->resolver->resolveType($insurance);
|
||||
|
||||
$this->assertEquals(InsuranceTypeResolver::TRAVEL_CANCELLATION_FAMILY, $result);
|
||||
}
|
||||
|
||||
public function testResolveTypeForIndividualTravelProtectionInsurance(): void
|
||||
{
|
||||
$insurance = new Insurance();
|
||||
$insurance->package = false;
|
||||
$insurance->subType = 'PAK';
|
||||
$insurance->familyInsurance = false;
|
||||
|
||||
$result = $this->resolver->resolveType($insurance);
|
||||
|
||||
$this->assertEquals(InsuranceTypeResolver::TRAVEL_PROTECTION, $result);
|
||||
}
|
||||
|
||||
public function testResolveTypeForIndividualFamilyTravelProtectionInsurance(): void
|
||||
{
|
||||
$insurance = new Insurance();
|
||||
$insurance->package = false;
|
||||
$insurance->subType = 'PAK';
|
||||
$insurance->familyInsurance = true;
|
||||
|
||||
$result = $this->resolver->resolveType($insurance);
|
||||
|
||||
$this->assertEquals(InsuranceTypeResolver::TRAVEL_PROTECTION_FAMILY, $result);
|
||||
}
|
||||
|
||||
public function testResolveTypeForIndividualDeductibleInsurance(): void
|
||||
{
|
||||
$insurance = new Insurance();
|
||||
$insurance->package = false;
|
||||
$insurance->subType = 'OHN';
|
||||
$insurance->familyInsurance = false;
|
||||
|
||||
$result = $this->resolver->resolveType($insurance);
|
||||
|
||||
$this->assertEquals(InsuranceTypeResolver::DEDUCTIBLE, $result);
|
||||
}
|
||||
|
||||
public function testResolveTypeForIndividualUnknownSubtype(): void
|
||||
{
|
||||
$insurance = new Insurance();
|
||||
$insurance->package = false;
|
||||
$insurance->subType = 'UNKNOWN';
|
||||
$insurance->familyInsurance = false;
|
||||
|
||||
$result = $this->resolver->resolveType($insurance);
|
||||
|
||||
$this->assertNull($result);
|
||||
}
|
||||
|
||||
public function testResolveTypeForIndividualNullSubtype(): void
|
||||
{
|
||||
$insurance = new Insurance();
|
||||
$insurance->package = false;
|
||||
$insurance->subType = null;
|
||||
$insurance->familyInsurance = false;
|
||||
|
||||
$result = $this->resolver->resolveType($insurance);
|
||||
|
||||
$this->assertNull($result);
|
||||
}
|
||||
|
||||
public function testResolveTypeForPackageWithTravelProtectionContent(): void
|
||||
{
|
||||
// Create contained insurances
|
||||
$protectionInsurance = new Insurance();
|
||||
$protectionInsurance->subType = 'PAK';
|
||||
|
||||
$deductibleInsurance = new Insurance();
|
||||
$deductibleInsurance->subType = 'OHN';
|
||||
|
||||
// Create package
|
||||
$package = new Insurance();
|
||||
$package->package = true;
|
||||
$package->familyInsurance = false;
|
||||
$package->containedInsurances = [$protectionInsurance, $deductibleInsurance];
|
||||
|
||||
$result = $this->resolver->resolveType($package);
|
||||
|
||||
$this->assertEquals(InsuranceTypeResolver::TRAVEL_PROTECTION, $result);
|
||||
}
|
||||
|
||||
public function testResolveTypeForFamilyPackageWithTravelProtectionContent(): void
|
||||
{
|
||||
// Create contained insurances
|
||||
$protectionInsurance = new Insurance();
|
||||
$protectionInsurance->subType = 'PAK';
|
||||
|
||||
$deductibleInsurance = new Insurance();
|
||||
$deductibleInsurance->subType = 'OHN';
|
||||
|
||||
// Create family package
|
||||
$package = new Insurance();
|
||||
$package->package = true;
|
||||
$package->familyInsurance = true;
|
||||
$package->containedInsurances = [$protectionInsurance, $deductibleInsurance];
|
||||
|
||||
$result = $this->resolver->resolveType($package);
|
||||
|
||||
$this->assertEquals(InsuranceTypeResolver::TRAVEL_PROTECTION_FAMILY, $result);
|
||||
}
|
||||
|
||||
public function testResolveTypeForPackageWithTravelCancellationContent(): void
|
||||
{
|
||||
// Create contained insurances
|
||||
$cancellationInsurance = new Insurance();
|
||||
$cancellationInsurance->subType = 'RRV';
|
||||
|
||||
$deductibleInsurance = new Insurance();
|
||||
$deductibleInsurance->subType = 'OHN';
|
||||
|
||||
// Create package
|
||||
$package = new Insurance();
|
||||
$package->package = true;
|
||||
$package->familyInsurance = false;
|
||||
$package->containedInsurances = [$cancellationInsurance, $deductibleInsurance];
|
||||
|
||||
$result = $this->resolver->resolveType($package);
|
||||
|
||||
$this->assertEquals(InsuranceTypeResolver::TRAVEL_CANCELLATION, $result);
|
||||
}
|
||||
|
||||
public function testResolveTypeForPackageWithOnlyDeductibleContent(): void
|
||||
{
|
||||
// Create contained insurance (only deductible)
|
||||
$deductibleInsurance = new Insurance();
|
||||
$deductibleInsurance->subType = 'OHN';
|
||||
|
||||
// Create package
|
||||
$package = new Insurance();
|
||||
$package->package = true;
|
||||
$package->familyInsurance = false;
|
||||
$package->containedInsurances = [$deductibleInsurance];
|
||||
|
||||
$result = $this->resolver->resolveType($package);
|
||||
|
||||
$this->assertNull($result);
|
||||
}
|
||||
|
||||
public function testResolveTypeForPackageWithNoContainedInsurances(): void
|
||||
{
|
||||
$package = new Insurance();
|
||||
$package->package = true;
|
||||
$package->familyInsurance = false;
|
||||
$package->containedInsurances = [];
|
||||
|
||||
$result = $this->resolver->resolveType($package);
|
||||
|
||||
$this->assertNull($result);
|
||||
}
|
||||
|
||||
public function testResolveTypeForPackageWithMultiplePrimaryTypes(): void
|
||||
{
|
||||
// Create contained insurances with multiple primary types
|
||||
$protectionInsurance = new Insurance();
|
||||
$protectionInsurance->subType = 'PAK';
|
||||
|
||||
$cancellationInsurance = new Insurance();
|
||||
$cancellationInsurance->subType = 'RRV';
|
||||
|
||||
// Create package - should return first non-deductible type found
|
||||
$package = new Insurance();
|
||||
$package->package = true;
|
||||
$package->familyInsurance = false;
|
||||
$package->containedInsurances = [$protectionInsurance, $cancellationInsurance];
|
||||
|
||||
$result = $this->resolver->resolveType($package);
|
||||
|
||||
$this->assertEquals(InsuranceTypeResolver::TRAVEL_PROTECTION, $result);
|
||||
}
|
||||
|
||||
public function testGetAllTypes(): void
|
||||
{
|
||||
$types = $this->resolver->getAllTypes();
|
||||
|
||||
$expectedTypes = [
|
||||
InsuranceTypeResolver::TRAVEL_CANCELLATION,
|
||||
InsuranceTypeResolver::TRAVEL_CANCELLATION_FAMILY,
|
||||
InsuranceTypeResolver::TRAVEL_PROTECTION,
|
||||
InsuranceTypeResolver::TRAVEL_PROTECTION_FAMILY,
|
||||
InsuranceTypeResolver::DEDUCTIBLE,
|
||||
];
|
||||
|
||||
$this->assertEquals($expectedTypes, $types);
|
||||
$this->assertCount(5, $types);
|
||||
}
|
||||
|
||||
public function testIsFamilyType(): void
|
||||
{
|
||||
$this->assertTrue($this->resolver->isFamilyType(InsuranceTypeResolver::TRAVEL_CANCELLATION_FAMILY));
|
||||
$this->assertTrue($this->resolver->isFamilyType(InsuranceTypeResolver::TRAVEL_PROTECTION_FAMILY));
|
||||
$this->assertFalse($this->resolver->isFamilyType(InsuranceTypeResolver::TRAVEL_CANCELLATION));
|
||||
$this->assertFalse($this->resolver->isFamilyType(InsuranceTypeResolver::TRAVEL_PROTECTION));
|
||||
$this->assertFalse($this->resolver->isFamilyType(InsuranceTypeResolver::DEDUCTIBLE));
|
||||
}
|
||||
|
||||
public function testGetBaseType(): void
|
||||
{
|
||||
$this->assertEquals(
|
||||
InsuranceTypeResolver::TRAVEL_CANCELLATION,
|
||||
$this->resolver->getBaseType(InsuranceTypeResolver::TRAVEL_CANCELLATION_FAMILY)
|
||||
);
|
||||
$this->assertEquals(
|
||||
InsuranceTypeResolver::TRAVEL_PROTECTION,
|
||||
$this->resolver->getBaseType(InsuranceTypeResolver::TRAVEL_PROTECTION_FAMILY)
|
||||
);
|
||||
$this->assertEquals(
|
||||
InsuranceTypeResolver::TRAVEL_CANCELLATION,
|
||||
$this->resolver->getBaseType(InsuranceTypeResolver::TRAVEL_CANCELLATION)
|
||||
);
|
||||
$this->assertEquals(
|
||||
InsuranceTypeResolver::DEDUCTIBLE,
|
||||
$this->resolver->getBaseType(InsuranceTypeResolver::DEDUCTIBLE)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user