-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: VOL-5239 create transport consultant reg journey
# Conflicts: # app/api/composer.lock
- Loading branch information
Showing
32 changed files
with
1,736 additions
and
57 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
app/api/module/Api/src/Domain/CommandHandler/User/RegisterConsultantAndOperator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<?php | ||
|
||
/** | ||
* Register Operator and Consultant | ||
*/ | ||
|
||
namespace Dvsa\Olcs\Api\Domain\CommandHandler\User; | ||
|
||
use Doctrine\Common\Collections\ArrayCollection; | ||
use Dvsa\Olcs\Api\Domain\CommandHandler\AbstractUserCommandHandler; | ||
use Dvsa\Olcs\Api\Domain\CommandHandler\TransactionedInterface; | ||
use Dvsa\Olcs\Api\Entity\User\Role as RoleEntity; | ||
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'; | ||
protected $extraRepos = ['Role']; | ||
|
||
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))); | ||
|
||
// Get the new consultant user entity and set the correct role. | ||
$consultantUser = $this->getRepo()->fetchById($this->result->getId('user')); | ||
$operatorTcRole = $this->getRepo('Role')->fetchByRole(RoleEntity::ROLE_OPERATOR_TC); | ||
$consultantUser->setRoles(new ArrayCollection([$operatorTcRole])); | ||
$this->getRepo()->save($consultantUser); | ||
return $this->result; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
app/api/module/Email/view/email/en_GB/html/user-registered-tc.phtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<p>Hello,</p> | ||
|
||
<p>You've been added to the Vehicle Operator Licensing service for <?php echo $this->escapeHtml($this->orgName); ?>.</p> | ||
|
||
<p>Your username is: <?php echo $this->escapeHtml($this->loginId); ?></p> | ||
|
||
<p>You'll receive a second email with a temporary password in the next two hours. If it doesn't arrive email notification@vehicle-operator-licensing.service.gov.uk</p> | ||
|
||
<p> | ||
<a href="<?php echo $this->escapeHtml($this->url); ?>">Sign in</a> | ||
</p> |
9 changes: 9 additions & 0 deletions
9
app/api/module/Email/view/email/en_GB/plain/user-registered-tc.phtml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
Hello, | ||
|
||
You've been added to the Vehicle Operator Licensing service for <?php echo $this->orgName; ?>. | ||
|
||
Your username is: <?php echo $this->loginId; ?></p> | ||
|
||
You'll receive a second email with a temporary password in the next two hours. If it doesn't arrive email notification@vehicle-operator-licensing.service.gov.uk | ||
|
||
Sign in at <?php echo $this->url; ?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
app/api/test/module/Api/src/Domain/CommandHandler/User/RegisterConsultantAndOperatorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
<?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\Role; | ||
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); | ||
$this->mockRepo('Role', \Dvsa\Olcs\Api\Domain\Repository\Role::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'); | ||
|
||
$consultant = m::mock(UserEntity::class)->makePartial(); | ||
$this->repoMap['User']->shouldReceive('fetchById')->with(101)->andReturn($consultant); | ||
|
||
$consultant->shouldReceive('setRoles') | ||
->with(m::type(\Doctrine\Common\Collections\ArrayCollection::class)) | ||
->once() | ||
->andReturnSelf(); | ||
|
||
$this->repoMap['User']->shouldReceive('save')->with($consultant); | ||
|
||
$mockRole = m::mock(Role::class); | ||
$this->repoMap['Role']->shouldReceive('fetchByRole')->with(Role::ROLE_OPERATOR_TC)->andReturn($mockRole); | ||
|
||
$this->expectedSideEffect( | ||
RegisterUserSelfServeCommand::class, | ||
$consultantDetails, | ||
$consultantResult | ||
); | ||
|
||
$result = $this->sut->handleCommand($command); | ||
$this->assertEquals(['User created successfully', 'User created successfully'], $result->getMessages()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.