feat: offer contact validation flow
This commit is contained in:
@@ -28,6 +28,7 @@ use Doctrine\ORM\EntityManagerInterface;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
class AccommodationBookingServiceTest extends TestCase
|
||||
{
|
||||
@@ -1010,6 +1011,90 @@ class AccommodationBookingServiceTest extends TestCase
|
||||
return $booking;
|
||||
}
|
||||
|
||||
public function testHasCompleteContactDataAcceptsAFullyFilledBooking(): void
|
||||
{
|
||||
$service = $this->createServiceWithAccommodation();
|
||||
|
||||
self::assertTrue($service->hasCompleteContactData($this->createBookingWithContactData()));
|
||||
}
|
||||
|
||||
/**
|
||||
* An offer the office saved with only the fields its own form requires.
|
||||
*/
|
||||
public function testHasCompleteContactDataRejectsWhatTheOfficeMayLeaveOut(): void
|
||||
{
|
||||
$service = $this->createServiceWithAccommodation();
|
||||
|
||||
$booking = $this->createBookingWithContactData();
|
||||
$booking->setPhone(null);
|
||||
|
||||
self::assertFalse($service->hasCompleteContactData($booking));
|
||||
}
|
||||
|
||||
public function testHasCompleteContactDataAppliesTheStep3Constraints(): void
|
||||
{
|
||||
$service = $this->createServiceWithAccommodation();
|
||||
|
||||
$booking = $this->createBookingWithContactData();
|
||||
$booking->setSalutation('Dr.');
|
||||
|
||||
self::assertFalse($service->hasCompleteContactData($booking));
|
||||
}
|
||||
|
||||
public function testApplyContactDataRoundTripsAndFlushes(): void
|
||||
{
|
||||
$entityManager = $this->createMock(EntityManagerInterface::class);
|
||||
$entityManager->expects(self::once())->method('flush');
|
||||
$service = $this->createServiceWithAccommodation(entityManager: $entityManager);
|
||||
|
||||
$dto = $service->contactDataFromBooking($this->createBookingWithContactData());
|
||||
$dto->phone = '0171 999999';
|
||||
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setRemarks('bleibt');
|
||||
$service->applyContactData($booking, $dto);
|
||||
|
||||
self::assertSame('Skiclub Nord', $booking->getGroupName());
|
||||
self::assertSame('Frau', $booking->getSalutation());
|
||||
self::assertSame('Erika', $booking->getFirstName());
|
||||
self::assertSame('Mustermann', $booking->getLastName());
|
||||
self::assertSame('[email protected]', $booking->getEmail());
|
||||
self::assertSame('0171 999999', $booking->getPhone());
|
||||
self::assertSame('Hauptstraße 1', $booking->getStreet());
|
||||
self::assertSame('12345', $booking->getZip());
|
||||
self::assertSame('Musterstadt', $booking->getCity());
|
||||
self::assertSame('bleibt', $booking->getRemarks(), 'remarks are not contact data');
|
||||
}
|
||||
|
||||
public function testCreateOfferContextCombinesCmsDataAndStoredBreakdown(): void
|
||||
{
|
||||
$booking = new AccommodationBooking();
|
||||
$accommodation = (new Accommodation())->setCalendarCode('HOTEL');
|
||||
|
||||
$breakdownCalculator = $this->createMock(AccommodationBookingBreakdownCalculator::class);
|
||||
$breakdownCalculator->method('compute')->with($booking)->willReturn(['total' => 1000]);
|
||||
$service = $this->createServiceWithAccommodation(breakdownCalculator: $breakdownCalculator);
|
||||
|
||||
$ctx = $service->createOfferContext($booking, $accommodation);
|
||||
|
||||
self::assertSame($accommodation, $ctx->accommodation);
|
||||
self::assertSame(['total' => 1000], $ctx->priceBreakdown);
|
||||
}
|
||||
|
||||
private function createBookingWithContactData(): AccommodationBooking
|
||||
{
|
||||
return (new AccommodationBooking())
|
||||
->setGroupName('Skiclub Nord')
|
||||
->setSalutation('Frau')
|
||||
->setFirstName('Erika')
|
||||
->setLastName('Mustermann')
|
||||
->setEmail('[email protected]')
|
||||
->setPhone('0171 123456')
|
||||
->setStreet('Hauptstraße 1')
|
||||
->setZip('12345')
|
||||
->setCity('Musterstadt');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AccommodationPrice[] $prices
|
||||
*/
|
||||
@@ -1051,6 +1136,7 @@ class AccommodationBookingServiceTest extends TestCase
|
||||
$linkSigner ?? $this->createStub(AccommodationBookingLinkSigner::class),
|
||||
$breakdownCalculator ?? $this->createStub(AccommodationBookingBreakdownCalculator::class),
|
||||
$pdfGenerator ?? $this->createStub(AccommodationBookingPdfGenerator::class),
|
||||
Validation::createValidatorBuilder()->enableAttributeMapping()->getValidator(),
|
||||
'[email protected]',
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user