feat: auto-booking services
addresses #869cfcptv
This commit is contained in:
@@ -0,0 +1,98 @@
|
||||
<?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\ParticipantBoardFieldHandler;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class ParticipantBoardFieldHandlerTest extends TestCase
|
||||
{
|
||||
public function testDeselectAutoBookBoardAddsOptOutId(): void
|
||||
{
|
||||
$autoBookBoard = new Service();
|
||||
$autoBookBoard->id = 60;
|
||||
$autoBookBoard->subType = Constants::TOKEN_BOARD;
|
||||
$autoBookBoard->label = 'Auto Book Board';
|
||||
$autoBookBoard->autoBook = true;
|
||||
|
||||
$travel = new Travel();
|
||||
$travel->dateFrom = new \DateTimeImmutable('+30 days');
|
||||
$travel->dateTo = new \DateTimeImmutable('+37 days');
|
||||
$travel->additionalServices = [60 => $autoBookBoard];
|
||||
|
||||
$bookingDto = new BookingDto($travel, 1);
|
||||
$participant = new ParticipantDto();
|
||||
$participant->index = 0;
|
||||
$participant->dateOfBirth = $travel->dateFrom->modify('-25 years');
|
||||
$participant->board = [$autoBookBoard];
|
||||
$bookingDto->participants[0] = $participant;
|
||||
|
||||
$handler = new ParticipantBoardFieldHandler();
|
||||
$handler->processField([], $bookingDto, 0);
|
||||
|
||||
$this->assertSame([60], $participant->autoBookOptOutBoardIds);
|
||||
$this->assertSame([], $participant->board);
|
||||
}
|
||||
|
||||
public function testDeselectMandatoryAutoBookBoardDoesNotAddOptOutId(): void
|
||||
{
|
||||
$mandatoryAutoBookBoard = new Service();
|
||||
$mandatoryAutoBookBoard->id = 61;
|
||||
$mandatoryAutoBookBoard->subType = Constants::TOKEN_BOARD;
|
||||
$mandatoryAutoBookBoard->label = 'Mandatory Auto Book Board';
|
||||
$mandatoryAutoBookBoard->mandatory = true;
|
||||
$mandatoryAutoBookBoard->autoBook = true;
|
||||
|
||||
$travel = new Travel();
|
||||
$travel->dateFrom = new \DateTimeImmutable('+30 days');
|
||||
$travel->dateTo = new \DateTimeImmutable('+37 days');
|
||||
$travel->additionalServices = [61 => $mandatoryAutoBookBoard];
|
||||
|
||||
$bookingDto = new BookingDto($travel, 1);
|
||||
$participant = new ParticipantDto();
|
||||
$participant->index = 0;
|
||||
$participant->dateOfBirth = $travel->dateFrom->modify('-25 years');
|
||||
$participant->board = [$mandatoryAutoBookBoard];
|
||||
$bookingDto->participants[0] = $participant;
|
||||
|
||||
$handler = new ParticipantBoardFieldHandler();
|
||||
$handler->processField([], $bookingDto, 0);
|
||||
|
||||
$this->assertSame([], $participant->autoBookOptOutBoardIds);
|
||||
}
|
||||
|
||||
public function testReselectAutoBookBoardRemovesOptOutId(): void
|
||||
{
|
||||
$autoBookBoard = new Service();
|
||||
$autoBookBoard->id = 62;
|
||||
$autoBookBoard->subType = Constants::TOKEN_BOARD;
|
||||
$autoBookBoard->label = 'Auto Book Board';
|
||||
$autoBookBoard->autoBook = true;
|
||||
|
||||
$travel = new Travel();
|
||||
$travel->dateFrom = new \DateTimeImmutable('+30 days');
|
||||
$travel->dateTo = new \DateTimeImmutable('+37 days');
|
||||
$travel->additionalServices = [62 => $autoBookBoard];
|
||||
|
||||
$bookingDto = new BookingDto($travel, 1);
|
||||
$participant = new ParticipantDto();
|
||||
$participant->index = 0;
|
||||
$participant->dateOfBirth = $travel->dateFrom->modify('-25 years');
|
||||
$participant->autoBookOptOutBoardIds = [62];
|
||||
$bookingDto->participants[0] = $participant;
|
||||
|
||||
$handler = new ParticipantBoardFieldHandler();
|
||||
$handler->processField(['board' => ['62']], $bookingDto, 0);
|
||||
|
||||
$this->assertSame([], $participant->autoBookOptOutBoardIds);
|
||||
$this->assertCount(1, $participant->board);
|
||||
$this->assertSame(62, $participant->board[0]->id);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user