feat: implement mutability cutoff for rentals
addresses #869cca42x
This commit is contained in:
1 parent
752e6752b4
commit
cb56a4fe46
9 files changed
+253
-8
No files matched your search
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Form\Service\Condition;
|
||||
|
||||
use App\BusProNet\Model\Booking;
|
||||
use App\BusProNet\Model\Travel;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Service\Condition\TravelStartCutoffReachedCondition;
|
||||
use Carbon\CarbonImmutable;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class TravelStartCutoffReachedConditionTest extends TestCase
|
||||
{
|
||||
protected function tearDown(): void
|
||||
{
|
||||
CarbonImmutable::setTestNow();
|
||||
}
|
||||
|
||||
public function testEvaluateReturnsFalseBeforeCutoff(): void
|
||||
{
|
||||
CarbonImmutable::setTestNow('2026-01-05 10:00:00');
|
||||
$condition = new TravelStartCutoffReachedCondition(4);
|
||||
|
||||
$result = $condition->evaluate($this->createCreateDto('2026-01-10 12:00:00'), 0, []);
|
||||
|
||||
$this->assertFalse($result);
|
||||
}
|
||||
|
||||
public function testEvaluateReturnsTrueAtInclusiveCutoffBoundary(): void
|
||||
{
|
||||
CarbonImmutable::setTestNow('2026-01-06 01:00:00');
|
||||
$condition = new TravelStartCutoffReachedCondition(4);
|
||||
|
||||
$result = $condition->evaluate($this->createCreateDto('2026-01-10 12:00:00'), 0, []);
|
||||
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
public function testEvaluateReturnsTrueAfterCutoff(): void
|
||||
{
|
||||
CarbonImmutable::setTestNow('2026-01-08 09:00:00');
|
||||
$condition = new TravelStartCutoffReachedCondition(4);
|
||||
|
||||
$result = $condition->evaluate($this->createCreateDto('2026-01-10 12:00:00'), 0, []);
|
||||
|
||||
$this->assertTrue($result);
|
||||
}
|
||||
|
||||
public function testEvaluateReturnsTrueInEditModeAfterCutoff(): void
|
||||
{
|
||||
CarbonImmutable::setTestNow('2026-01-08 09:00:00');
|
||||
$condition = new TravelStartCutoffReachedCondition(4);
|
||||
|
||||
$this->assertTrue($condition->evaluate($this->createEditDto('2026-01-10 12:00:00'), 0, []));
|
||||
}
|
||||
|
||||
public function testConstructorThrowsForNegativeDays(): void
|
||||
{
|
||||
$this->expectException(\InvalidArgumentException::class);
|
||||
|
||||
new TravelStartCutoffReachedCondition(-1);
|
||||
}
|
||||
|
||||
private function createCreateDto(string $travelStartDate): BookingDto
|
||||
{
|
||||
$travel = new Travel();
|
||||
$travel->dateFrom = new \DateTimeImmutable($travelStartDate);
|
||||
|
||||
return new BookingDto($travel, 1);
|
||||
}
|
||||
|
||||
private function createEditDto(string $travelStartDate): BookingDto
|
||||
{
|
||||
$dto = $this->createCreateDto($travelStartDate);
|
||||
$dto->booking = new Booking();
|
||||
|
||||
return $dto;
|
||||
}
|
||||
}
|
||||
@@ -12,10 +12,16 @@ use App\BusProNet\Model\Travel;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Model\ParticipantDto;
|
||||
use App\Service\BookingEditSubmitGuardService;
|
||||
use Carbon\CarbonImmutable;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class BookingEditSubmitGuardServiceTest extends TestCase
|
||||
{
|
||||
protected function tearDown(): void
|
||||
{
|
||||
CarbonImmutable::setTestNow();
|
||||
}
|
||||
|
||||
public function testReconcileImmutableCategoriesRestoresLockedServiceData(): void
|
||||
{
|
||||
$travel = new Travel();
|
||||
@@ -90,6 +96,43 @@ class BookingEditSubmitGuardServiceTest extends TestCase
|
||||
$this->assertSame([99], array_map(static fn (Service $s) => $s->id, $workingParticipant->additionalServices));
|
||||
}
|
||||
|
||||
public function testReconcileImmutableCategoriesLocksRentalsFromFourDaysBeforeTravelStart(): void
|
||||
{
|
||||
CarbonImmutable::setTestNow('2026-01-08 12:00:00');
|
||||
|
||||
$travel = new Travel();
|
||||
$travel->dateFrom = new \DateTimeImmutable('2026-01-10 09:00:00');
|
||||
$travel->additionalServicesMutable = true;
|
||||
$travel->transportationServicesMutable = true;
|
||||
$travel->pickupsMutable = true;
|
||||
|
||||
$workingParticipant = new ParticipantDto();
|
||||
$workingParticipant->index = 0;
|
||||
$workingParticipant->rentals = [$this->createService(99)];
|
||||
|
||||
$workingDto = new BookingDto($travel, 1);
|
||||
$workingDto->participants = [$workingParticipant];
|
||||
|
||||
$baselineParticipant = new ParticipantDto();
|
||||
$baselineParticipant->index = 0;
|
||||
$baselineParticipant->rentals = [$this->createService(10)];
|
||||
|
||||
$baselineDto = new BookingDto($travel, 1);
|
||||
$baselineDto->participants = [$baselineParticipant];
|
||||
|
||||
$processor = $this->createMock(BookingDataProcessor::class);
|
||||
$processor->expects($this->once())
|
||||
->method('createBookingDtoFromBooking')
|
||||
->willReturn($baselineDto);
|
||||
|
||||
$service = new BookingEditSubmitGuardService($processor);
|
||||
|
||||
$changed = $service->reconcileImmutableCategories($workingDto, new Booking());
|
||||
|
||||
$this->assertTrue($changed);
|
||||
$this->assertSame([10], array_map(static fn (Service $s) => $s->id, $workingParticipant->rentals));
|
||||
}
|
||||
|
||||
private function createService(int $id): Service
|
||||
{
|
||||
$service = new Service();
|
||||
|
||||
Reference in new issue
Block a user