Several important fixes, new tests
This commit is contained in:
parent
02a45d8272
commit
348d500843
@ -13,6 +13,7 @@
|
||||
|
||||
namespace RetailCrm\Mg\Bot\Model\Entity\Chat;
|
||||
|
||||
use JMS\Serializer\Annotation as Serializer;
|
||||
use RetailCrm\Mg\Bot\Model\Entity\Channel\Channel;
|
||||
use RetailCrm\Mg\Bot\Model\Entity\CommonFields;
|
||||
use JMS\Serializer\Annotation\Accessor;
|
||||
@ -55,6 +56,7 @@ class Chat
|
||||
*
|
||||
* @Type("RetailCrm\Mg\Bot\Model\Entity\Channel\Channel")
|
||||
* @Accessor(getter="getChannel",setter="setChannel")
|
||||
* @SkipWhenEmpty()
|
||||
*/
|
||||
private $channel;
|
||||
|
||||
|
@ -49,10 +49,10 @@ trait CommonFields
|
||||
private $createdAt;
|
||||
|
||||
/**
|
||||
* @var \DateTime $createdAt
|
||||
* @var \DateTime $updatedAt
|
||||
*
|
||||
* @Type("DateTime<'Y-m-d\TH:i:s\.u\Z'>")
|
||||
* @Accessor(getter="getCreatedAt",setter="setCreatedAt")
|
||||
* @Accessor(getter="getUpdatedAt",setter="setUpdatedAt")
|
||||
* @SkipWhenEmpty()
|
||||
*/
|
||||
private $updatedAt;
|
||||
|
@ -13,7 +13,6 @@
|
||||
|
||||
namespace RetailCrm\Mg\Bot\Model\Entity;
|
||||
|
||||
use RetailCrm\Mg\Bot\Model\Entity\CommonFields;
|
||||
use JMS\Serializer\Annotation\Accessor;
|
||||
use JMS\Serializer\Annotation\SkipWhenEmpty;
|
||||
use JMS\Serializer\Annotation\Type;
|
||||
|
@ -30,9 +30,9 @@ use JMS\Serializer\Annotation\Type;
|
||||
class Responsible
|
||||
{
|
||||
/**
|
||||
* @var \DateTime $assignedAt
|
||||
* @var string $assignedAt
|
||||
*
|
||||
* @Type("DateTime<'Y-m-d\TH:i:s\.u\Z'>")
|
||||
* @Type("string")
|
||||
* @Accessor(getter="getAssignedAt",setter="setAssignedAt")
|
||||
* @SkipWhenEmpty()
|
||||
*/
|
||||
@ -57,17 +57,17 @@ class Responsible
|
||||
private $type;
|
||||
|
||||
/**
|
||||
* @return \DateTime
|
||||
* @return string
|
||||
*/
|
||||
public function getAssignedAt(): \DateTime
|
||||
public function getAssignedAt(): string
|
||||
{
|
||||
return $this->assignedAt;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param \DateTime $assignedAt
|
||||
* @param string $assignedAt
|
||||
*/
|
||||
public function setAssignedAt(\DateTime $assignedAt)
|
||||
public function setAssignedAt(string $assignedAt)
|
||||
{
|
||||
$this->assignedAt = $assignedAt;
|
||||
}
|
||||
|
@ -33,8 +33,7 @@ class DialogAssignRequest
|
||||
* @var int $dialogId
|
||||
*
|
||||
* @Type("int")
|
||||
* @Accessor(getter="getDialogId,setter="setDialogId")
|
||||
* @SkipWhenEmpty
|
||||
* @Accessor(getter="getDialogId", setter="setDialogId")
|
||||
*/
|
||||
private $dialogId;
|
||||
|
||||
@ -43,7 +42,7 @@ class DialogAssignRequest
|
||||
*
|
||||
* @Type("int")
|
||||
* @Accessor(getter="getUserId", setter="setUserId")
|
||||
* @SkipWhenEmpty
|
||||
* @SkipWhenEmpty()
|
||||
*/
|
||||
private $userId;
|
||||
|
||||
@ -67,7 +66,7 @@ class DialogAssignRequest
|
||||
/**
|
||||
* @param int $dialogId
|
||||
*/
|
||||
public function setDialogId(int $dialogId)
|
||||
public function setDialogId($dialogId)
|
||||
{
|
||||
$this->dialogId = $dialogId;
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ class AssignResponse
|
||||
/**
|
||||
* @var Responsible $previousResponsible
|
||||
*
|
||||
* @Type("Responsible")
|
||||
* @Type("RetailCrm\Mg\Bot\Model\Entity\Responsible")
|
||||
* @Accessor(getter="getPreviousResponsible",setter="setPreviousResponsible")
|
||||
* @SkipWhenEmpty()
|
||||
*/
|
||||
@ -62,7 +62,7 @@ class AssignResponse
|
||||
/**
|
||||
* @var Responsible $responsible
|
||||
*
|
||||
* @Type("Responsible")
|
||||
* @Type("RetailCrm\Mg\Bot\Model\Entity\Responsible")
|
||||
* @Accessor(getter="getResponsible",setter="setResponsible")
|
||||
* @SkipWhenEmpty()
|
||||
*/
|
||||
@ -71,7 +71,7 @@ class AssignResponse
|
||||
/**
|
||||
* @return bool
|
||||
*/
|
||||
public function isReassign(): bool
|
||||
public function getIsReassign(): bool
|
||||
{
|
||||
return $this->isReassign;
|
||||
}
|
||||
|
@ -54,11 +54,8 @@ class ListResponse implements \Iterator, \ArrayAccess, \Countable {
|
||||
$this->errors = $data['errors'];
|
||||
} else {
|
||||
foreach($data as $item) {
|
||||
if (substr($responseType, 0, 1) == '\\') {
|
||||
$responseType = substr($responseType, 1);
|
||||
}
|
||||
|
||||
$this->items[] = Serializer::deserialize($item, $responseType, Serializer::S_ARRAY);
|
||||
$this->items[] =
|
||||
Serializer::deserialize($item, $responseType, Serializer::S_ARRAY);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -76,10 +76,12 @@ class Serializer
|
||||
|
||||
switch ($from) {
|
||||
case self::S_ARRAY:
|
||||
$deserialized = $serializer->fromArray(array_filter($data), self::normalizeNamespace($entityType), $context);
|
||||
$deserialized =
|
||||
$serializer->fromArray(array_filter($data), self::normalizeNamespace($entityType), $context);
|
||||
break;
|
||||
case self::S_JSON:
|
||||
$deserialized = $serializer->deserialize($data, self::normalizeNamespace($entityType), $from, $context);
|
||||
$deserialized =
|
||||
$serializer->deserialize($data, self::normalizeNamespace($entityType), $from, $context);
|
||||
break;
|
||||
}
|
||||
|
||||
@ -112,9 +114,9 @@ class Serializer
|
||||
private static function normalizeNamespace(string $namespace)
|
||||
{
|
||||
if (substr($namespace, 0, 1) == '\\') {
|
||||
return substr($namespace, 1);
|
||||
} else {
|
||||
$namespace = substr($namespace, 1);
|
||||
}
|
||||
|
||||
return $namespace;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,7 @@
|
||||
/**
|
||||
* PHP version 7.0
|
||||
*
|
||||
* Client Test
|
||||
* Commands Test
|
||||
*
|
||||
* @package RetailCrm\Mg\Bot\Tests
|
||||
* @author retailCRM <integration@retailcrm.ru>
|
||||
@ -23,7 +23,7 @@ use RetailCrm\Mg\Bot\Test\TestCase;
|
||||
/**
|
||||
* PHP version 7.0
|
||||
*
|
||||
* Class ClientTest
|
||||
* Class CommandsTest
|
||||
*
|
||||
* @package RetailCrm\Mg\Bot\Tests
|
||||
* @author retailCRM <integration@retailcrm.ru>
|
||||
|
118
tests/Bot/Tests/DialogsTest.php
Normal file
118
tests/Bot/Tests/DialogsTest.php
Normal file
@ -0,0 +1,118 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHP version 7.0
|
||||
*
|
||||
* Dialogs Test
|
||||
*
|
||||
* @package RetailCrm\Mg\Bot\Tests
|
||||
* @author retailCRM <integration@retailcrm.ru>
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link http://help.retailcrm.pro/docs/Developers
|
||||
*/
|
||||
|
||||
namespace RetailCrm\Mg\Bot\Tests;
|
||||
|
||||
use InvalidArgumentException;
|
||||
use RetailCrm\Mg\Bot\Model\Entity\Responsible;
|
||||
use RetailCrm\Mg\Bot\Model\Request\DialogAssignRequest;
|
||||
use RetailCrm\Mg\Bot\Model\Response\ErrorOnlyResponse;
|
||||
use RetailCrm\Mg\Bot\Test\TestCase;
|
||||
|
||||
/**
|
||||
* PHP version 7.0
|
||||
*
|
||||
* Class DialogsTest
|
||||
*
|
||||
* @package RetailCrm\Mg\Bot\Tests
|
||||
* @author retailCRM <integration@retailcrm.ru>
|
||||
* @license https://opensource.org/licenses/MIT MIT License
|
||||
* @link http://help.retailcrm.pro/docs/Developers
|
||||
*/
|
||||
class DialogsTest extends TestCase
|
||||
{
|
||||
/**
|
||||
* @group("dialogs")
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function testDialogAssignError()
|
||||
{
|
||||
$client = self::getApiClient(
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
$this->getResponse('{"errors":["incorrect dialog_id"]}', 400)
|
||||
);
|
||||
|
||||
$request = new DialogAssignRequest();
|
||||
$request->setDialogId(-1);
|
||||
|
||||
$response = $client->dialogAssign($request);
|
||||
|
||||
self::assertTrue(!$response->isSuccessful());
|
||||
self::assertNotEmpty($response->getErrors());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group("dialogs")
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function testDialogAssign()
|
||||
{
|
||||
$client = self::getApiClient(
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
$this->getJsonResponse('dialogReassigned')
|
||||
);
|
||||
|
||||
$request = new DialogAssignRequest();
|
||||
$request->setDialogId(60);
|
||||
$request->setUserId(4);
|
||||
|
||||
$response = $client->dialogAssign($request);
|
||||
|
||||
self::assertTrue($response->isSuccessful());
|
||||
self::assertTrue($response->getIsReassign());
|
||||
self::assertTrue($response->getPreviousResponsible() instanceof Responsible);
|
||||
self::assertTrue($response->getResponsible() instanceof Responsible);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group("dialogs")
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function testDialogCloseError()
|
||||
{
|
||||
self::expectException(InvalidArgumentException::class);
|
||||
|
||||
$client = self::getApiClient(
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
$this->getResponse('{"errors":["dialog #2131231231 not found"]}', 404)
|
||||
);
|
||||
|
||||
$client->dialogClose('2131231231');
|
||||
}
|
||||
|
||||
/**
|
||||
* @group("dialogs")
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function testDialogClose()
|
||||
{
|
||||
$client = self::getApiClient(
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
$this->getResponse('{}')
|
||||
);
|
||||
|
||||
$response = $client->dialogClose('62');
|
||||
|
||||
self::assertTrue($response instanceof ErrorOnlyResponse);
|
||||
self::assertTrue($response->isSuccessful());
|
||||
self::assertEmpty($response->getErrors());
|
||||
}
|
||||
}
|
@ -3,7 +3,7 @@
|
||||
/**
|
||||
* PHP version 7.0
|
||||
*
|
||||
* Client Test
|
||||
* Messages Test
|
||||
*
|
||||
* @package RetailCrm\Mg\Bot\Tests
|
||||
* @author retailCRM <integration@retailcrm.ru>
|
||||
|
@ -38,7 +38,7 @@
|
||||
}
|
||||
},
|
||||
"created_at": "2019-06-11T12:46:48.72241Z",
|
||||
"updated_at": "2019-06-11T12:46:48.72241Z",
|
||||
"updated_at": "2019-06-11T12:56:48.72241Z",
|
||||
"activated_at": "2019-06-11T12:46:48.722086Z",
|
||||
"deactivated_at": null,
|
||||
"is_active": true
|
||||
|
1
tests/Resources/dialogReassigned.json
Normal file
1
tests/Resources/dialogReassigned.json
Normal file
@ -0,0 +1 @@
|
||||
{"responsible":{"type":"user","id":4,"assigned_at":"2019-06-21T08:01:09Z"},"is_reassign":true,"previous_responsible":{"type":"user","id":12,"assigned_at":"2019-06-11T12:49:34Z"},"left_user_id":12}
|
Loading…
Reference in New Issue
Block a user