wip: group inquiries and booking
This commit is contained in:
1 parent
225ed518e3
commit
1e59d38eb4
33 files changed
+644
-95
No files matched your search
@@ -79,7 +79,7 @@ class Step2ControllerTest extends TestCase
|
||||
$bookingService
|
||||
->expects(self::once())
|
||||
->method('computeInquiryStatus')
|
||||
->with(self::callback(static fn(AccommodationBookingDto $submittedDto): bool => 3 === $submittedDto->paxCount), [])
|
||||
->with(self::callback(static fn (AccommodationBookingDto $submittedDto): bool => 3 === $submittedDto->paxCount), [])
|
||||
->willReturn(new InquiryStatus(true, ['Mindestaufenthalt: 5 Nächte (gebucht: 4)']));
|
||||
|
||||
$controller = new TestableAccommodationStep2Controller(
|
||||
|
||||
@@ -51,7 +51,7 @@ class AccommodationBookingControllerTest extends TestCase
|
||||
$booking->setBoardServiceLabel('Halbpension');
|
||||
$booking->setBoardServicePrice(1500);
|
||||
$booking->addAdditionalServiceSnapshot('Bettwäsche', 500, 'flat', 3);
|
||||
$booking->setDiscount(1000);
|
||||
$booking->setDiscount(10);
|
||||
$booking->setIsInquiry(false);
|
||||
$booking->setAcceptedAt(new \DateTimeImmutable('2026-07-15T10:00:00+00:00'));
|
||||
|
||||
@@ -63,6 +63,7 @@ class AccommodationBookingControllerTest extends TestCase
|
||||
->willReturn($booking);
|
||||
|
||||
$breakdown = ['total' => 12345, 'currency' => 'EUR'];
|
||||
$booking->setPriceSnapshot($breakdown, 11111, 'EUR', 1);
|
||||
$breakdownCalculator = $this->createMock(AccommodationBookingBreakdownCalculator::class);
|
||||
$breakdownCalculator
|
||||
->expects(self::once())
|
||||
@@ -116,7 +117,10 @@ class AccommodationBookingControllerTest extends TestCase
|
||||
'type' => 'flat',
|
||||
],
|
||||
],
|
||||
'discount' => 1000,
|
||||
'discount' => 10,
|
||||
'totalPrice' => 11111,
|
||||
'pricingCurrency' => 'EUR',
|
||||
'pricingVersion' => 1,
|
||||
'priceBreakdown' => $breakdown,
|
||||
], $payload);
|
||||
|
||||
|
||||
@@ -57,18 +57,54 @@ class OfferControllerTest extends TestCase
|
||||
$bookingService = $this->createMock(AccommodationBookingService::class);
|
||||
$bookingService->expects(self::once())->method('acceptBooking')->with($booking);
|
||||
|
||||
$controller = new OfferController(
|
||||
$controller = new TestableOfferController(
|
||||
$bookingRepository,
|
||||
$linkSigner,
|
||||
$this->createMock(AccommodationBookingBreakdownCalculator::class),
|
||||
$bookingService,
|
||||
);
|
||||
|
||||
$request = Request::create('/groups/booking/offer/'.$booking->getUuid().'?t=123&_hash=abc', 'POST');
|
||||
$request = Request::create(
|
||||
'/groups/booking/offer/'.$booking->getUuid().'?t=123&_hash=abc',
|
||||
'POST',
|
||||
['_token' => 'valid-token'],
|
||||
);
|
||||
$response = $controller->index($booking->getUuid(), $request);
|
||||
|
||||
self::assertSame(Response::HTTP_FOUND, $response->getStatusCode());
|
||||
self::assertSame($request->getUri(), $response->headers->get('Location'));
|
||||
self::assertSame('accept_accommodation_offer_'.$booking->getUuid(), $controller->csrfTokenId);
|
||||
self::assertSame('valid-token', $controller->csrfToken);
|
||||
}
|
||||
|
||||
public function testPostRejectsInvalidCsrfToken(): void
|
||||
{
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setIsInquiry(true);
|
||||
|
||||
$bookingRepository = $this->createMock(AccommodationBookingRepository::class);
|
||||
$bookingRepository->method('findOneBy')->willReturn($booking);
|
||||
|
||||
$linkSigner = $this->createMock(AccommodationBookingLinkSigner::class);
|
||||
$linkSigner->method('isValidLinkRequest')->willReturn(true);
|
||||
|
||||
$bookingService = $this->createMock(AccommodationBookingService::class);
|
||||
$bookingService->expects(self::never())->method('acceptBooking');
|
||||
|
||||
$controller = new TestableOfferController(
|
||||
$bookingRepository,
|
||||
$linkSigner,
|
||||
$this->createMock(AccommodationBookingBreakdownCalculator::class),
|
||||
$bookingService,
|
||||
);
|
||||
$controller->csrfValid = false;
|
||||
|
||||
$this->expectException(\Symfony\Component\Security\Core\Exception\AccessDeniedException::class);
|
||||
|
||||
$controller->index(
|
||||
$booking->getUuid(),
|
||||
Request::create('/groups/booking/offer/'.$booking->getUuid(), 'POST', ['_token' => 'invalid']),
|
||||
);
|
||||
}
|
||||
|
||||
public function testGetRendersConfirmationWithoutAcceptFormForBooking(): void
|
||||
@@ -146,11 +182,22 @@ class OfferControllerTest extends TestCase
|
||||
|
||||
final class TestableOfferController extends OfferController
|
||||
{
|
||||
public bool $csrfValid = true;
|
||||
public ?string $csrfTokenId = null;
|
||||
public ?string $csrfToken = null;
|
||||
public ?string $renderedView = null;
|
||||
|
||||
/** @var array<string, mixed> */
|
||||
public array $renderedParameters = [];
|
||||
|
||||
protected function isCsrfTokenValid(string $id, ?string $token): bool
|
||||
{
|
||||
$this->csrfTokenId = $id;
|
||||
$this->csrfToken = $token;
|
||||
|
||||
return $this->csrfValid;
|
||||
}
|
||||
|
||||
protected function render(string $view, array $parameters = [], ?Response $response = null): Response
|
||||
{
|
||||
$this->renderedView = $view;
|
||||
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Model;
|
||||
|
||||
use App\Model\ContingentCalendarQuery;
|
||||
use App\Model\ContingentPricesQuery;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\Validator\Validation;
|
||||
|
||||
class ContingentQueryTest extends TestCase
|
||||
{
|
||||
public function testCalendarQueryAcceptsValidRange(): void
|
||||
{
|
||||
$query = new ContingentCalendarQuery('HOTEL_1', '2026-01-01', '2026-12-31');
|
||||
|
||||
self::assertCount(0, $this->validator()->validate($query));
|
||||
self::assertSame('2026-01-01', $query->dateFromDate()->format('Y-m-d'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @dataProvider invalidCalendarQueries
|
||||
*/
|
||||
public function testCalendarQueryRejectsInvalidInput(ContingentCalendarQuery $query): void
|
||||
{
|
||||
self::assertGreaterThan(0, $this->validator()->validate($query)->count());
|
||||
}
|
||||
|
||||
public function invalidCalendarQueries(): iterable
|
||||
{
|
||||
yield 'normalized invalid date' => [new ContingentCalendarQuery('HOTEL', '2026-02-31', '2026-03-01')];
|
||||
yield 'reversed range' => [new ContingentCalendarQuery('HOTEL', '2026-03-02', '2026-03-01')];
|
||||
yield 'range over 366 days' => [new ContingentCalendarQuery('HOTEL', '2026-01-01', '2027-01-03')];
|
||||
yield 'invalid hotel code' => [new ContingentCalendarQuery('HOTEL CODE', '2026-01-01', '2026-01-02')];
|
||||
}
|
||||
|
||||
public function testPricesQueryRequiresFourDigitYear(): void
|
||||
{
|
||||
self::assertCount(0, $this->validator()->validate(new ContingentPricesQuery('HOTEL', 2026)));
|
||||
self::assertGreaterThan(0, $this->validator()->validate(new ContingentPricesQuery('HOTEL', 26))->count());
|
||||
}
|
||||
|
||||
private function validator(): \Symfony\Component\Validator\Validator\ValidatorInterface
|
||||
{
|
||||
return Validation::createValidatorBuilder()
|
||||
->enableAttributeMapping()
|
||||
->getValidator();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,39 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Service;
|
||||
|
||||
use App\Entity\Groups\AccommodationBooking;
|
||||
use App\Repository\Groups\AccommodationPriceRepository;
|
||||
use App\Service\AccommodationBookingBreakdownCalculator;
|
||||
use App\Service\GroupsPriceCalculator;
|
||||
use App\Service\PriceTimelineBuilder;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class AccommodationBookingBreakdownCalculatorTest extends TestCase
|
||||
{
|
||||
public function testComputeReturnsStoredSnapshotWithoutLoadingCurrentPrices(): void
|
||||
{
|
||||
$snapshot = ['total' => 12345, 'currency' => 'EUR'];
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setPriceSnapshot($snapshot, 12345, 'EUR', 1);
|
||||
|
||||
$priceRepository = $this->createMock(AccommodationPriceRepository::class);
|
||||
$priceRepository->expects(self::never())->method('findByHotelCodeAndDateRange');
|
||||
|
||||
$calculator = new AccommodationBookingBreakdownCalculator(
|
||||
new GroupsPriceCalculator(new PriceTimelineBuilder(), [
|
||||
'runningCostsEur' => 0,
|
||||
'runningCostsChf' => 0,
|
||||
'undersubscription30Eur' => 0,
|
||||
'undersubscription30Chf' => 0,
|
||||
'undersubscription40Eur' => 0,
|
||||
'undersubscription40Chf' => 0,
|
||||
]),
|
||||
$priceRepository,
|
||||
);
|
||||
|
||||
self::assertSame($snapshot, $calculator->compute($booking));
|
||||
}
|
||||
}
|
||||
@@ -175,7 +175,7 @@ class AccommodationBookingServiceTest extends TestCase
|
||||
$service->sendCustomerConfirmationEmail($booking);
|
||||
}
|
||||
|
||||
public function testRegenerateAccessLinkAndNotifyCustomerAlwaysOverwritesAndSends(): void
|
||||
public function testRegenerateAccessLinkOverwritesAccessLinkIssuedAt(): void
|
||||
{
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setEmail('[email protected]');
|
||||
@@ -190,7 +190,7 @@ class AccommodationBookingServiceTest extends TestCase
|
||||
$breakdownCalculator->method('compute')->willReturn(null);
|
||||
|
||||
$mailer = $this->createMock(Mailer::class);
|
||||
$mailer->expects(self::once())->method('createAndSendEmail');
|
||||
$mailer->expects(self::never())->method('createAndSendEmail');
|
||||
|
||||
$service = $this->createServiceWithAccommodation(
|
||||
entityManager: $entityManager,
|
||||
@@ -198,7 +198,7 @@ class AccommodationBookingServiceTest extends TestCase
|
||||
breakdownCalculator: $breakdownCalculator,
|
||||
);
|
||||
|
||||
$service->regenerateAccessLinkAndNotifyCustomer($booking);
|
||||
$service->regenerateAccessLink($booking);
|
||||
|
||||
self::assertNotSame($previousIssuedAt, $booking->getAccessLinkIssuedAt());
|
||||
}
|
||||
@@ -234,6 +234,27 @@ class AccommodationBookingServiceTest extends TestCase
|
||||
self::assertNull($booking->getAcceptedAt());
|
||||
}
|
||||
|
||||
public function testRefreshPriceSnapshotStoresDiscountedFinalTotal(): void
|
||||
{
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setDiscount(10);
|
||||
|
||||
$breakdownCalculator = $this->createMock(AccommodationBookingBreakdownCalculator::class);
|
||||
$breakdownCalculator
|
||||
->expects(self::once())
|
||||
->method('computeCurrent')
|
||||
->with($booking)
|
||||
->willReturn(['total' => 12345, 'currency' => 'CHF']);
|
||||
|
||||
$service = $this->createServiceWithAccommodation(breakdownCalculator: $breakdownCalculator);
|
||||
$service->refreshPriceSnapshot($booking);
|
||||
|
||||
self::assertSame(['total' => 12345, 'currency' => 'CHF'], $booking->getPriceBreakdown());
|
||||
self::assertSame(11110, $booking->getTotalPrice());
|
||||
self::assertSame('CHF', $booking->getPricingCurrency());
|
||||
self::assertSame(1, $booking->getPricingVersion());
|
||||
}
|
||||
|
||||
/**
|
||||
* @param AccommodationPrice[] $prices
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user