Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: VOL-4575 Conversation query (L2) #9

Merged
merged 13 commits into from
Dec 13, 2023
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# This repository has been migrated to: https://github.com/dvsa/olcs-transfer.
jerotire marked this conversation as resolved.
Show resolved Hide resolved
11 changes: 11 additions & 0 deletions config/backend-routes/messaging/messaging.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,17 @@
),
],
),
'messages' => RouteConfig::getRouteConfig(
'messages',
[
'by-conversation' => RouteConfig::getRouteConfig(
'by-conversation',
[
'GET' => QueryConfig::getConfig(Query\Messaging\Messages\ByConversation::class),
],
),
]
),
]
)
];
27 changes: 27 additions & 0 deletions src/FieldType/Traits/Conversation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Dvsa\Olcs\Transfer\FieldType\Traits;

/**
* Trait Conversation
*
* @package Dvsa\Olcs\Transfer\FieldType\Traits
*/
trait Conversation
{
/**
* @var int
* @Transfer\Filter({"name":"Laminas\Filter\Digits"})
* @Transfer\Validator({"name":"Laminas\Validator\Digits"})
* @Transfer\Validator({"name":"Laminas\Validator\GreaterThan", "options": {"min": 0}})
*/
protected $conversation;

/**
* @return int
*/
public function getConversation()
{
return $this->conversation;
}
}
18 changes: 18 additions & 0 deletions src/Query/Messaging/Messages/ByConversation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

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

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

/**
* @Transfer\RouteName("backend/messaging/messages/by-conversation")
*/
final class ByConversation extends AbstractQuery implements PagedQueryInterface
{
use PagedTrait;
use Conversation;
}
112 changes: 112 additions & 0 deletions test/Query/Messaging/Message/ByConversationTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?php

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

use Dvsa\Olcs\Transfer\Query\Messaging\Messages\ByConversation;
use Dvsa\OlcsTest\Transfer\DtoWithoutOptionalFieldsTest;
use Dvsa\OlcsTest\Transfer\Query\QueryTest;
use Laminas\Stdlib\ArraySerializableInterface;

class ByConversationTest 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 ByConversation();
}

/**
* 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 [
'conversation' => [
'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 [
'conversation' => $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 [
'conversation' => [[99, '99']],
'page' => [[99, '99']],
'limit' => [[99, '99']],
];
}
}
Loading