Skip to content

Commit

Permalink
feat: VOL-5239 create transport consultant reg journey
Browse files Browse the repository at this point in the history
  • Loading branch information
ilindsay authored and fibble committed Aug 23, 2024
1 parent 64c5c3c commit 1d6e983
Show file tree
Hide file tree
Showing 23 changed files with 945 additions and 36 deletions.
1 change: 1 addition & 0 deletions app/api/module/Api/config/command-map.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@
TransferCommand\User\UpdatePartner::class => CommandHandler\User\UpdatePartner::class,
TransferCommand\User\DeletePartner::class => CommandHandler\User\DeletePartner::class,
TransferCommand\User\UpdateUserLastLoginAt::class => CommandHandler\User\UpdateUserLastLoginAt::class,
TransferCommand\User\RegisterConsultantAndOperator::class => CommandHandler\User\RegisterConsultantAndOperator::class,

// Transfer - Team
TransferCommand\Team\CreateTeam::class => CommandHandler\Team\CreateTeam::class,
Expand Down
1 change: 1 addition & 0 deletions app/api/module/Api/config/validation-map/user.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
CommandHandler\User\RegisterUserSelfserve::class => NoValidationRequired::class,
CommandHandler\User\RegisterUserSelfserveFactory::class => NoValidationRequired::class,
CommandHandler\User\RemindUsernameSelfserve::class => NoValidationRequired::class,
CommandHandler\User\RegisterConsultantAndOperator::class => NoValidationRequired::class,
CommandHandler\User\UpdatePartner::class => IsInternalUser::class,
CommandHandler\User\CreateUserSelfserve::class => CanManageUser::class,
CommandHandler\User\CreateUserSelfServeFactory::class => CanManageUser::class,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

/**
* Register Operator and Consultant
*/

namespace Dvsa\Olcs\Api\Domain\CommandHandler\User;

use Dvsa\Olcs\Api\Domain\CommandHandler\AbstractUserCommandHandler;
use Dvsa\Olcs\Api\Domain\CommandHandler\TransactionedInterface;
use Dvsa\Olcs\Transfer\Command\CommandInterface;
use Dvsa\Olcs\Transfer\Command\User\RegisterUserSelfserve as RegisterUserSelfServeCommand;

