fix: stop offering unbookable services in the booking edit flow
This commit is contained in:
@@ -4,6 +4,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Service;
|
||||
|
||||
use App\BusProNet\Constants;
|
||||
use App\BusProNet\DataProcessor\BookingDataProcessor;
|
||||
use App\BusProNet\Model\Booking;
|
||||
use App\BusProNet\Model\Pickup;
|
||||
@@ -12,6 +13,7 @@ use App\BusProNet\Model\Travel;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Model\ParticipantDto;
|
||||
use App\Service\BookingEditSubmitGuard;
|
||||
use App\Service\ServiceAvailabilityCalculator;
|
||||
use Carbon\CarbonImmutable;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
@@ -54,7 +56,7 @@ class BookingEditSubmitGuardTest extends TestCase
|
||||
->method('createBookingDtoFromBooking')
|
||||
->willReturn($baselineDto);
|
||||
|
||||
$service = new BookingEditSubmitGuard($processor);
|
||||
$service = new BookingEditSubmitGuard($processor, new ServiceAvailabilityCalculator());
|
||||
|
||||
$changed = $service->reconcileImmutableCategories($workingDto, new Booking());
|
||||
|
||||
@@ -91,7 +93,7 @@ class BookingEditSubmitGuardTest extends TestCase
|
||||
->method('createBookingDtoFromBooking')
|
||||
->willReturn($baselineDto);
|
||||
|
||||
$service = new BookingEditSubmitGuard($processor);
|
||||
$service = new BookingEditSubmitGuard($processor, new ServiceAvailabilityCalculator());
|
||||
|
||||
$changed = $service->reconcileImmutableCategories($workingDto, new Booking());
|
||||
|
||||
@@ -128,7 +130,7 @@ class BookingEditSubmitGuardTest extends TestCase
|
||||
->method('createBookingDtoFromBooking')
|
||||
->willReturn($baselineDto);
|
||||
|
||||
$service = new BookingEditSubmitGuard($processor);
|
||||
$service = new BookingEditSubmitGuard($processor, new ServiceAvailabilityCalculator());
|
||||
|
||||
$changed = $service->reconcileImmutableCategories($workingDto, new Booking());
|
||||
|
||||
@@ -136,6 +138,85 @@ class BookingEditSubmitGuardTest extends TestCase
|
||||
$this->assertSame([10], array_map(static fn (Service $s) => $s->id, $workingParticipant->rentals));
|
||||
}
|
||||
|
||||
public function testRevertUnbookableServiceAdditionsDropsOnRequestAddition(): void
|
||||
{
|
||||
$onRequest = $this->createService(99);
|
||||
$onRequest->label = 'Bus-Hinfahrt';
|
||||
$onRequest->subType = Constants::TOKEN_SKI_PASS;
|
||||
$onRequest->status = Constants::STATUS_ON_REQUEST;
|
||||
|
||||
$travel = new Travel();
|
||||
$travel->additionalServices = [99 => $onRequest];
|
||||
|
||||
$workingParticipant = new ParticipantDto();
|
||||
$workingParticipant->index = 0;
|
||||
$workingParticipant->skiPass = $onRequest;
|
||||
|
||||
$freshBooking = new Booking();
|
||||
|
||||
$workingDto = new BookingDto($travel, 1);
|
||||
$workingDto->participants = [$workingParticipant];
|
||||
$workingDto->booking = $freshBooking;
|
||||
|
||||
$baselineParticipant = new ParticipantDto();
|
||||
$baselineParticipant->index = 0;
|
||||
|
||||
$baselineDto = new BookingDto($travel, 1);
|
||||
$baselineDto->participants = [$baselineParticipant];
|
||||
|
||||
$processor = $this->createStub(BookingDataProcessor::class);
|
||||
$processor->method('createBookingDtoFromBooking')->willReturn($baselineDto);
|
||||
|
||||
$guard = new BookingEditSubmitGuard($processor, new ServiceAvailabilityCalculator());
|
||||
|
||||
$reverted = $guard->revertUnbookableServiceAdditions($workingDto, $freshBooking);
|
||||
|
||||
$this->assertSame(['Bus-Hinfahrt'], $reverted);
|
||||
$this->assertNull($workingParticipant->skiPass);
|
||||
}
|
||||
|
||||
public function testRevertUnbookableServiceAdditionsKeepsAServiceTheParticipantAlreadyHolds(): void
|
||||
{
|
||||
$onRequest = $this->createService(99);
|
||||
$onRequest->label = 'Bus-Hinfahrt';
|
||||
$onRequest->subType = Constants::TOKEN_SKI_PASS;
|
||||
$onRequest->status = Constants::STATUS_ON_REQUEST;
|
||||
|
||||
$travel = new Travel();
|
||||
$travel->additionalServices = [99 => $onRequest];
|
||||
|
||||
$held = clone $onRequest;
|
||||
$held->mapping = [0];
|
||||
|
||||
$freshBooking = new Booking();
|
||||
$freshBooking->additionalServices = [99 => $held];
|
||||
|
||||
$workingParticipant = new ParticipantDto();
|
||||
$workingParticipant->index = 0;
|
||||
$workingParticipant->skiPass = $onRequest;
|
||||
|
||||
$workingDto = new BookingDto($travel, 1);
|
||||
$workingDto->participants = [$workingParticipant];
|
||||
$workingDto->booking = $freshBooking;
|
||||
|
||||
$baselineParticipant = new ParticipantDto();
|
||||
$baselineParticipant->index = 0;
|
||||
$baselineParticipant->skiPass = $held;
|
||||
|
||||
$baselineDto = new BookingDto($travel, 1);
|
||||
$baselineDto->participants = [$baselineParticipant];
|
||||
|
||||
$processor = $this->createStub(BookingDataProcessor::class);
|
||||
$processor->method('createBookingDtoFromBooking')->willReturn($baselineDto);
|
||||
|
||||
$guard = new BookingEditSubmitGuard($processor, new ServiceAvailabilityCalculator());
|
||||
|
||||
$reverted = $guard->revertUnbookableServiceAdditions($workingDto, $freshBooking);
|
||||
|
||||
$this->assertSame([], $reverted);
|
||||
$this->assertSame($onRequest, $workingParticipant->skiPass);
|
||||
}
|
||||
|
||||
private function createService(int $id): Service
|
||||
{
|
||||
$service = new Service();
|
||||
|
||||
Reference in New Issue
Block a user