Skip to content

Commit

Permalink
fix: updated handler and unit test to set correct role for consultant…
Browse files Browse the repository at this point in the history
… user.
  • Loading branch information
fibble committed Aug 27, 2024
1 parent ed700b2 commit 12c419e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@

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;

Expand All @@ -29,6 +31,10 @@ public function handleCommand(CommandInterface $command)

$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'));
$consultantUser->setRoles(new ArrayCollection([RoleEntity::ROLE_OPERATOR_TC]));
$this->getRepo()->save($consultantUser);
return $this->result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,16 @@ public function testHandleCommand()
$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);

$this->expectedSideEffect(
RegisterUserSelfServeCommand::class,
$consultantDetails,
Expand Down

0 comments on commit 12c419e

Please sign in to comment.