fix: refuse implausible accommodation booking prices
This commit is contained in:
1 parent
773cd4f847
commit
56adf72d12
16 files changed
+628
-15
No files matched your search
@@ -7,6 +7,7 @@ namespace App\Tests\Controller\Admin\AccommodationBooking;
|
||||
use App\Controller\Admin\AccommodationBooking\CreateController;
|
||||
use App\Entity\Groups\AccommodationBooking;
|
||||
use App\Entity\User;
|
||||
use App\Exception\ImplausibleBookingPriceException;
|
||||
use App\Service\AccommodationBookingService;
|
||||
use Doctrine\ORM\EntityManagerInterface;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
@@ -32,6 +33,37 @@ class CreateControllerTest extends TestCase
|
||||
self::assertSame($user, $controller->capturedBooking?->getManagedBy());
|
||||
}
|
||||
|
||||
public function testAnImplausiblePriceComesBackAsAFormErrorWithoutSaving(): void
|
||||
{
|
||||
// Same as on the edit form: the fix is in the house's price rows, so the office is told
|
||||
// on the form it is standing in front of, and nothing is written.
|
||||
$bookingService = $this->createStub(AccommodationBookingService::class);
|
||||
$bookingService->method('refreshPriceSnapshot')
|
||||
->willThrowException(new ImplausibleBookingPriceException(AccommodationBooking::MAX_TOTAL_PRICE + 1, 40, 2));
|
||||
|
||||
$form = $this->createMock(FormInterface::class);
|
||||
$form->method('handleRequest')->willReturn($form);
|
||||
$form->method('isSubmitted')->willReturn(true);
|
||||
$form->method('isValid')->willReturn(true);
|
||||
$form->expects(self::once())->method('addError');
|
||||
|
||||
$entityManager = $this->createMock(EntityManagerInterface::class);
|
||||
$entityManager->expects(self::never())->method('persist');
|
||||
$entityManager->expects(self::never())->method('flush');
|
||||
|
||||
$controller = new TestableCreateController(
|
||||
$entityManager,
|
||||
$this->createStub(LoggerInterface::class),
|
||||
$bookingService,
|
||||
$form,
|
||||
new User('[email protected]'),
|
||||
);
|
||||
|
||||
$response = $controller->index(Request::create('/admin/accommodation-booking/create', 'POST'));
|
||||
|
||||
self::assertSame(Response::HTTP_OK, $response->getStatusCode(), 'the modal is re-rendered, not redirected');
|
||||
}
|
||||
|
||||
private function buildController(?UserInterface $user): TestableCreateController
|
||||
{
|
||||
$form = $this->createStub(FormInterface::class);
|
||||
|
||||
Reference in new issue
Block a user