Skip to content

Commit

Permalink
fix: Register TC consultant journey.
Browse files Browse the repository at this point in the history
  • Loading branch information
fibble committed Aug 28, 2024
1 parent 03e6c70 commit d685fd2
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 59 deletions.
2 changes: 1 addition & 1 deletion app/selfserve/module/Olcs/config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -1481,7 +1481,7 @@
'QaIrhpPermitApplicationViewGenerator' => QaService\ViewGenerator\IrhpPermitApplicationViewGenerator::class,
LicenceVehicleManagement::class => LicenceVehicleManagement::class,
\Olcs\Session\ConsultantRegistration::class => \Olcs\Session\ConsultantRegistration::class,
\Olcs\Controller\Mapper\CreateAccountFormatSaveData::class => \Olcs\Controller\Mapper\CreateAccountFormatSaveData::class,
\Olcs\Controller\Mapper\CreateAccountMapper::class => \Olcs\Controller\Mapper\CreateAccountMapper::class,

],
'abstract_factories' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
use Laminas\Http\Response;
use Laminas\View\Model\ViewModel;
use LmcRbacMvc\Service\AuthorizationService;
use Olcs\Controller\Mapper\CreateAccountFormatSaveData;
use Olcs\Controller\Mapper\CreateAccountMapper;
use Olcs\Form\Model\Form\ExistingOperatorLicence;
use Olcs\Form\Model\Form\OperatorRepresentation;
use Olcs\Form\Model\Form\RegisterConsultantAccount;
Expand All @@ -34,7 +34,7 @@ public function __construct(
protected UrlHelperService $urlHelper,
protected FlashMessengerHelperService $flashMessengerHelper,
protected ConsultantRegistration $consultantRegistrationSession,
protected CreateAccountFormatSaveData $formatSaveDataMapper
protected CreateAccountMapper $formatDataMapper
) {
parent::__construct($niTextTranslationUtil, $authService);
}
Expand All @@ -53,7 +53,7 @@ public function addAction()
return $this->redirectToHome();
}

$postData = $this->formatPostData($this->params()->fromPost());
$postData = $this->formatDataMapper->formatPostData($this->params()->fromPost());
$form->setData($postData);

if ($form->isValid()) {
Expand Down Expand Up @@ -84,7 +84,7 @@ public function operatorRepresentationAction()
return $this->redirectToHome();
}

$postData = $this->formatPostData($this->params()->fromPost());
$postData = $this->formatDataMapper->formatPostData($this->params()->fromPost());
$form->setData($postData);

if ($form->isValid()) {
Expand Down Expand Up @@ -116,7 +116,7 @@ public function registerForOperatorAction()
return $this->redirectToHome();
}

$postData = $this->formatPostData($this->params()->fromPost());
$postData = $this->formatDataMapper->formatPostData($this->params()->fromPost());
$form->setData($postData);

if ($form->isValid()) {
Expand Down Expand Up @@ -144,7 +144,7 @@ public function registerConsultantAccountAction()
return $this->redirectToHome();
}

$form->setData($this->formatPostData($this->params()->fromPost()));
$form->setData($this->formatDataMapper->formatPostData($this->params()->fromPost()));

