-
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
- Loading branch information
Showing
23 changed files
with
945 additions
and
36 deletions.
There are no files selected for viewing
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
34 changes: 34 additions & 0 deletions
34
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,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; | ||
} | ||
} |
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
72 changes: 72 additions & 0 deletions
72
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,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()); | ||
} | ||
} |
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
Oops, something went wrong.