final class RegisterConsultantAndOperator extends AbstractUserCommandHandler implements TransactionedInterface
{
protected $repoServiceName = 'User';

public function handleCommand(CommandInterface $command)
{
// Register the operator first, a new Org will be created.
$this->result->merge($this->handleSideEffect(RegisterUserSelfServeCommand::create($command->getOperatorDetails())));

// Get the newly created user entity
$user = $this->getRepo()->fetchById($this->result->getId('user'));

// Add the org ID of the newly created user/org to the consultant details, then register the consultant
$consultantDetails = $command->getConsultantDetails();
$consultantDetails['organisation'] = $user->getOrganisationUsers()->first()->getOrganisation()->getId();

$this->result->merge($this->handleSideEffect(RegisterUserSelfServeCommand::create($consultantDetails)));

return $this->result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ public function handleCommand(CommandInterface $command)
} elseif (!empty($data['organisationName'])) {
// create organisation and link with it
$data['organisations'] = [$this->createOrganisation($data)];
} elseif (!empty($data['organisation'])) {
// link with the organisation
$data['organisations'] = [$this->getRepo('Organisation')->fetchById($data['organisation'])];
}

if (empty($data['organisations'])) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
<?php

namespace Dvsa\OlcsTest\Api\Domain\CommandHandler\User;

use Dvsa\Olcs\Api\Domain\CommandHandler\User\RegisterConsultantAndOperator;
use Dvsa\Olcs\Api\Domain\Repository\User as UserRepo;
use Dvsa\Olcs\Api\Entity\User\User as UserEntity;
use Dvsa\Olcs\Transfer\Command\User\RegisterConsultantAndOperator as RegisterConsultantAndOperatorCommand;
use Dvsa\Olcs\Transfer\Command\User\RegisterUserSelfserve as RegisterUserSelfServeCommand;
use Dvsa\OlcsTest\Api\Domain\CommandHandler\AbstractCommandHandlerTestCase;
use Dvsa\Olcs\Api\Domain\Command\Result;
use Mockery as m;

class RegisterConsultantAndOperatorTest extends AbstractCommandHandlerTestCase
{
public function setUp(): void
{
$this->sut = new RegisterConsultantAndOperator();
$this->mockRepo('User', UserRepo::class);

$mockAuthService = m::mock(\LmcRbacMvc\Service\AuthorizationService::class);
$this->mockedSmServices['LmcRbacMvc\Service\AuthorizationService'] = $mockAuthService;

parent::setUp();
}

public function testHandleCommand()
{
$operatorDetails = ['organisationName' => 'Operator Org',];

$command = RegisterConsultantAndOperatorCommand::create(
[
'operatorDetails' => $operatorDetails,
'consultantDetails' => []
]);

$operatorResult = new Result();
$operatorResult->addId('user', 100)->addMessage('User created successfully');

$this->expectedSideEffect(
RegisterUserSelfServeCommand::class,
$operatorDetails,
$operatorResult
);

$organisationId = 200;
$organisation = m::mock();
$organisation->shouldReceive('getId')->andReturn($organisationId);

$organisationUser = m::mock();
$organisationUser->shouldReceive('getOrganisation')->andReturn($organisation);

$user = m::mock(UserEntity::class)->makePartial();
$user->shouldReceive('getOrganisationUsers->first')->andReturn($organisationUser);

$this->repoMap['User']->shouldReceive('fetchById')->with(100)->andReturn($user);

$consultantDetails['organisation'] = $organisationId;

$consultantResult = new Result();
$consultantResult->addId('user', 101)->addMessage('User created successfully');

$this->expectedSideEffect(
RegisterUserSelfServeCommand::class,
$consultantDetails,
$consultantResult
);

$result = $this->sut->handleCommand($command);
$this->assertEquals(['User created successfully', 'User created successfully'], $result->getMessages());
}
}
58 changes: 54 additions & 4 deletions app/selfserve/module/Olcs/config/module.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -502,7 +502,50 @@
'route' => '/register[/]',
'defaults' => [
'controller' => UserRegistrationController::class,
'action' => 'add'
'action' => 'start'
]
],
'may_terminate' => true,
'child_routes' => [
'operator' => [
'type' => 'segment',
'options' => [
'route' => 'operator[/]',
'defaults' => [
'controller' => UserRegistrationController::class,
'action' => 'add'
]
]
],
'operator-representation' => [
'type' => 'segment',
'options' => [
'route' => 'operator-representation[/]',
'defaults' => [
'controller' => UserRegistrationController::class,
'action' => 'operatorRepresentation'
]
]
],
'register-for-operator' => [
'type' => 'segment',
'options' => [
'route' => 'register-for-operator[/]',
'defaults' => [
'controller' => UserRegistrationController::class,
'action' => 'registerForOperator'
]
]
],
'register-consultant-account' => [
'type' => 'segment',
'options' => [
'route' => 'register-consultant-account[/]',
'defaults' => [
'controller' => UserRegistrationController::class,
'action' => 'registerConsultantAccount'
]
]
]
]
],
Expand Down Expand Up @@ -1434,7 +1477,9 @@
'CookieSettingsCookieNamesProvider' => CookieService\SettingsCookieNamesProvider::class,
'QaIrhpApplicationViewGenerator' => QaService\ViewGenerator\IrhpApplicationViewGenerator::class,
'QaIrhpPermitApplicationViewGenerator' => QaService\ViewGenerator\IrhpPermitApplicationViewGenerator::class,
LicenceVehicleManagement::class => LicenceVehicleManagement::class
LicenceVehicleManagement::class => LicenceVehicleManagement::class,
\Olcs\Session\ConsultantRegistration::class => \Olcs\Session\ConsultantRegistration::class,

],
'abstract_factories' => [
\Laminas\Cache\Service\StorageCacheAbstractServiceFactory::class,
Expand Down Expand Up @@ -1668,7 +1713,7 @@
'verify/process-response' => ['*'],
'search*' => ['*'],
'index' => ['*'],
'user-registration' => ['*'],
'user-registration*' => ['*'],
'user-forgot-username' => ['*'],
'cookies*' => ['*'],
'privacy-notice' => ['*'],
Expand Down Expand Up @@ -1701,5 +1746,10 @@
'options_default_plus_cancel' => \Permits\Form\Model\Fieldset\SubmitOrCancelApplication::class,
'options_bilateral' => \Permits\Form\Model\Fieldset\SubmitOnly::class,
]
]
],
'validators' => [
'factories' => [
\Olcs\Form\Validator\UniqueConsultantDetails::class => \Olcs\Form\Validator\Factory\UniqueConsultantDetailsFactory::class,
],
],
];
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Common\Service\Helper\UrlHelperService;
use Common\Service\Script\ScriptFactory;
use Dvsa\Olcs\Utils\Translation\NiTextTranslation;
use Olcs\Session\ConsultantRegistration;
use Psr\Container\ContainerInterface;
use Laminas\ServiceManager\Factory\FactoryInterface;
use Olcs\Controller\UserRegistrationController;
Expand All @@ -30,6 +31,7 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o
$translationHelper = $container->get(TranslationHelperService::class);
$urlHelper = $container->get(UrlHelperService::class);
$flashMessengerHelper = $container->get(FlashMessengerHelperService::class);
$consultantRegistrationSession = $container->get(ConsultantRegistration::class);

return new UserRegistrationController(
$niTextTranslationUtil,
Expand All @@ -38,7 +40,8 @@ public function __invoke(ContainerInterface $container, $requestedName, array $o
$scriptFactory,
$translationHelper,
$urlHelper,
$flashMessengerHelper
$flashMessengerHelper,
$consultantRegistrationSession
);
}
}
Loading

0 comments on commit 1d6e983

Please sign in to comment.