if ($form->isValid()) {
$result = $this->registerConsultantAndOperator($form->getData());
Expand All @@ -168,8 +168,8 @@ public function registerConsultantAccountAction()
private function registerConsultantAndOperator($consultantFormData)
{
$operatorData = $this->consultantRegistrationSession->getOperatorDetails();
$formattedOperatorData = $this->formatSaveDataMapper->formatSaveData($operatorData);
$formattedConsultantData = $this->formatSaveDataMapper->formatSaveData($consultantFormData);
$formattedOperatorData = $this->formatDataMapper->formatSaveData($operatorData);
$formattedConsultantData = $this->formatDataMapper->formatSaveData($consultantFormData);

$response = $this->handleCommand(
RegisterConsultantAndOperator::create(
Expand Down Expand Up @@ -206,24 +206,6 @@ private function prepareView(string $template, array $variables = []): ViewModel
return $view;
}

/**
* A radio button is used and validated only if a checkbox is selected.
* As browsers by default do not post the value or default value of a radio
* button. We specify an empty input for this field.
*
* @param array $postData Data from posted form
*
* @return array
*/
private function formatPostData(array $postData)
{
if (empty($postData['fields']['businessType'])) {
$postData['fields']['businessType'] = null;
}

return $postData;
}

/**
* Redirects to home
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
use Common\Service\Script\ScriptFactory;
use Dvsa\Olcs\Utils\Translation\NiTextTranslation;
use Olcs\Controller\ConsultantRegistrationController;
use Olcs\Controller\Mapper\CreateAccountFormatSaveData;
use Olcs\Controller\Mapper\CreateAccountMapper;
use Olcs\Session\ConsultantRegistration;
use Psr\Container\ContainerInterface;
use Laminas\ServiceManager\Factory\FactoryInterface;
Expand All @@ -34,7 +34,7 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o
$urlHelper = $container->get(UrlHelperService::class);
$flashMessengerHelper = $container->get(FlashMessengerHelperService::class);
$consultantRegistrationSession = $container->get(ConsultantRegistration::class);
$formatSaveDataMapper = $container->get(CreateAccountFormatSaveData::class);
$formatDataMapper = $container->get(CreateAccountMapper::class);

return new ConsultantRegistrationController(
$niTextTranslationUtil,
Expand All @@ -45,7 +45,7 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o
$urlHelper,
$flashMessengerHelper,
$consultantRegistrationSession,
$formatSaveDataMapper
$formatDataMapper
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use Common\Service\Helper\UrlHelperService;
use Common\Service\Script\ScriptFactory;
use Dvsa\Olcs\Utils\Translation\NiTextTranslation;
use Olcs\Controller\Mapper\CreateAccountFormatSaveData;
use Olcs\Controller\Mapper\CreateAccountMapper;
use Olcs\Session\ConsultantRegistration;
use Psr\Container\ContainerInterface;
use Laminas\ServiceManager\Factory\FactoryInterface;
Expand All @@ -32,7 +32,7 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o
$translationHelper = $container->get(TranslationHelperService::class);
$urlHelper = $container->get(UrlHelperService::class);
$flashMessengerHelper = $container->get(FlashMessengerHelperService::class);
$formatSaveDataMapper = $container->get(CreateAccountFormatSaveData::class);
$formatDataMapper = $container->get(CreateAccountMapper::class);

return new UserRegistrationController(
$niTextTranslationUtil,
Expand All @@ -42,7 +42,7 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o
$translationHelper,
$urlHelper,
$flashMessengerHelper,
$formatSaveDataMapper
$formatDataMapper
);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace Olcs\Controller\Mapper;

class CreateAccountFormatSaveData
class CreateAccountMapper
{
/**
*
Expand All @@ -26,4 +26,22 @@ public function formatSaveData(array $data)

return $output;
}

/**
* A radio button is used and validated only if a checkbox is selected.
* As browsers by default do not post the value or default value of a radio
* button. We specify an empty input for this field.
*
* @param array $postData Data from posted form
*
* @return array
*/
public function formatPostData(array $postData)
{
if (empty($postData['fields']['businessType'])) {
$postData['fields']['businessType'] = null;
}

return $postData;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use Laminas\Form\Form;
use Laminas\View\Model\ViewModel;
use LmcRbacMvc\Service\AuthorizationService;
use Olcs\Controller\Mapper\CreateAccountFormatSaveData;
use Olcs\Controller\Mapper\CreateAccountMapper;

/**
* User Registration Controller
Expand All @@ -32,7 +32,7 @@ public function __construct(
protected TranslationHelperService $translationHelper,
protected UrlHelperService $urlHelper,
protected FlashMessengerHelperService $flashMessengerHelper,
protected CreateAccountFormatSaveData $formatSaveDataMapper
protected CreateAccountMapper $formatDataMapper
) {
parent::__construct($niTextTranslationUtil, $authService);
}
Expand Down Expand Up @@ -71,7 +71,7 @@ public function addAction()
return $this->redirectToHome();
}

$postData = $this->formatPostData(
$postData = $this->formatDataMapper->formatPostData(
$this->params()->fromPost()
);

Expand Down Expand Up @@ -298,7 +298,7 @@ private function createUserWithOrg($formData)
*/
private function createUser($formData)
{
$data = $this->formatSaveDataMapper->formatSaveData($formData);
$data = $this->formatDataMapper->formatSaveData($formData);

$response = $this->handleCommand(
RegisterDto::create($data)
Expand All @@ -322,24 +322,6 @@ private function createUser($formData)
return $this->generateContentForUserRegistration($formData, $errors);
}

/**
* A radio button is used and validated only if a checkbox is selected.
* As browsers by default do not post the value or default value of a radio
* button. We specify an empty input for this field.
*
* @param array $postData Data from posted form
*
* @return array
*/
private function formatPostData(array $postData)
{
if (empty($postData['fields']['businessType'])) {
$postData['fields']['businessType'] = null;
}

return $postData;
}

/**
* Redirects to home
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use Dvsa\Olcs\Utils\Translation\NiTextTranslation;
use Mockery as m;
use Mockery\Adapter\Phpunit\MockeryTestCase as TestCase;
use Olcs\Controller\Mapper\CreateAccountFormatSaveData;
use Olcs\Controller\Mapper\CreateAccountMapper;
use Olcs\Controller\UserRegistrationController as Sut;
use ReflectionClass;
use LmcRbacMvc\Service\AuthorizationService;
Expand Down Expand Up @@ -53,7 +53,7 @@ public function setUp(): void
$this->mockScriptFactory = m::mock(ScriptFactory::class)->makePartial();
$this->mockUrlHelper = m::mock(UrlHelperService::class)->makePartial();
$this->mockTranslationHelper = m::mock(TranslationHelperService::class)->makePartial();
$this->mockFormatSaveDataMapper = m::mock(CreateAccountFormatSaveData::class);
$this->mockFormatSaveDataMapper = m::mock(CreateAccountMapper::class)->makePartial();

$reflectionClass = new ReflectionClass(Sut::class);
$this->setMockedProperties($reflectionClass, 'niTextTranslationUtil', $this->mockniTextTranslationUtil);
Expand All @@ -63,7 +63,7 @@ public function setUp(): void
$this->setMockedProperties($reflectionClass, 'scriptFactory', $this->mockScriptFactory);
$this->setMockedProperties($reflectionClass, 'urlHelper', $this->mockUrlHelper);
$this->setMockedProperties($reflectionClass, 'translationHelper', $this->mockTranslationHelper);
$this->setMockedProperties($reflectionClass, 'formatSaveDataMapper', $this->mockFormatSaveDataMapper);
$this->setMockedProperties($reflectionClass, 'formatDataMapper', $this->mockFormatSaveDataMapper);
}

/**
Expand Down Expand Up @@ -202,6 +202,7 @@ public function testAddActionForPostWithOrg(): void
$this->sut->shouldReceive('placeholder')->andReturn($placeholder);

$this->mockFormatSaveDataMapper->shouldReceive('formatSaveData')->once()->with($postData)->andReturn($postData);
$this->mockFormatSaveDataMapper->shouldReceive('formatPostData')->once()->with($postData)->andReturn($postData);

$view = $this->sut->addAction();

Expand Down Expand Up @@ -279,6 +280,7 @@ public function testAddActionForPostWithOrgError(): void
->once();

$this->mockFormatSaveDataMapper->shouldReceive('formatSaveData')->once()->with($postData)->andReturn($postData);
$this->mockFormatSaveDataMapper->shouldReceive('formatPostData')->once()->with($postData)->andReturn($postData);

$view = $this->sut->addAction();

Expand Down Expand Up @@ -363,6 +365,8 @@ public function testAddActionForPostWithLic(): void
->once();
$this->sut->shouldReceive('placeholder')->andReturn($placeholder);

$this->mockFormatSaveDataMapper->shouldReceive('formatPostData')->once()->with($postData)->andReturn($formattedPostData);

$view = $this->sut->addAction();

$this->assertInstanceOf(\Laminas\View\Model\ViewModel::class, $view);
Expand Down Expand Up @@ -448,6 +452,8 @@ public function testAddActionForPostWithLicError(): void
->with('user-registration')
->once();

$this->mockFormatSaveDataMapper->shouldReceive('formatPostData')->once()->with($postData)->andReturn($formattedPostData);

$view = $this->sut->addAction();

$this->assertInstanceOf(\Laminas\View\Model\ViewModel::class, $view);
Expand Down Expand Up @@ -515,6 +521,7 @@ public function testAddActionForPostWithLicConfirmed(): void
$this->sut->shouldReceive('placeholder')->andReturn($placeholder);

$this->mockFormatSaveDataMapper->shouldReceive('formatSaveData')->once()->with($formattedPostData)->andReturn($formattedPostData);
$this->mockFormatSaveDataMapper->shouldReceive('formatPostData')->once()->with($postData)->andReturn($formattedPostData);

$view = $this->sut->addAction();

Expand Down Expand Up @@ -601,6 +608,8 @@ public function testAddActionForPostWithLicConfirmedError(): void
->once();

$this->mockFormatSaveDataMapper->shouldReceive('formatSaveData')->once()->with($formattedPostData)->andReturn($formattedPostData);
$this->mockFormatSaveDataMapper->shouldReceive('formatPostData')->once()->with($postData)->andReturn($formattedPostData);


$view = $this->sut->addAction();

Expand Down

0 comments on commit d685fd2

Please sign in to comment.