Skip to content

Commit

Permalink
Fix: VOL-4687 - Refactor ListConversation Query for compatibility wit…
Browse files Browse the repository at this point in the history
…h internal (applications) (#5)

* Refactor query for compatibility with applications

* Unit Tests
  • Loading branch information
jerotire committed Dec 11, 2023
1 parent 9d457fd commit d3922c9
Show file tree
Hide file tree
Showing 6 changed files with 273 additions and 55 deletions.
15 changes: 13 additions & 2 deletions config/backend-routes/messaging/messaging.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,19 @@
'conversations' => RouteConfig::getRouteConfig(
'conversations',
[
'GET' => QueryConfig::getConfig(Query\Messaging\GetConversationList::class),
]
'by-licence' => RouteConfig::getRouteConfig(
'by-licence',
[
'GET' => QueryConfig::getConfig(Query\Messaging\Conversations\ByLicence::class),
],
),
'by-application-to-licence' => RouteConfig::getRouteConfig(
'by-application-to-licence',
[
'GET' => QueryConfig::getConfig(Query\Messaging\Conversations\ByApplicationToLicence::class),
],
),
],
),
]
)
Expand Down
18 changes: 18 additions & 0 deletions src/Query/Messaging/Conversations/ByApplicationToLicence.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Dvsa\Olcs\Transfer\Query\Messaging\Conversations;

use Dvsa\Olcs\Transfer\FieldType\Traits\Application;
use Dvsa\Olcs\Transfer\Query\AbstractQuery;
use Dvsa\Olcs\Transfer\Query\PagedQueryInterface;
use Dvsa\Olcs\Transfer\Query\PagedTrait;
use Dvsa\Olcs\Transfer\Util\Annotation as Transfer;

/**
* @Transfer\RouteName("backend/messaging/conversations/by-application-to-licence")
*/
final class ByApplicationToLicence extends AbstractQuery implements PagedQueryInterface
{
use PagedTrait;
use Application;
}
18 changes: 18 additions & 0 deletions src/Query/Messaging/Conversations/ByLicence.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Dvsa\Olcs\Transfer\Query\Messaging\Conversations;

use Dvsa\Olcs\Transfer\FieldType\Traits\Licence;
use Dvsa\Olcs\Transfer\Query\AbstractQuery;
use Dvsa\Olcs\Transfer\Query\PagedQueryInterface;
use Dvsa\Olcs\Transfer\Query\PagedTrait;
use Dvsa\Olcs\Transfer\Util\Annotation as Transfer;

/**
* @Transfer\RouteName("backend/messaging/conversations/by-licence")
*/
final class ByLicence extends AbstractQuery implements PagedQueryInterface
{
use PagedTrait;
use Licence;
}
53 changes: 0 additions & 53 deletions src/Query/Messaging/GetConversationList.php

This file was deleted.

112 changes: 112 additions & 0 deletions test/Query/Messaging/Conversations/ByApplicationToLicenceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php

namespace Dvsa\OlcsTest\Transfer\Query\Messaging\Conversations;

use Dvsa\Olcs\Transfer\Query\Messaging\Conversations\ByApplicationToLicence;
use Dvsa\OlcsTest\Transfer\DtoWithoutOptionalFieldsTest;
use Dvsa\OlcsTest\Transfer\Query\QueryTest;
use Laminas\Stdlib\ArraySerializableInterface;

