feat: pre-flight check of agency bookings
addresses #869bqxr4q
This commit is contained in:
@@ -4,14 +4,12 @@ declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Service;
|
||||
|
||||
use App\BusProNet\Model\BaseData;
|
||||
use App\BusProNet\Model\Booking;
|
||||
use App\BusProNet\Model\MutableData;
|
||||
use App\BusProNet\Model\Travel;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Model\BookingEditContext;
|
||||
use App\Form\Model\BookingMutabilityDto;
|
||||
use App\Form\Model\BookingSummaryDto;
|
||||
use App\Form\Model\ParticipantCardDataDto;
|
||||
use App\Form\Model\ParticipantCardPriceDto;
|
||||
use App\Service\BookingEditContextFactory;
|
||||
use App\Service\BookingSummaryAssembler;
|
||||
use App\Service\ParticipantCardAssembler;
|
||||
@@ -20,151 +18,61 @@ use PHPUnit\Framework\TestCase;
|
||||
|
||||
class BookingEditContextFactoryTest extends TestCase
|
||||
{
|
||||
public function testPrepareBookingDtoRefreshesTravelAvailability(): void
|
||||
public function testCreateOverviewContextKeepsCardsNeutralAndTracksMissingValueLabels(): void
|
||||
{
|
||||
$travel = new Travel();
|
||||
$travel->dateFrom = new \DateTimeImmutable('2030-01-01');
|
||||
$travel->dateTo = new \DateTimeImmutable('2030-01-06');
|
||||
$bookingDto = new BookingDto($travel, 157047);
|
||||
$travel->id = 123;
|
||||
|
||||
$travelDataService = $this->createMock(TravelDataProvider::class);
|
||||
$travelDataService->expects($this->once())
|
||||
->method('enrichWithFreshAvailabilities')
|
||||
->with($travel);
|
||||
|
||||
$service = new BookingEditContextFactory(
|
||||
$this->createMock(ParticipantCardAssembler::class),
|
||||
$this->createMock(BookingSummaryAssembler::class),
|
||||
$travelDataService,
|
||||
);
|
||||
|
||||
$service->prepareBookingDto($bookingDto);
|
||||
}
|
||||
|
||||
public function testCreateBuildsEditContext(): void
|
||||
{
|
||||
$travel = new Travel();
|
||||
$travel->dateFrom = new \DateTimeImmutable('2030-01-01');
|
||||
$travel->dateTo = new \DateTimeImmutable('2030-01-06');
|
||||
|
||||
$bookingDto = new BookingDto($travel, 157047);
|
||||
$bookingDto->booking = new Booking();
|
||||
$bookingDto = new BookingDto($travel, 1);
|
||||
$bookingDto->participants = [
|
||||
new \App\Form\Model\ParticipantDto(),
|
||||
new \App\Form\Model\ParticipantDto(),
|
||||
];
|
||||
|
||||
$bookingData = new Booking();
|
||||
$bookingData->dateId = 1234;
|
||||
$bookingData->dateId = 123;
|
||||
|
||||
$mutableData = new BaseData([
|
||||
MutableData::CATEGORY_ADDITIONAL_SERVICES => new MutableData(MutableData::CATEGORY_ADDITIONAL_SERVICES, true, new \DateTimeImmutable('2030-01-02')),
|
||||
]);
|
||||
$summaryData = $this->createMock(BookingSummaryDto::class);
|
||||
|
||||
$summaryDataService = $this->createMock(BookingSummaryAssembler::class);
|
||||
$summaryDataService->expects($this->once())
|
||||
->method('getSummaryData')
|
||||
->with($bookingDto)
|
||||
->willReturn($summaryData);
|
||||
|
||||
$travelDataService = $this->createMock(TravelDataProvider::class);
|
||||
$travelDataService->expects($this->once())
|
||||
->method('getMutabilityData')
|
||||
->with(1234)
|
||||
->willReturn($mutableData);
|
||||
|
||||
$service = new BookingEditContextFactory(
|
||||
$this->createMock(ParticipantCardAssembler::class),
|
||||
$summaryDataService,
|
||||
$travelDataService,
|
||||
);
|
||||
|
||||
$context = $service->createParticipantContext($bookingDto, $bookingData);
|
||||
|
||||
$this->assertInstanceOf(BookingEditContext::class, $context);
|
||||
$this->assertSame($bookingDto, $context->bookingDto);
|
||||
$this->assertSame($bookingData, $context->bookingData);
|
||||
$this->assertInstanceOf(BookingMutabilityDto::class, $context->mutableData);
|
||||
$this->assertSame($mutableData->getItemByKey(MutableData::CATEGORY_ADDITIONAL_SERVICES), $context->mutableData->additionalServices);
|
||||
$this->assertNull($context->mutableData->transportation);
|
||||
$this->assertSame($summaryData, $context->summaryData);
|
||||
}
|
||||
|
||||
public function testCreateParticipantContextWithoutBookingDataFallsBackToSummaryOnly(): void
|
||||
{
|
||||
$travel = new Travel();
|
||||
$travel->dateFrom = new \DateTimeImmutable('2030-01-01');
|
||||
$travel->dateTo = new \DateTimeImmutable('2030-01-06');
|
||||
|
||||
$bookingDto = new BookingDto($travel, 157047);
|
||||
$summaryData = $this->createMock(BookingSummaryDto::class);
|
||||
|
||||
$summaryDataService = $this->createMock(BookingSummaryAssembler::class);
|
||||
$summaryDataService->expects($this->once())
|
||||
->method('getSummaryData')
|
||||
->with($bookingDto)
|
||||
->willReturn($summaryData);
|
||||
|
||||
$travelDataService = $this->createMock(TravelDataProvider::class);
|
||||
$travelDataService->expects($this->never())
|
||||
->method('getMutabilityData');
|
||||
|
||||
$service = new BookingEditContextFactory(
|
||||
$this->createMock(ParticipantCardAssembler::class),
|
||||
$summaryDataService,
|
||||
$travelDataService,
|
||||
);
|
||||
|
||||
$context = $service->createParticipantContext($bookingDto, null);
|
||||
|
||||
$this->assertInstanceOf(BookingEditContext::class, $context);
|
||||
$this->assertSame($bookingDto, $context->bookingDto);
|
||||
$this->assertNull($context->bookingData);
|
||||
$this->assertNull($context->mutableData);
|
||||
$this->assertSame($summaryData, $context->summaryData);
|
||||
}
|
||||
|
||||
public function testCreateOverviewContextBuildsEditOverviewPayload(): void
|
||||
{
|
||||
$travel = new Travel();
|
||||
$travel->dateFrom = new \DateTimeImmutable('2030-01-01');
|
||||
$travel->dateTo = new \DateTimeImmutable('2030-01-06');
|
||||
|
||||
$bookingDto = new BookingDto($travel, 157047);
|
||||
$bookingData = new Booking();
|
||||
$bookingData->dateId = 1234;
|
||||
|
||||
$mutableData = new BaseData([]);
|
||||
$summaryData = $this->createMock(BookingSummaryDto::class);
|
||||
$cardsData = [];
|
||||
|
||||
$participantCardDataService = $this->createMock(ParticipantCardAssembler::class);
|
||||
$participantCardDataService->expects($this->once())
|
||||
$participantCardAssembler = $this->createMock(ParticipantCardAssembler::class);
|
||||
$participantCardAssembler->expects($this->once())
|
||||
->method('getAllCardsDataWithValidation')
|
||||
->with($bookingDto)
|
||||
->willReturn($cardsData);
|
||||
->willReturn([
|
||||
0 => new ParticipantCardDataDto('One', '[email protected]', 'Room A', new ParticipantCardPriceDto(10.0, false), false, true),
|
||||
1 => new ParticipantCardDataDto('Two', '[email protected]', 'Room B', new ParticipantCardPriceDto(20.0, false), false, true),
|
||||
]);
|
||||
|
||||
$summaryDataService = $this->createMock(BookingSummaryAssembler::class);
|
||||
$summaryDataService->expects($this->once())
|
||||
$summaryAssembler = $this->createMock(BookingSummaryAssembler::class);
|
||||
$summaryAssembler->expects($this->once())
|
||||
->method('getSummaryData')
|
||||
->with($bookingDto)
|
||||
->willReturn($summaryData);
|
||||
|
||||
$travelDataService = $this->createMock(TravelDataProvider::class);
|
||||
$travelDataService->expects($this->once())
|
||||
$travelDataProvider = $this->createMock(TravelDataProvider::class);
|
||||
$travelDataProvider->expects($this->once())
|
||||
->method('getMutabilityData')
|
||||
->with(1234)
|
||||
->willReturn($mutableData);
|
||||
->with(123)
|
||||
->willReturn(null);
|
||||
|
||||
$service = new BookingEditContextFactory(
|
||||
$participantCardDataService,
|
||||
$summaryDataService,
|
||||
$travelDataService,
|
||||
$factory = new BookingEditContextFactory(
|
||||
$participantCardAssembler,
|
||||
$summaryAssembler,
|
||||
$travelDataProvider,
|
||||
);
|
||||
|
||||
$context = $service->createOverviewContext($bookingDto, $bookingData, true, false, true);
|
||||
$context = $factory->createOverviewContext(
|
||||
$bookingDto,
|
||||
$bookingData,
|
||||
false,
|
||||
false,
|
||||
false,
|
||||
[1 => ['E-Mail', 'Straße']],
|
||||
);
|
||||
|
||||
$this->assertInstanceOf(BookingEditContext::class, $context);
|
||||
$this->assertSame($cardsData, $context->cardsData);
|
||||
$this->assertTrue($context->isDirty);
|
||||
$this->assertFalse($context->isSubmitted);
|
||||
$this->assertTrue($context->hasValidationErrors);
|
||||
$this->assertTrue($context->cardsData[0]->isValid);
|
||||
$this->assertTrue($context->cardsData[1]->isValid);
|
||||
$this->assertSame([], $context->cardsData[1]->errorMessages);
|
||||
$this->assertSame([1 => ['E-Mail', 'Straße']], $context->missingValueLabelsByParticipantIndex);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user