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\Entity\Groups;
|
||||
use App\Entity\Groups\AccommodationBooking;
|
||||
use App\Enum\Groups\AccommodationBookingOrigin;
|
||||
use App\Enum\Groups\AccommodationBookingStatus;
|
||||
use App\Exception\ImplausibleBookingPriceException;
|
||||
use PHPUnit\Framework\Attributes\DataProvider;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
@@ -87,6 +88,36 @@ class AccommodationBookingTest extends TestCase
|
||||
}
|
||||
}
|
||||
|
||||
public function testAnImplausibleTotalIsRefusedRatherThanStored(): void
|
||||
{
|
||||
// The pax count and the nights are capped, so what gets here is a catalog price with a
|
||||
// digit too many. A stored total would end up on an offer; the INT column would answer
|
||||
// it with SQLSTATE 22003 and say nothing about the cause.
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setDateFrom(new \DateTimeImmutable('2026-09-23'));
|
||||
$booking->setDateTo(new \DateTimeImmutable('2026-09-25'));
|
||||
$booking->setPaxCount(40);
|
||||
|
||||
$this->expectException(ImplausibleBookingPriceException::class);
|
||||
|
||||
$booking->setPriceSnapshot(['total' => AccommodationBooking::MAX_TOTAL_PRICE + 1], AccommodationBooking::MAX_TOTAL_PRICE + 1, 'EUR', 1);
|
||||
}
|
||||
|
||||
public function testATotalAtTheCeilingIsStillStored(): void
|
||||
{
|
||||
$booking = new AccommodationBooking();
|
||||
$booking->setPriceSnapshot(['total' => AccommodationBooking::MAX_TOTAL_PRICE], AccommodationBooking::MAX_TOTAL_PRICE, 'EUR', 1);
|
||||
|
||||
self::assertSame(AccommodationBooking::MAX_TOTAL_PRICE, $booking->getTotalPrice());
|
||||
}
|
||||
|
||||
public function testTheCeilingLeavesTheIntColumnRoomToSpare(): void
|
||||
{
|
||||
// The ceiling exists to keep implausible prices out, not to use up the column: a total
|
||||
// that needs more room than this is a mistake, never a wider column.
|
||||
self::assertLessThan(2147483647, AccommodationBooking::MAX_TOTAL_PRICE);
|
||||
}
|
||||
|
||||
public function testTheLabelIsIndependentOfWhereTheBookingCameFrom(): void
|
||||
{
|
||||
// Origin answers "how did this come about" and is deliberately not the same
|
||||
|
||||
Reference in new issue
Block a user