feat: inquiry bookings
This commit is contained in:
@@ -0,0 +1,164 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Tests\Service;
|
||||
|
||||
use App\BusProNet\Model\Room;
|
||||
use App\BusProNet\Model\Travel;
|
||||
use App\Exception\BookingNotPossibleException;
|
||||
use App\Exception\NoRoomsAvailableException;
|
||||
use App\Service\BookingPriceCalculatorService;
|
||||
use App\Service\BookingService;
|
||||
use App\Service\ParticipantEligibilityService;
|
||||
use App\Service\TravelDataService;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\HttpFoundation\Request;
|
||||
use Symfony\Component\HttpFoundation\Session\Session;
|
||||
use Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage;
|
||||
|
||||
class BookingServiceStatusTest extends TestCase
|
||||
{
|
||||
private BookingService $bookingService;
|
||||
private TravelDataService $travelDataService;
|
||||
|
||||
protected function setUp(): void
|
||||
{
|
||||
$this->travelDataService = $this->createMock(TravelDataService::class);
|
||||
$priceCalculator = $this->createMock(BookingPriceCalculatorService::class);
|
||||
$participantEligibility = $this->createMock(ParticipantEligibilityService::class);
|
||||
|
||||
$this->bookingService = new BookingService(
|
||||
$this->travelDataService,
|
||||
$priceCalculator,
|
||||
$participantEligibility
|
||||
);
|
||||
}
|
||||
|
||||
public function testStartFreshBookingWithFreiStatus(): void
|
||||
{
|
||||
$travel = $this->createTravelWithStatus('Frei', 5);
|
||||
|
||||
$this->travelDataService
|
||||
->method('getTravelData')
|
||||
->willReturn($travel);
|
||||
|
||||
$request = $this->createRequestWithSession();
|
||||
|
||||
$bookingDto = $this->bookingService->startFreshBooking($request, 123, 456);
|
||||
|
||||
$this->assertSame('F', $bookingDto->bookingStatus);
|
||||
$this->assertCount(1, $bookingDto->roomSelections);
|
||||
}
|
||||
|
||||
public function testStartFreshBookingWithFreiStatusAndNoRoomsThrowsException(): void
|
||||
{
|
||||
$travel = $this->createTravelWithStatus('Frei', 0);
|
||||
|
||||
$this->travelDataService
|
||||
->method('getTravelData')
|
||||
->willReturn($travel);
|
||||
|
||||
$request = $this->createRequestWithSession();
|
||||
|
||||
$this->expectException(NoRoomsAvailableException::class);
|
||||
|
||||
$this->bookingService->startFreshBooking($request, 123, 456);
|
||||
}
|
||||
|
||||
public function testStartFreshBookingWithAnfrageStatus(): void
|
||||
{
|
||||
$travel = $this->createTravelWithStatus('Anfrage', 5);
|
||||
|
||||
$this->travelDataService
|
||||
->method('getTravelData')
|
||||
->willReturn($travel);
|
||||
|
||||
$request = $this->createRequestWithSession();
|
||||
|
||||
$bookingDto = $this->bookingService->startFreshBooking($request, 123, 456);
|
||||
|
||||
$this->assertSame('A', $bookingDto->bookingStatus);
|
||||
$this->assertCount(1, $bookingDto->roomSelections);
|
||||
}
|
||||
|
||||
public function testStartFreshBookingWithAnfrageStatusAndNoRoomsAllowsBooking(): void
|
||||
{
|
||||
$travel = $this->createTravelWithStatus('Anfrage', 0);
|
||||
|
||||
$this->travelDataService
|
||||
->method('getTravelData')
|
||||
->willReturn($travel);
|
||||
|
||||
$request = $this->createRequestWithSession();
|
||||
|
||||
$bookingDto = $this->bookingService->startFreshBooking($request, 123, 456);
|
||||
|
||||
$this->assertSame('A', $bookingDto->bookingStatus);
|
||||
$this->assertCount(1, $bookingDto->roomSelections);
|
||||
}
|
||||
|
||||
public function testStartFreshBookingWithBuchungsstopThrowsException(): void
|
||||
{
|
||||
$travel = $this->createTravelWithStatus('Buchungsstop', 5);
|
||||
|
||||
$this->travelDataService
|
||||
->method('getTravelData')
|
||||
->willReturn($travel);
|
||||
|
||||
$request = $this->createRequestWithSession();
|
||||
|
||||
$this->expectException(BookingNotPossibleException::class);
|
||||
$this->expectExceptionMessage('Für diese Reise ist aktuell keine Buchung möglich');
|
||||
|
||||
$this->bookingService->startFreshBooking($request, 123, 456);
|
||||
}
|
||||
|
||||
public function testStartFreshBookingWithBuchungsstopAndNoRoomsThrowsException(): void
|
||||
{
|
||||
$travel = $this->createTravelWithStatus('Buchungsstop', 0);
|
||||
|
||||
$this->travelDataService
|
||||
->method('getTravelData')
|
||||
->willReturn($travel);
|
||||
|
||||
$request = $this->createRequestWithSession();
|
||||
|
||||
$this->expectException(BookingNotPossibleException::class);
|
||||
|
||||
$this->bookingService->startFreshBooking($request, 123, 456);
|
||||
}
|
||||
|
||||
private function createTravelWithStatus(string $status, int $availability): Travel
|
||||
{
|
||||
$travel = new Travel();
|
||||
$travel->id = 123;
|
||||
$travel->hotelId = 456;
|
||||
$travel->status = $status;
|
||||
$travel->dateFrom = new \DateTimeImmutable('2030-01-01');
|
||||
$travel->dateTo = new \DateTimeImmutable('2030-01-06');
|
||||
|
||||
$room = new Room();
|
||||
$room->id = 1;
|
||||
$room->label = 'Test Room';
|
||||
$room->price = 100.0;
|
||||
$room->available = $availability;
|
||||
$room->status = \App\BusProNet\Constants::STATUS_AVAILABLE;
|
||||
$room->minPax = 2;
|
||||
$room->category = 'A';
|
||||
$room->boardId = 1;
|
||||
|
||||
$travel->rooms = [1 => $room];
|
||||
|
||||
return $travel;
|
||||
}
|
||||
|
||||
private function createRequestWithSession(): Request
|
||||
{
|
||||
$session = new Session(new MockArraySessionStorage());
|
||||
$request = new Request();
|
||||
$request->setSession($session);
|
||||
|
||||
return $request;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user