feat: voucher purchase flow
This commit is contained in:
1 parent
a628e96d06
commit
f3dd122678
70 files changed
+3672
-122
No files matched your search
@@ -7,8 +7,12 @@ namespace App\Tests\Controller;
|
||||
use App\BusProNet\Model\Travel;
|
||||
use App\Controller\SecurityController;
|
||||
use App\Form\Model\BookingDto;
|
||||
use App\Form\Model\VoucherPurchaseDto;
|
||||
use App\Model\PurchaseFlow;
|
||||
use App\Service\BookingSessionManager;
|
||||
use App\Service\BookingSummaryAssembler;
|
||||
use App\Service\PurchaseFlowResolver;
|
||||
use App\Service\VoucherPurchaseSessionManager;
|
||||
use League\Bundle\OAuth2ServerBundle\Manager\ClientManagerInterface;
|
||||
use League\Bundle\OAuth2ServerBundle\Model\Client;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
@@ -98,6 +102,7 @@ class SecurityControllerTest extends TestCase
|
||||
->willReturn(new Client('EPHub', 'abc123', null));
|
||||
|
||||
$session = $this->createSession(self::AUTHORIZE_PATH);
|
||||
$session->set(BookingSessionManager::BOOKING_CREATE_KEY, $this->createBookingDto());
|
||||
$response = $controller->login(...$this->arguments($controller, self::AUTHORIZE_PATH, $session));
|
||||
|
||||
self::assertSame(200, $response->getStatusCode());
|
||||
@@ -111,15 +116,65 @@ class SecurityControllerTest extends TestCase
|
||||
$controller->clientManager->expects(self::never())->method('find');
|
||||
|
||||
$session = $this->createSession(null);
|
||||
$session->set(BookingSessionManager::BOOKING_CREATE_KEY, $this->createBookingDto());
|
||||
$response = $controller->login(...$this->arguments($controller, null, $session));
|
||||
|
||||
self::assertSame(200, $response->getStatusCode());
|
||||
self::assertSame('booking/create/authenticate.html.twig', $controller->renderedView);
|
||||
self::assertSame('/booking/create/step-1', $session->get('_security.main.target_path'));
|
||||
self::assertSame('/app_booking_create_step_1', $session->get('_security.main.target_path'));
|
||||
}
|
||||
|
||||
public function testAPendingVoucherPurchaseRendersTheVoucherLoginAndContinuesWithItsFirstStep(): void
|
||||
{
|
||||
$controller = $this->createController();
|
||||
$controller->clientManager->expects(self::never())->method('find');
|
||||
|
||||
$session = $this->createSession(null);
|
||||
$session->set(VoucherPurchaseSessionManager::SESSION_KEY, new VoucherPurchaseDto());
|
||||
$response = $controller->login(...$this->arguments($controller, null, $session));
|
||||
|
||||
self::assertSame(200, $response->getStatusCode());
|
||||
self::assertSame('voucher/authenticate.html.twig', $controller->renderedView);
|
||||
self::assertSame('/app_voucher_step_1', $session->get('_security.main.target_path'));
|
||||
self::assertNull($controller->renderedParameters['travel_title']);
|
||||
}
|
||||
|
||||
public function testAPendingAuthorizationWinsOverAPendingVoucherPurchase(): void
|
||||
{
|
||||
$controller = $this->createController();
|
||||
$controller->clientManager->expects(self::once())->method('find')->willReturn(new Client('EPHub', 'abc123', null));
|
||||
|
||||
$session = $this->createSession(self::AUTHORIZE_PATH);
|
||||
$session->set(VoucherPurchaseSessionManager::SESSION_KEY, new VoucherPurchaseDto());
|
||||
$controller->login(...$this->arguments($controller, self::AUTHORIZE_PATH, $session));
|
||||
|
||||
self::assertSame('security/login_oauth2.html.twig', $controller->renderedView);
|
||||
self::assertSame(self::AUTHORIZE_PATH, $session->get('_security.main.target_path'));
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{AuthenticationUtils, Request, BookingSessionManager, BookingSummaryAssembler, ClientManagerInterface}
|
||||
* A booking and a voucher purchase can both be pending, e.g. from two tabs. The one the visitor
|
||||
* started last is the one they are signing in for.
|
||||
*/
|
||||
public function testTheLastStartedOfTwoPendingFlowsWins(): void
|
||||
{
|
||||
foreach ([PurchaseFlow::Voucher, PurchaseFlow::Booking] as $lastStarted) {
|
||||
$controller = $this->createController(bookingDto: $this->createBookingDto());
|
||||
$controller->clientManager->expects(self::never())->method('find');
|
||||
|
||||
$session = $this->createSession(null);
|
||||
$session->set(BookingSessionManager::BOOKING_CREATE_KEY, $this->createBookingDto());
|
||||
$session->set(VoucherPurchaseSessionManager::SESSION_KEY, new VoucherPurchaseDto());
|
||||
$session->set(PurchaseFlowResolver::LAST_STARTED_KEY, $lastStarted->value);
|
||||
$controller->login(...$this->arguments($controller, null, $session));
|
||||
|
||||
self::assertSame($lastStarted->authenticateTemplate(), $controller->renderedView);
|
||||
self::assertSame('/'.$lastStarted->firstStepRoute(), $session->get('_security.main.target_path'));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{AuthenticationUtils, Request, BookingSessionManager, BookingSummaryAssembler, ClientManagerInterface, PurchaseFlowResolver}
|
||||
*/
|
||||
private function arguments(TestableSecurityController $controller, ?string $targetPath, ?Session $session = null): array
|
||||
{
|
||||
@@ -132,6 +187,7 @@ class SecurityControllerTest extends TestCase
|
||||
$controller->bookingSessionManager,
|
||||
$controller->summaryAssembler,
|
||||
$controller->clientManager,
|
||||
new PurchaseFlowResolver(),
|
||||
];
|
||||
}
|
||||
|
||||
@@ -203,6 +259,6 @@ final class TestableSecurityController extends SecurityController
|
||||
|
||||
protected function generateUrl(string $route, array $parameters = [], int $referenceType = UrlGeneratorInterface::ABSOLUTE_PATH): string
|
||||
{
|
||||
return '/booking/create/step-1';
|
||||
return '/'.$route;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user