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.
fix: redesign query handlers for conversations
(cherry picked from commit 8fcc7e4)
- Loading branch information
1 parent
94044fe
commit b2f21bc
Showing
6 changed files
with
154 additions
and
77 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
45 changes: 45 additions & 0 deletions
45
module/Api/src/Domain/QueryHandler/Messaging/Conversations/ByApplicationToLicence.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,45 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Dvsa\Olcs\Api\Domain\QueryHandler\Messaging\Conversations; | ||
|
||
use Dvsa\Olcs\Api\Domain\QueryHandler\AbstractQueryHandler; | ||
use Dvsa\Olcs\Api\Domain\Repository\Application as ApplicationRepo; | ||
use Dvsa\Olcs\Api\Domain\ToggleAwareTrait; | ||
use Dvsa\Olcs\Api\Domain\ToggleRequiredInterface; | ||
use Dvsa\Olcs\Api\Entity\System\FeatureToggle; | ||
use Dvsa\Olcs\Transfer\Query\Messaging\Conversations\ByApplicationToLicence as GetConversationsByApplicationToLicenceQuery; | ||
use Dvsa\Olcs\Transfer\Query\Messaging\Conversations\ByLicence as GetConversationsByLicenceQuery; | ||
use Dvsa\Olcs\Transfer\Query\QueryInterface; | ||
|
||
class ByApplicationToLicence extends AbstractQueryHandler implements ToggleRequiredInterface | ||
{ | ||
use ToggleAwareTrait; | ||
|
||
protected $toggleConfig = [FeatureToggle::MESSAGING]; | ||
protected $extraRepos = ['Application']; | ||
|
||
public function handleQuery(QueryInterface $query) | ||
{ | ||
assert($query instanceof GetConversationsByApplicationToLicenceQuery); | ||
$applicationRepository = $this->getApplicationRepository(); | ||
|
||
$application = $applicationRepository->fetchById($query->getApplication()); | ||
|
||
$licenceQuery = [ | ||
'page' => $query->getPage(), | ||
'limit' => $query->getLimit(), | ||
'licence' => $application->getLicence()->getId(), | ||
]; | ||
|
||
return $this->getQueryHandler()->handleQuery(GetConversationsByLicenceQuery::create($licenceQuery)); | ||
} | ||
|
||
private function getApplicationRepository(): ApplicationRepo | ||
{ | ||
$applicationRepository = $this->getRepo('Application'); | ||
assert($applicationRepository instanceof ApplicationRepo); | ||
return $applicationRepository; | ||
} | ||
} |
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
48 changes: 48 additions & 0 deletions
48
...module/Api/src/Domain/QueryHandler/Messaging/Conversations/ByApplicationToLicenceTest.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,48 @@ | ||
<?php | ||
|
||
namespace Dvsa\OlcsTest\Api\Domain\QueryHandler\Messaging; | ||
|
||
use Dvsa\Olcs\Api\Domain\QueryHandler\Messaging\Conversations\ByApplicationToLicence as Handler; | ||
use Dvsa\Olcs\Api\Domain\Repository; | ||
use Dvsa\Olcs\Api\Entity\Application\Application; | ||
use Dvsa\Olcs\Api\Entity\Licence\Licence; | ||
use Dvsa\Olcs\Transfer\Query\Messaging\Conversations\ByApplicationToLicence as Qry; | ||
use Dvsa\Olcs\Transfer\Query\Messaging\Conversations\ByLicence; | ||
use Dvsa\OlcsTest\Api\Domain\QueryHandler\QueryHandlerTestCase; | ||
use Mockery as m; | ||
|
||
class ByApplicationToLicenceTest extends QueryHandlerTestCase | ||
{ | ||
public function setUp(): void | ||
{ | ||
$this->sut = new Handler(); | ||
$this->mockRepo('Application', Repository\Application::class); | ||
|
||
parent::setUp(); | ||
} | ||
|
||
public function testHandleQuery() | ||
{ | ||
$query = Qry::create([ | ||
'application' => 1, | ||
]); | ||
|
||
$mockLicence = m::mock(Licence::class); | ||
$mockLicence->shouldReceive('getId')->once()->andReturn(2); | ||
$mockApplication = m::mock(Application::class); | ||
$mockApplication->shouldReceive('getLicence')->once()->andReturn($mockLicence); | ||
|
||
$this->repoMap['Application']->shouldReceive('fetchById')->andReturn($mockApplication); | ||
|
||
$this->queryHandler->shouldReceive('handleQuery')->with(m::on( | ||
function ($argument) { | ||
$this->assertInstanceOf(ByLicence::class, $argument); | ||
assert($argument instanceof ByLicence); | ||
$this->assertEquals(2, $argument->getLicence(), 'Expected licence ID used in proxy call to ByLicence to match licence returned from application'); | ||
return true; | ||
} | ||
))->once(); | ||
|
||
$this->sut->handleQuery($query); | ||
} | ||
} |
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