feat: auto-booking services

addresses #869cfcptv
This commit is contained in:
Björn Fromme
2026-03-16 20:24:58 +01:00
parent 6d9265de0f
commit c510cbf590
19 changed files with 1829 additions and 72 deletions
+545
View File
@@ -189,6 +189,299 @@ class BookingServiceBabyTest extends TestCase
$this->assertEmpty($participant->additionalServices, 'Age should be calculated at travel date, not current date');
}
public function testPreselectMandatoryServicesIncludesAutoBookServiceForEligibleParticipant(): void
{
$travel = $this->createTravelWithAutoBookServices();
$bookingDto = new BookingDto($travel, 1);
$participant = new ParticipantDto();
$participant->index = 0;
$participant->dateOfBirth = $travel->dateFrom->modify('-25 years');
$participant->additionalServices = [];
$bookingDto->participants[0] = $participant;
$this->participantEligibilityService
->method('isParticipantEligible')
->willReturn(true);
$this->bookingService->preselectMandatoryServices($bookingDto);
$this->assertCount(1, $participant->additionalServices);
$this->assertSame('Auto Book Service', $participant->additionalServices[0]->label);
}
public function testPreselectMandatoryServicesRespectsAutoBookOptOut(): void
{
$travel = $this->createTravelWithAutoBookServices();
$bookingDto = new BookingDto($travel, 1);
$participant = new ParticipantDto();
$participant->index = 0;
$participant->dateOfBirth = $travel->dateFrom->modify('-25 years');
$participant->additionalServices = [];
$participant->autoBookOptOutServiceIds = [2];
$bookingDto->participants[0] = $participant;
$this->participantEligibilityService
->method('isParticipantEligible')
->willReturn(true);
$this->bookingService->preselectMandatoryServices($bookingDto);
$this->assertEmpty($participant->additionalServices);
}
public function testPreselectMandatoryServicesMandatoryOverridesAutoBookOptOut(): void
{
$travel = $this->createTravelWithMandatoryAndAutoBookService();
$bookingDto = new BookingDto($travel, 1);
$participant = new ParticipantDto();
$participant->index = 0;
$participant->dateOfBirth = $travel->dateFrom->modify('-25 years');
$participant->additionalServices = [];
$participant->autoBookOptOutServiceIds = [3];
$bookingDto->participants[0] = $participant;
$this->participantEligibilityService
->method('isParticipantEligible')
->willReturn(true);
$this->bookingService->preselectMandatoryServices($bookingDto);
$this->assertCount(1, $participant->additionalServices);
$this->assertSame('Mandatory And Auto Book Service', $participant->additionalServices[0]->label);
}
public function testPreselectMandatoryServicesIncludesAutoBookSkiPassForEligibleParticipant(): void
{
$travel = $this->createTravelWithAutoBookSkiPassServices();
$bookingDto = new BookingDto($travel, 1);
$participant = new ParticipantDto();
$participant->index = 0;
$participant->dateOfBirth = $travel->dateFrom->modify('-25 years');
$bookingDto->participants[0] = $participant;
$this->participantEligibilityService
->method('isParticipantEligible')
->willReturn(true);
$this->bookingService->preselectMandatoryServices($bookingDto);
$this->assertNotNull($participant->skiPass);
$this->assertSame('Auto Book Ski Pass', $participant->skiPass?->label);
}
public function testPreselectMandatoryServicesRespectsAutoBookSkiPassOptOut(): void
{
$travel = $this->createTravelWithAutoBookSkiPassServices();
$bookingDto = new BookingDto($travel, 1);
$participant = new ParticipantDto();
$participant->index = 0;
$participant->dateOfBirth = $travel->dateFrom->modify('-25 years');
$participant->autoBookOptOutSkiPassIds = [20];
$bookingDto->participants[0] = $participant;
$this->participantEligibilityService
->method('isParticipantEligible')
->willReturn(true);
$this->bookingService->preselectMandatoryServices($bookingDto);
$this->assertNull($participant->skiPass);
}
public function testPreselectMandatoryServicesMandatorySkiPassOverridesAutoBookOptOut(): void
{
$travel = $this->createTravelWithMandatoryAndAutoBookSkiPassService();
$bookingDto = new BookingDto($travel, 1);
$participant = new ParticipantDto();
$participant->index = 0;
$participant->dateOfBirth = $travel->dateFrom->modify('-25 years');
$participant->autoBookOptOutSkiPassIds = [21];
$bookingDto->participants[0] = $participant;
$this->participantEligibilityService
->method('isParticipantEligible')
->willReturn(true);
$this->bookingService->preselectMandatoryServices($bookingDto);
$this->assertNotNull($participant->skiPass);
$this->assertSame('Mandatory And Auto Book Ski Pass', $participant->skiPass?->label);
}
public function testPreselectMandatoryServicesIncludesAutoBookBoardForEligibleParticipant(): void
{
$travel = $this->createTravelWithAutoBookBoardServices();
$bookingDto = new BookingDto($travel, 1);
$participant = new ParticipantDto();
$participant->index = 0;
$participant->dateOfBirth = $travel->dateFrom->modify('-25 years');
$bookingDto->participants[0] = $participant;
$this->participantEligibilityService
->method('isParticipantEligible')
->willReturn(true);
$this->bookingService->preselectMandatoryServices($bookingDto);
$this->assertCount(1, $participant->board);
$this->assertSame('Auto Book Board', $participant->board[0]->label);
}
public function testPreselectMandatoryServicesRespectsAutoBookBoardOptOut(): void
{
$travel = $this->createTravelWithAutoBookBoardServices();
$bookingDto = new BookingDto($travel, 1);
$participant = new ParticipantDto();
$participant->index = 0;
$participant->dateOfBirth = $travel->dateFrom->modify('-25 years');
$participant->autoBookOptOutBoardIds = [40];
$bookingDto->participants[0] = $participant;
$this->participantEligibilityService
->method('isParticipantEligible')
->willReturn(true);
$this->bookingService->preselectMandatoryServices($bookingDto);
$this->assertSame([], $participant->board);
}
public function testPreselectMandatoryServicesMandatoryBoardOverridesAutoBookOptOut(): void
{
$travel = $this->createTravelWithMandatoryAndAutoBookBoardService();
$bookingDto = new BookingDto($travel, 1);
$participant = new ParticipantDto();
$participant->index = 0;
$participant->dateOfBirth = $travel->dateFrom->modify('-25 years');
$participant->autoBookOptOutBoardIds = [41];
$bookingDto->participants[0] = $participant;
$this->participantEligibilityService
->method('isParticipantEligible')
->willReturn(true);
$this->bookingService->preselectMandatoryServices($bookingDto);
$this->assertCount(1, $participant->board);
$this->assertSame('Mandatory And Auto Book Board', $participant->board[0]->label);
}
public function testPreselectMandatoryServicesIncludesAutoBookRentalForMatchingSkiPass(): void
{
$travel = $this->createTravelWithAutoBookRentalServices();
$bookingDto = new BookingDto($travel, 1);
$participant = new ParticipantDto();
$participant->index = 0;
$participant->dateOfBirth = $travel->dateFrom->modify('-25 years');
$participant->skiPass = $travel->additionalServices[20];
$bookingDto->participants[0] = $participant;
$this->participantEligibilityService
->method('isParticipantEligible')
->willReturn(true);
$this->bookingService->preselectMandatoryServices($bookingDto);
$this->assertCount(1, $participant->rentals);
$this->assertSame('Auto Book Rental', $participant->rentals[0]->label);
}
public function testPreselectMandatoryServicesRespectsAutoBookRentalOptOut(): void
{
$travel = $this->createTravelWithAutoBookRentalServices();
$bookingDto = new BookingDto($travel, 1);
$participant = new ParticipantDto();
$participant->index = 0;
$participant->dateOfBirth = $travel->dateFrom->modify('-25 years');
$participant->skiPass = $travel->additionalServices[20];
$participant->autoBookOptOutRentalIds = [50];
$bookingDto->participants[0] = $participant;
$this->participantEligibilityService
->method('isParticipantEligible')
->willReturn(true);
$this->bookingService->preselectMandatoryServices($bookingDto);
$this->assertSame([], $participant->rentals);
}
public function testPreselectMandatoryServicesMandatoryRentalOverridesAutoBookOptOut(): void
{
$travel = $this->createTravelWithMandatoryAndAutoBookRentalServices();
$bookingDto = new BookingDto($travel, 1);
$participant = new ParticipantDto();
$participant->index = 0;
$participant->dateOfBirth = $travel->dateFrom->modify('-25 years');
$participant->skiPass = $travel->additionalServices[22];
$participant->autoBookOptOutRentalIds = [51];
$bookingDto->participants[0] = $participant;
$this->participantEligibilityService
->method('isParticipantEligible')
->willReturn(true);
$this->bookingService->preselectMandatoryServices($bookingDto);
$this->assertCount(1, $participant->rentals);
$this->assertSame('Mandatory And Auto Book Rental', $participant->rentals[0]->label);
}
public function testPreselectMandatoryServicesSkipsAutoBookRentalWithoutSkiPass(): void
{
$travel = $this->createTravelWithAutoBookRentalServices();
$bookingDto = new BookingDto($travel, 1);
$participant = new ParticipantDto();
$participant->index = 0;
$participant->dateOfBirth = $travel->dateFrom->modify('-25 years');
$bookingDto->participants[0] = $participant;
$this->participantEligibilityService
->method('isParticipantEligible')
->willReturn(true);
$this->bookingService->preselectMandatoryServices($bookingDto);
$this->assertSame([], $participant->rentals);
}
public function testPreselectMandatoryServicesSkipsAutoBookRentalForNonMatchingSkiPassDuration(): void
{
$travel = $this->createTravelWithAutoBookRentalServices();
$bookingDto = new BookingDto($travel, 1);
$participant = new ParticipantDto();
$participant->index = 0;
$participant->dateOfBirth = $travel->dateFrom->modify('-25 years');
$participant->skiPass = new Service();
$participant->skiPass->id = 99;
$participant->skiPass->subType = Constants::TOKEN_SKI_PASS;
$participant->skiPass->dateFrom = new \DateTimeImmutable('+31 days');
$participant->skiPass->dateTo = new \DateTimeImmutable('+35 days');
$bookingDto->participants[0] = $participant;
$this->participantEligibilityService
->method('isParticipantEligible')
->willReturn(true);
$this->bookingService->preselectMandatoryServices($bookingDto);
$this->assertSame([], $participant->rentals);
}
private function createTravelWithMandatoryServices(): Travel
{
$travel = new Travel();
@@ -199,6 +492,86 @@ class BookingServiceBabyTest extends TestCase
return $travel;
}
private function createTravelWithAutoBookServices(): Travel
{
$travel = new Travel();
$travel->dateFrom = new \DateTimeImmutable('+30 days');
$travel->dateTo = new \DateTimeImmutable('+37 days');
$travel->additionalServices = $this->createAutoBookAdditionalServices();
return $travel;
}
private function createTravelWithMandatoryAndAutoBookService(): Travel
{
$travel = new Travel();
$travel->dateFrom = new \DateTimeImmutable('+30 days');
$travel->dateTo = new \DateTimeImmutable('+37 days');
$travel->additionalServices = $this->createMandatoryAndAutoBookAdditionalServices();
return $travel;
}
private function createTravelWithAutoBookSkiPassServices(): Travel
{
$travel = new Travel();
$travel->dateFrom = new \DateTimeImmutable('+30 days');
$travel->dateTo = new \DateTimeImmutable('+37 days');
$travel->additionalServices = $this->createAutoBookSkiPassServices();
return $travel;
}
private function createTravelWithMandatoryAndAutoBookSkiPassService(): Travel
{
$travel = new Travel();
$travel->dateFrom = new \DateTimeImmutable('+30 days');
$travel->dateTo = new \DateTimeImmutable('+37 days');
$travel->additionalServices = $this->createMandatoryAndAutoBookSkiPassServices();
return $travel;
}
private function createTravelWithAutoBookBoardServices(): Travel
{
$travel = new Travel();
$travel->dateFrom = new \DateTimeImmutable('+30 days');
$travel->dateTo = new \DateTimeImmutable('+37 days');
$travel->additionalServices = $this->createAutoBookBoardServices();
return $travel;
}
private function createTravelWithMandatoryAndAutoBookBoardService(): Travel
{
$travel = new Travel();
$travel->dateFrom = new \DateTimeImmutable('+30 days');
$travel->dateTo = new \DateTimeImmutable('+37 days');
$travel->additionalServices = $this->createMandatoryAndAutoBookBoardServices();
return $travel;
}
private function createTravelWithAutoBookRentalServices(): Travel
{
$travel = new Travel();
$travel->dateFrom = new \DateTimeImmutable('2030-01-01');
$travel->dateTo = new \DateTimeImmutable('2030-01-08');
$travel->additionalServices = $this->createAutoBookRentalServices();
return $travel;
}
private function createTravelWithMandatoryAndAutoBookRentalServices(): Travel
{
$travel = new Travel();
$travel->dateFrom = new \DateTimeImmutable('2030-01-01');
$travel->dateTo = new \DateTimeImmutable('2030-01-08');
$travel->additionalServices = $this->createMandatoryAndAutoBookRentalServices();
return $travel;
}
/**
* @return array<int, Service>
*/
@@ -214,4 +587,176 @@ class BookingServiceBabyTest extends TestCase
return [1 => $mandatoryService];
}
/**
* @return array<int, Service>
*/
private function createAutoBookAdditionalServices(): array
{
$autoBookService = new Service();
$autoBookService->id = 2;
$autoBookService->label = 'Auto Book Service';
$autoBookService->subType = Constants::TOKEN_ADDITIONAL;
$autoBookService->mandatory = false;
$autoBookService->autoBook = true;
$autoBookService->available = 10;
$autoBookService->price = 10.0;
return [2 => $autoBookService];
}
/**
* @return array<int, Service>
*/
private function createMandatoryAndAutoBookAdditionalServices(): array
{
$service = new Service();
$service->id = 3;
$service->label = 'Mandatory And Auto Book Service';
$service->subType = Constants::TOKEN_ADDITIONAL;
$service->mandatory = true;
$service->autoBook = true;
$service->available = 10;
$service->price = 10.0;
return [3 => $service];
}
/**
* @return array<int, Service>
*/
private function createAutoBookSkiPassServices(): array
{
$service = new Service();
$service->id = 20;
$service->label = 'Auto Book Ski Pass';
$service->subType = Constants::TOKEN_SKI_PASS;
$service->mandatory = false;
$service->autoBook = true;
$service->available = 10;
$service->price = 59.0;
$service->dateFrom = new \DateTimeImmutable('+30 days');
$service->dateTo = new \DateTimeImmutable('+36 days');
return [20 => $service];
}
/**
* @return array<int, Service>
*/
private function createMandatoryAndAutoBookSkiPassServices(): array
{
$service = new Service();
$service->id = 21;
$service->label = 'Mandatory And Auto Book Ski Pass';
$service->subType = Constants::TOKEN_SKI_PASS;
$service->mandatory = true;
$service->autoBook = true;
$service->available = 10;
$service->price = 59.0;
$service->dateFrom = new \DateTimeImmutable('+30 days');
$service->dateTo = new \DateTimeImmutable('+36 days');
return [21 => $service];
}
/**
* @return array<int, Service>
*/
private function createAutoBookBoardServices(): array
{
$service = new Service();
$service->id = 40;
$service->label = 'Auto Book Board';
$service->subType = Constants::TOKEN_BOARD;
$service->mandatory = false;
$service->autoBook = true;
$service->available = 10;
$service->price = 12.0;
return [40 => $service];
}
/**
* @return array<int, Service>
*/
private function createMandatoryAndAutoBookBoardServices(): array
{
$service = new Service();
$service->id = 41;
$service->label = 'Mandatory And Auto Book Board';
$service->subType = Constants::TOKEN_BOARD;
$service->mandatory = true;
$service->autoBook = true;
$service->available = 10;
$service->price = 12.0;
return [41 => $service];
}
/**
* @return array<int, Service>
*/
private function createAutoBookRentalServices(): array
{
$serviceDateFrom = new \DateTimeImmutable('2030-01-01');
$serviceDateTo = new \DateTimeImmutable('2030-01-07');
$skiPass = new Service();
$skiPass->id = 20;
$skiPass->label = 'Matching Ski Pass';
$skiPass->subType = Constants::TOKEN_SKI_PASS;
$skiPass->mandatory = false;
$skiPass->autoBook = false;
$skiPass->available = 10;
$skiPass->price = 59.0;
$skiPass->dateFrom = $serviceDateFrom;
$skiPass->dateTo = $serviceDateTo;
$rental = new Service();
$rental->id = 50;
$rental->label = 'Auto Book Rental';
$rental->subType = 'VER';
$rental->mandatory = false;
$rental->autoBook = true;
$rental->available = 10;
$rental->price = 39.0;
$rental->dateFrom = $serviceDateFrom;
$rental->dateTo = $serviceDateTo;
return [20 => $skiPass, 50 => $rental];
}
/**
* @return array<int, Service>
*/
private function createMandatoryAndAutoBookRentalServices(): array
{
$serviceDateFrom = new \DateTimeImmutable('2030-01-01');
$serviceDateTo = new \DateTimeImmutable('2030-01-07');
$skiPass = new Service();
$skiPass->id = 22;
$skiPass->label = 'Matching Ski Pass Mandatory Rental';
$skiPass->subType = Constants::TOKEN_SKI_PASS;
$skiPass->mandatory = false;
$skiPass->autoBook = false;
$skiPass->available = 10;
$skiPass->price = 59.0;
$skiPass->dateFrom = $serviceDateFrom;
$skiPass->dateTo = $serviceDateTo;
$rental = new Service();
$rental->id = 51;
$rental->label = 'Mandatory And Auto Book Rental';
$rental->subType = 'VER';
$rental->mandatory = true;
$rental->autoBook = true;
$rental->available = 10;
$rental->price = 39.0;
$rental->dateFrom = $serviceDateFrom;
$rental->dateTo = $serviceDateTo;
return [22 => $skiPass, 51 => $rental];
}
}