-
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: welcome page for external users with terms and conditions VOL-5664
- Loading branch information
Showing
23 changed files
with
680 additions
and
16 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
46 changes: 46 additions & 0 deletions
46
app/api/module/Api/src/Domain/CommandHandler/User/AgreeTerms.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,46 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Dvsa\Olcs\Api\Domain\CommandHandler\User; | ||
|
||
use Dvsa\Olcs\Api\Domain\AuthAwareInterface; | ||
use Dvsa\Olcs\Api\Domain\AuthAwareTrait; | ||
use Dvsa\Olcs\Api\Domain\CacheAwareInterface; | ||
use Dvsa\Olcs\Api\Domain\CacheAwareTrait; | ||
use Dvsa\Olcs\Api\Domain\CommandHandler\AbstractCommandHandler; | ||
use Dvsa\Olcs\Api\Domain\Repository\User as UserRepository; | ||
use Dvsa\Olcs\Api\Entity\User\User; | ||
use Dvsa\Olcs\Transfer\Command\CommandInterface; | ||
|
||
final class AgreeTerms extends AbstractCommandHandler implements AuthAwareInterface, CacheAwareInterface | ||
{ | ||
use AuthAwareTrait; | ||
use CacheAwareTrait; | ||
|
||
public const SUCCESS_MSG = 'Terms and conditions accepted'; | ||
|
||
protected $repoServiceName = 'User'; | ||
|
||
public function handleCommand(CommandInterface $command) | ||
{ | ||
$userId = $this->getCurrentUser()->getId(); | ||
|
||
/** | ||
* @var UserRepository $repo | ||
* @var User $user | ||
*/ | ||
$repo = $this->getRepo(); | ||
|
||
$user = $repo->fetchById($userId); | ||
$user->agreeTermsAndConditions(); | ||
$repo->save($user); | ||
|
||
$this->clearUserCaches([$userId]); | ||
|
||
$this->result->addId('User', $userId); | ||
$this->result->addMessage(self::SUCCESS_MSG); | ||
|
||
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
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
63 changes: 63 additions & 0 deletions
63
app/api/test/module/Api/src/Domain/CommandHandler/User/AgreeTermsTest.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,63 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Dvsa\OlcsTest\Api\Domain\CommandHandler\User; | ||
|
||
use Dvsa\Olcs\Api\Domain\Repository\User as UserRepository; | ||
use Dvsa\Olcs\Api\Entity\User\User as UserEntity; | ||
use Dvsa\Olcs\Transfer\Command\User\AgreeTerms as Cmd; | ||
use Dvsa\Olcs\Transfer\Service\CacheEncryption; | ||
use Dvsa\OlcsTest\Api\Domain\CommandHandler\AbstractCommandHandlerTestCase; | ||
use Dvsa\Olcs\Api\Domain\CommandHandler\User\AgreeTerms; | ||
use LmcRbacMvc\Service\AuthorizationService; | ||
use Mockery as m; | ||
|
||
class AgreeTermsTest extends AbstractCommandHandlerTestCase | ||
{ | ||
public function setUp(): void | ||
{ | ||
$this->sut = new AgreeTerms(); | ||
$this->mockRepo('User', UserRepository::class); | ||
|
||
$this->mockedSmServices = [ | ||
AuthorizationService::class => m::mock(AuthorizationService::class), | ||
CacheEncryption::class => m::mock(CacheEncryption::class), | ||
]; | ||
|
||
parent::setUp(); | ||
} | ||
|
||
public function testHandleCommand() | ||
{ | ||
$userId = 999; | ||
|
||
$command = Cmd::create([]); | ||
|
||
$loggedInUser = m::mock(UserEntity::class); | ||
$loggedInUser->expects('getId')->andReturn($userId); | ||
|
||
$this->mockedSmServices[AuthorizationService::class]->expects('getIdentity->getUser') | ||
->andReturn($loggedInUser); | ||
|
||
$this->mockedSmServices[CacheEncryption::class]->expects('removeCustomItems') | ||
->with(CacheEncryption::USER_ACCOUNT_IDENTIFIER, [$userId]); | ||
|
||
$userFromRepo = m::mock(UserEntity::class); | ||
$userFromRepo->expects('agreeTermsAndConditions')->withNoArgs(); | ||
|
||
$this->repoMap['User']->expects('fetchById')->with($userId)->andReturn($userFromRepo); | ||
$this->repoMap['User']->expects('save')->with($userFromRepo); | ||
|
||
$expectedResult = [ | ||
'id' => [ | ||
'User' => $userId, | ||
], | ||
'messages' => [ | ||
0 => AgreeTerms::SUCCESS_MSG | ||
], | ||
]; | ||
|
||
$this->assertEquals($expectedResult, $this->sut->handleCommand($command)->toArray()); | ||
} | ||
} |
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.