This repository has been archived by the owner on Aug 16, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Add backend api support for Local Authority UI
- Loading branch information
Showing
11 changed files
with
191 additions
and
8 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,14 @@ | ||
<?php | ||
|
||
use Dvsa\Olcs\Api\Domain\QueryHandler; | ||
use Dvsa\Olcs\Api\Domain\CommandHandler; | ||
use Dvsa\Olcs\Api\Domain\Validation\Handlers\Misc\IsInternalUser; | ||
use Dvsa\Olcs\Api\Domain\Validation\Handlers\Misc\IsSystemAdmin; | ||
|
||
return [ | ||
// Queries | ||
QueryHandler\LocalAuthority\LocalAuthorityList::class => IsInternalUser::class, | ||
QueryHandler\LocalAuthority\ById::class => IsSystemAdmin::class, | ||
// Commands | ||
CommandHandler\LocalAuthority\Update::class => IsSystemAdmin::class | ||
]; |
39 changes: 39 additions & 0 deletions
39
module/Api/src/Domain/CommandHandler/LocalAuthority/Update.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,39 @@ | ||
<?php | ||
|
||
namespace Dvsa\Olcs\Api\Domain\CommandHandler\LocalAuthority; | ||
|
||
use Dvsa\Olcs\Api\Domain\Command\Result; | ||
use Dvsa\Olcs\Api\Domain\CommandHandler\AbstractCommandHandler; | ||
use Dvsa\Olcs\Api\Domain\Repository\LocalAuthority as LocalAuthorityRepo; | ||
use Dvsa\Olcs\Api\Entity\Bus\LocalAuthority as LocalAuthorityEntity; | ||
use Dvsa\Olcs\Transfer\Command\CommandInterface; | ||
use Dvsa\Olcs\Transfer\Command\LocalAuthority\Update as UpdateLocalAuthorityCmd; | ||
|
||
/** | ||
* Update a Local Authority | ||
*/ | ||
final class Update extends AbstractCommandHandler | ||
{ | ||
protected $repoServiceName = 'LocalAuthority'; | ||
|
||
public function handleCommand(CommandInterface $command): Result | ||
{ | ||
/** | ||
* @var UpdateLocalAuthorityCmd $command | ||
* @var LocalAuthorityEntity $localAuthority | ||
* @var LocalAuthorityRepo $repo | ||
*/ | ||
$repo = $this->getRepo(); | ||
$localAuthority = $repo->fetchUsingId($command); | ||
$localAuthority->update( | ||
$command->getDescription(), | ||
$command->getEmailAddress() | ||
); | ||
|
||
$repo->save($localAuthority); | ||
|
||
$this->result->addId('LocalAuthority', $localAuthority->getId()); | ||
$this->result->addMessage("Local Authority '{$localAuthority->getId()}' updated"); | ||
return $this->result; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
module/Api/src/Domain/QueryHandler/LocalAuthority/ById.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,13 @@ | ||
<?php | ||
|
||
namespace Dvsa\Olcs\Api\Domain\QueryHandler\LocalAuthority; | ||
|
||
use Dvsa\Olcs\Api\Domain\QueryHandler\AbstractQueryByIdHandler; | ||
|
||
/** | ||
* Retrieve a local authority by id | ||
*/ | ||
final class ById extends AbstractQueryByIdHandler | ||
{ | ||
protected $repoServiceName = 'LocalAuthority'; | ||
} |
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
66 changes: 66 additions & 0 deletions
66
test/module/Api/src/Domain/CommandHandler/LocalAuthority/UpdateTest.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,66 @@ | ||
<?php | ||
|
||
namespace Dvsa\OlcsTest\Api\Domain\CommandHandler\LocalAuthority; | ||
|
||
use Dvsa\Olcs\Api\Domain\CommandHandler\LocalAuthority\Update as UpdateHandler; | ||
use Dvsa\Olcs\Api\Domain\Repository\LocalAuthority as LocalAuthorityRepo; | ||
use Dvsa\Olcs\Api\Entity\Bus\LocalAuthority as LocalAuthorityEntity; | ||
use Dvsa\Olcs\Transfer\Command\LocalAuthority\Update as UpdateCmd; | ||
use Dvsa\OlcsTest\Api\Domain\CommandHandler\AbstractCommandHandlerTestCase; | ||
use Mockery as m; | ||
|
||
/** | ||
* Update Local Authority Test | ||
*/ | ||
class UpdateTest extends AbstractCommandHandlerTestCase | ||
{ | ||
public function setUp(): void | ||
{ | ||
$this->sut = new UpdateHandler(); | ||
$this->mockRepo('LocalAuthority', LocalAuthorityRepo::class); | ||
parent::setUp(); | ||
} | ||
|
||
public function testHandleCommand() | ||
{ | ||
$id = 999; | ||
$description = 'lta descr'; | ||
$emailAddress = '[email protected]'; | ||
|
||
$cmdData = [ | ||
'id' => $id, | ||
'description' => $description, | ||
'emailAddress' => $emailAddress, | ||
]; | ||
|
||
$command = UpdateCmd::create($cmdData); | ||
|
||
$entity = m::mock(LocalAuthorityEntity::class); | ||
$entity->shouldReceive('update') | ||
->once() | ||
->with($description, $emailAddress); | ||
$entity->shouldReceive('getId') | ||
->twice() | ||
->andReturn($id); | ||
|
||
$this->repoMap['LocalAuthority'] | ||
->shouldReceive('fetchUsingId') | ||
->once() | ||
->with($command) | ||
->andReturn($entity); | ||
|
||
$this->repoMap['LocalAuthority'] | ||
->shouldReceive('save') | ||
->once() | ||
->with(m::type(LocalAuthorityEntity::class)); | ||
|
||
$result = $this->sut->handleCommand($command); | ||
|
||
$expected = [ | ||
'id' => ['LocalAuthority' => $id], | ||
'messages' => ["Local Authority '" . $id . "' updated"] | ||
]; | ||
|
||
$this->assertEquals($expected, $result->toArray()); | ||
} | ||
} |
21 changes: 21 additions & 0 deletions
21
test/module/Api/src/Domain/QueryHandler/LocalAuthority/ByIdTest.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,21 @@ | ||
<?php | ||
|
||
namespace Dvsa\OlcsTest\Api\Domain\QueryHandler\LocalAuthority; | ||
|
||
use Dvsa\Olcs\Api\Domain\QueryHandler\LocalAuthority\ById as ToggleByIdHandler; | ||
use Dvsa\Olcs\Api\Domain\Repository\LocalAuthority as LocalAuthorityRepo; | ||
use Dvsa\Olcs\Api\Entity\Bus\LocalAuthority as LocalAuthorityEntity; | ||
use Dvsa\Olcs\Transfer\Query\LocalAuthority\ById as QryClass; | ||
use Dvsa\OlcsTest\Api\Domain\QueryHandler\AbstractQueryByIdHandlerTest; | ||
|
||
/** | ||
* Local Authority ById Test | ||
*/ | ||
class ByIdTest extends AbstractQueryByIdHandlerTest | ||
{ | ||
protected $sutClass = ToggleByIdHandler::class; | ||
protected $sutRepo = 'LocalAuthority'; | ||
protected $qryClass = QryClass::class; | ||
protected $repoClass = LocalAuthorityRepo::class; | ||
protected $entityClass = LocalAuthorityEntity::class; | ||
} |
29 changes: 29 additions & 0 deletions
29
test/module/Api/src/Entity/LocalAuthority/LocalAuthorityEntityTest.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,29 @@ | ||
<?php | ||
|
||
namespace Dvsa\OlcsTest\Api\Entity\LocalAuthority; | ||
|
||
use Dvsa\Olcs\Api\Entity\Bus\LocalAuthority as Entity; | ||
use Dvsa\OlcsTest\Api\Entity\Abstracts\EntityTester; | ||
|
||
/** | ||
* Local Authority Entity Unit Tests | ||
*/ | ||
class LocalAuthorityEntityTest extends EntityTester | ||
{ | ||
/** | ||
* Define the entity to test | ||
* | ||
* @var string | ||
*/ | ||
protected $entityClass = Entity::class; | ||
|
||
public function testUpdate() | ||
{ | ||
$description = 'some lta name'; | ||
$emailAddress = '[email protected]'; | ||
$entity = new Entity(); | ||
$entity->update($description, $emailAddress); | ||
$this->assertEquals($description, $entity->getDescription()); | ||
$this->assertEquals($emailAddress, $entity->getEmailAddress()); | ||
} | ||
} |