class ByApplicationToLicenceTest extends \PHPUnit\Framework\TestCase
{
use QueryTest, DtoWithoutOptionalFieldsTest {
DtoWithoutOptionalFieldsTest::testDefaultValues insteadof QueryTest;
}

/**
* Should return a new blank DTO on which to run tests
*
* @return ArraySerializableInterface
*/
protected function createBlankDto()
{
return new ByApplicationToLicence();
}

/**
* Should return an array of valid field values (i.e. those which should pass validation)
*
* for example:
*
* return [
* 'fieldName' => [
* 'good-value-1',
* 'good-value-2',
* ],
* 'anotherFieldName' => ['good-value'],
* ];
*
* @return array
*/
protected function getValidFieldValues()
{
return [
'application' => [
'1'
],
'page' => [
'1',
],
'limit' => [
'1',
],
];
}

/**
* Should return an array of invalid field values (i.e. those which should fail validation)
*
* for example:
*
* return [
* 'fieldName' => [
* 'bad-value-1',
* 'bad-value-2',
* ],
* 'anotherFieldName' => ['bad-value'],
* ];
*
* @return array
*/
protected function getInvalidFieldValues()
{
$invalidNumbers = [0,
'a',
'-',
'\n',];

return [
'application' => $invalidNumbers,
'page' => $invalidNumbers,
'limit' => $invalidNumbers,
];
}

/**
* Should return an array of expected transformations which input filters should apply to fields
*
* for example:
*
* return [
* 'fieldWhichGetsTrimmed' => [[' string ', 'string']],
* 'fieldWhichFiltersOutNonNumericDigits => [
* ['a1b2c3', '123'],
* [99, '99'],
* ],
* ];
*
* Tests expect the function 'getFoo' to exist for the function 'foo'.
*
* This DOES NOT assert that the value gets validated. To do that @see DtoTest::getValidFieldValues
*
* @return array
*/
protected function getFilterTransformations()
{
return [
'application' => [[99, '99']],
'page' => [[99, '99']],
'limit' => [[99, '99']],
];
}
}
112 changes: 112 additions & 0 deletions test/Query/Messaging/Conversations/ByLicenceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php

namespace Dvsa\OlcsTest\Transfer\Query\Messaging\Conversations;

use Dvsa\Olcs\Transfer\Query\Messaging\Conversations\ByLicence;
use Dvsa\OlcsTest\Transfer\DtoWithoutOptionalFieldsTest;
use Dvsa\OlcsTest\Transfer\Query\QueryTest;
use Laminas\Stdlib\ArraySerializableInterface;

class ByLicenceTest extends \PHPUnit\Framework\TestCase
{
use QueryTest, DtoWithoutOptionalFieldsTest {
DtoWithoutOptionalFieldsTest::testDefaultValues insteadof QueryTest;
}

/**
* Should return a new blank DTO on which to run tests
*
* @return ArraySerializableInterface
*/
protected function createBlankDto()
{
return new ByLicence();
}

/**
* Should return an array of valid field values (i.e. those which should pass validation)
*
* for example:
*
* return [
* 'fieldName' => [
* 'good-value-1',
* 'good-value-2',
* ],
* 'anotherFieldName' => ['good-value'],
* ];
*
* @return array
*/
protected function getValidFieldValues()
{
return [
'licence' => [
'1'
],
'page' => [
'1',
],
'limit' => [
'1',
],
];
}

/**
* Should return an array of invalid field values (i.e. those which should fail validation)
*
* for example:
*
* return [
* 'fieldName' => [
* 'bad-value-1',
* 'bad-value-2',
* ],
* 'anotherFieldName' => ['bad-value'],
* ];
*
* @return array
*/
protected function getInvalidFieldValues()
{
$invalidNumbers = [0,
'a',
'-',
'\n',];

return [
'licence' => $invalidNumbers,
'page' => $invalidNumbers,
'limit' => $invalidNumbers,
];
}

/**
* Should return an array of expected transformations which input filters should apply to fields
*
* for example:
*
* return [
* 'fieldWhichGetsTrimmed' => [[' string ', 'string']],
* 'fieldWhichFiltersOutNonNumericDigits => [
* ['a1b2c3', '123'],
* [99, '99'],
* ],
* ];
*
* Tests expect the function 'getFoo' to exist for the function 'foo'.
*
* This DOES NOT assert that the value gets validated. To do that @see DtoTest::getValidFieldValues
*
* @return array
*/
protected function getFilterTransformations()
{
return [
'licence' => [[99, '99']],
'page' => [[99, '99']],
'limit' => [[99, '99']],
];
}
}

0 comments on commit d3922c9

Please sign in to comment.