feat: auto-booking services
addresses #869cfcptv
This commit is contained in:
@@ -0,0 +1,107 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Form\Service;
|
||||
|
||||
use App\BusProNet\Constants;
|
||||
use App\BusProNet\Model\Service;
|
||||
use App\BusProNet\Model\Travel;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Model\ParticipantDto;
|
||||
use App\Form\Service\ParticipantRentalsFieldHandler;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ParticipantRentalsFieldHandlerTest extends TestCase
|
||||
{
|
||||
public function testDeselectAutoBookRentalAddsOptOutId(): void
|
||||
{
|
||||
$skiPass = $this->createSkiPass(70);
|
||||
$autoBookRental = $this->createRental(71, autoBook: true, mandatory: false);
|
||||
$bookingDto = $this->createBookingDtoWithSkiPassAndRental($skiPass, $autoBookRental);
|
||||
$participant = $bookingDto->participants[0];
|
||||
$participant->rentals = [$autoBookRental];
|
||||
|
||||
$handler = new ParticipantRentalsFieldHandler();
|
||||
$handler->processField([], $bookingDto, 0);
|
||||
|
||||
$this->assertSame([71], $participant->autoBookOptOutRentalIds);
|
||||
$this->assertSame([], $participant->rentals);
|
||||
}
|
||||
|
||||
public function testDeselectMandatoryAutoBookRentalDoesNotAddOptOutId(): void
|
||||
{
|
||||
$skiPass = $this->createSkiPass(72);
|
||||
$mandatoryAutoBookRental = $this->createRental(73, autoBook: true, mandatory: true);
|
||||
$bookingDto = $this->createBookingDtoWithSkiPassAndRental($skiPass, $mandatoryAutoBookRental);
|
||||
$participant = $bookingDto->participants[0];
|
||||
$participant->rentals = [$mandatoryAutoBookRental];
|
||||
|
||||
$handler = new ParticipantRentalsFieldHandler();
|
||||
$handler->processField([], $bookingDto, 0);
|
||||
|
||||
$this->assertSame([], $participant->autoBookOptOutRentalIds);
|
||||
}
|
||||
|
||||
public function testReselectAutoBookRentalRemovesOptOutId(): void
|
||||
{
|
||||
$skiPass = $this->createSkiPass(74);
|
||||
$autoBookRental = $this->createRental(75, autoBook: true, mandatory: false);
|
||||
$bookingDto = $this->createBookingDtoWithSkiPassAndRental($skiPass, $autoBookRental);
|
||||
$participant = $bookingDto->participants[0];
|
||||
$participant->autoBookOptOutRentalIds = [75];
|
||||
|
||||
$handler = new ParticipantRentalsFieldHandler();
|
||||
$handler->processField(['rentals' => ['75']], $bookingDto, 0);
|
||||
|
||||
$this->assertSame([], $participant->autoBookOptOutRentalIds);
|
||||
$this->assertCount(1, $participant->rentals);
|
||||
$this->assertSame(75, $participant->rentals[0]->id);
|
||||
}
|
||||
|
||||
private function createBookingDtoWithSkiPassAndRental(Service $skiPass, Service $rental): BookingDto
|
||||
{
|
||||
$travel = new Travel();
|
||||
$travel->dateFrom = new \DateTimeImmutable('2030-01-01');
|
||||
$travel->dateTo = new \DateTimeImmutable('2030-01-08');
|
||||
$travel->additionalServices = [
|
||||
$skiPass->id => $skiPass,
|
||||
$rental->id => $rental,
|
||||
];
|
||||
|
||||
$bookingDto = new BookingDto($travel, 1);
|
||||
$participant = new ParticipantDto();
|
||||
$participant->index = 0;
|
||||
$participant->dateOfBirth = $travel->dateFrom->modify('-25 years');
|
||||
$participant->skiPass = $skiPass;
|
||||
$bookingDto->participants[0] = $participant;
|
||||
|
||||
return $bookingDto;
|
||||
}
|
||||
|
||||
private function createSkiPass(int $id): Service
|
||||
{
|
||||
$service = new Service();
|
||||
$service->id = $id;
|
||||
$service->subType = Constants::TOKEN_SKI_PASS;
|
||||
$service->label = 'Ski Pass';
|
||||
$service->dateFrom = new \DateTimeImmutable('2030-01-01');
|
||||
$service->dateTo = new \DateTimeImmutable('2030-01-07');
|
||||
|
||||
return $service;
|
||||
}
|
||||
|
||||
private function createRental(int $id, bool $autoBook, bool $mandatory): Service
|
||||
{
|
||||
$service = new Service();
|
||||
$service->id = $id;
|
||||
$service->subType = 'VER';
|
||||
$service->label = 'Rental';
|
||||
$service->autoBook = $autoBook;
|
||||
$service->mandatory = $mandatory;
|
||||
$service->dateFrom = new \DateTimeImmutable('2030-01-01');
|
||||
$service->dateTo = new \DateTimeImmutable('2030-01-07');
|
||||
|
||||
return $service;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user