Add working with dialog tags
This commit is contained in:
parent
41cb22a720
commit
6682b9b02c
@ -313,6 +313,48 @@ class Client
|
||||
return $adapter->getResponseModel($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add tag to dialog
|
||||
*
|
||||
* @param Model\Request\DialogTagRequest $request Request parameters
|
||||
*
|
||||
* @return \RetailCrm\Mg\Bot\Model\ModelInterface
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function dialogAddTag(Model\Request\DialogTagRequest $request)
|
||||
{
|
||||
$response = $this->client->makeRequest(
|
||||
sprintf("/dialogs/%d/tags/add", $request->getDialogId()),
|
||||
HttpClient::METHOD_PATCH,
|
||||
$request
|
||||
);
|
||||
|
||||
$adapter = new ModelAdapter(ErrorOnlyResponse::class);
|
||||
|
||||
return $adapter->getResponseModel($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete tag from dialog
|
||||
*
|
||||
* @param Model\Request\DialogTagRequest $request Request parameters
|
||||
*
|
||||
* @return \RetailCrm\Mg\Bot\Model\ModelInterface
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function dialogDeleteTag(Model\Request\DialogTagRequest $request)
|
||||
{
|
||||
$response = $this->client->makeRequest(
|
||||
sprintf("/dialogs/%d/tags/delete", $request->getDialogId()),
|
||||
HttpClient::METHOD_PATCH,
|
||||
$request
|
||||
);
|
||||
|
||||
$adapter = new ModelAdapter(ErrorOnlyResponse::class);
|
||||
|
||||
return $adapter->getResponseModel($response);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns filtered members list
|
||||
*
|
||||
|
78
src/Bot/Model/Entity/Tag.php
Normal file
78
src/Bot/Model/Entity/Tag.php
Normal file
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHP version 7.1
|
||||
*
|
||||
* Tag entity
|
||||
*
|
||||
* @package RetailCrm\Mg\Bot\Model\Entity
|
||||
*/
|
||||
|
||||
namespace RetailCrm\Mg\Bot\Model\Entity;
|
||||
|
||||
use JMS\Serializer\Annotation\Accessor;
|
||||
use JMS\Serializer\Annotation\SkipWhenEmpty;
|
||||
use JMS\Serializer\Annotation\Type;
|
||||
use RetailCrm\Mg\Bot\Model\ModelInterface;
|
||||
use Symfony\Component\Validator\Constraints as Assert;
|
||||
|
||||
/**
|
||||
* Tag class
|
||||
*
|
||||
* @package RetailCrm\Mg\Bot\Model\Entity
|
||||
*/
|
||||
class Tag implements ModelInterface
|
||||
{
|
||||
/**
|
||||
* @var string $name
|
||||
*
|
||||
* @Type("string")
|
||||
* @Accessor(getter="getName",setter="setName")
|
||||
*
|
||||
* @Assert\NotBlank
|
||||
*/
|
||||
private $name;
|
||||
|
||||
/**
|
||||
* @var string $colorCode
|
||||
*
|
||||
* @Type("string")
|
||||
* @Accessor(getter="getColorCode",setter="setColorCode")
|
||||
* @SkipWhenEmpty()
|
||||
*/
|
||||
private $colorCode;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
public function getName(): string
|
||||
{
|
||||
return $this->name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $name
|
||||
* @return void
|
||||
*/
|
||||
public function setName(string $name): void
|
||||
{
|
||||
$this->name = $name;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string|null
|
||||
*/
|
||||
public function getColorCode(): ?string
|
||||
{
|
||||
return $this->colorCode;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string $colorCode
|
||||
* @return void
|
||||
*/
|
||||
public function setColorCode(string $colorCode): void
|
||||
{
|
||||
$this->colorCode = $colorCode;
|
||||
}
|
||||
}
|
78
src/Bot/Model/Request/DialogTagRequest.php
Normal file
78
src/Bot/Model/Request/DialogTagRequest.php
Normal file
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* PHP version 7.1
|
||||
*
|
||||
* Dialog add or delete tag request
|
||||
*
|
||||
* @package RetailCrm\Mg\Bot\Model\Request
|
||||
*/
|
||||
|
||||
namespace RetailCrm\Mg\Bot\Model\Request;
|
||||
|
||||
use JMS\Serializer\Annotation\Accessor;
|
||||
use JMS\Serializer\Annotation\SkipWhenEmpty;
|
||||
use JMS\Serializer\Annotation\Type;
|
||||
use RetailCrm\Mg\Bot\Model\Entity\Tag;
|
||||
use RetailCrm\Mg\Bot\Model\ModelInterface;
|
||||
|
||||
/**
|
||||
* DialogTagRequest class
|
||||
*
|
||||
* @package RetailCrm\Mg\Bot\Model\Request
|
||||
*/
|
||||
class DialogTagRequest implements ModelInterface
|
||||
{
|
||||
/**
|
||||
* @var int $dialogId
|
||||
*
|
||||
* @Type("int")
|
||||
* @Accessor(getter="getDialogId", setter="setDialogId")
|
||||
* @SkipWhenEmpty()
|
||||
*/
|
||||
private $dialogId;
|
||||
|
||||
/**
|
||||
* @var Tag[] $tags
|
||||
*
|
||||
* @Type("array")
|
||||
* @Accessor(getter="getTags", setter="setTags")
|
||||
* @SkipWhenEmpty()
|
||||
*/
|
||||
private $tags;
|
||||
|
||||
/**
|
||||
* @return int
|
||||
*/
|
||||
public function getDialogId(): int
|
||||
{
|
||||
return $this->dialogId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param int $dialogId
|
||||
* @return void
|
||||
*/
|
||||
public function setDialogId(int $dialogId): void
|
||||
{
|
||||
$this->dialogId = $dialogId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Tag[]
|
||||
*/
|
||||
public function getTags(): array
|
||||
{
|
||||
return $this->tags;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Tag[] $tags
|
||||
* @return void
|
||||
*/
|
||||
public function setTags(array $tags): void
|
||||
{
|
||||
$this->tags = $tags;
|
||||
}
|
||||
|
||||
}
|
@ -14,7 +14,9 @@ namespace RetailCrm\Mg\Bot\Tests;
|
||||
use InvalidArgumentException;
|
||||
use RetailCrm\Common\Exception\NotFoundException;
|
||||
use RetailCrm\Mg\Bot\Model\Entity\Responsible;
|
||||
use RetailCrm\Mg\Bot\Model\Entity\Tag;
|
||||
use RetailCrm\Mg\Bot\Model\Request\DialogAssignRequest;
|
||||
use RetailCrm\Mg\Bot\Model\Request\DialogTagRequest;
|
||||
use RetailCrm\Mg\Bot\Model\Response\ErrorOnlyResponse;
|
||||
use RetailCrm\Mg\Bot\Test\TestCase;
|
||||
|
||||
@ -145,4 +147,180 @@ class DialogsTest extends TestCase
|
||||
self::assertTrue($response->isSuccessful());
|
||||
self::assertEmpty($response->getErrors());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group("dialogs")
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function testDialogAddTagColorError()
|
||||
{
|
||||
$this->expectException(NotFoundException::class);
|
||||
|
||||
$client = self::getApiClient(
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
$this->getErrorsResponse(404,
|
||||
"'color_code can contain only the following values: " .
|
||||
"light-red; light-blue; light-green; light-orange; light-gray; " .
|
||||
"light-grayish-blue; red; blue; green; orange; gray; grayish-blue'"
|
||||
)
|
||||
);
|
||||
|
||||
$tags[0] = new Tag();
|
||||
$tags[0]->setName('tag1');
|
||||
$tags[0]->setColorCode('qwerty');
|
||||
|
||||
$request = new DialogTagRequest();
|
||||
$request->setDialogId(60);
|
||||
$request->setTags($tags);
|
||||
|
||||
$client->dialogAddTag($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group("dialogs")
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function testDialogAddTagDialogError()
|
||||
{
|
||||
$this->expectException(NotFoundException::class);
|
||||
|
||||
$client = self::getApiClient(
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
$this->getErrorsResponse(404, "dialog #123456789 not found")
|
||||
);
|
||||
|
||||
$tags[0] = new Tag();
|
||||
$tags[0]->setName('tag1');
|
||||
|
||||
$request = new DialogTagRequest();
|
||||
$request->setDialogId(123456789);
|
||||
$request->setTags($tags);
|
||||
|
||||
$client->dialogAddTag($request);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @group("dialogs")
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function testDialogAddTagEmptyTagError()
|
||||
{
|
||||
$this->expectException(\TypeError::class);
|
||||
|
||||
$client = self::getApiClient();
|
||||
|
||||
$tags[0] = new Tag();
|
||||
|
||||
$request = new DialogTagRequest();
|
||||
$request->setDialogId(60);
|
||||
$request->setTags($tags);
|
||||
|
||||
$client->dialogAddTag($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group("dialogs")
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function testDialogAddTag()
|
||||
{
|
||||
$client = self::getApiClient(
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
$this->getResponse('{}')
|
||||
);
|
||||
|
||||
$tags[0] = new Tag();
|
||||
$tags[0]->setName('tag1');
|
||||
$tags[0]->setColorCode('red');
|
||||
|
||||
$tags[1] = new Tag();
|
||||
$tags[1]->setName('tag2');
|
||||
|
||||
$request = new DialogTagRequest();
|
||||
$request->setDialogId(60);
|
||||
$request->setTags($tags);
|
||||
|
||||
$response = $client->dialogAddTag($request);
|
||||
|
||||
self::assertInstanceOF(ErrorOnlyResponse::class, $response);
|
||||
self::assertTrue($response->isSuccessful());
|
||||
self::assertEmpty($response->getErrors());
|
||||
}
|
||||
|
||||
/**
|
||||
* @group("dialogs")
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function testDialogDeleteTagDialogError()
|
||||
{
|
||||
$this->expectException(NotFoundException::class);
|
||||
|
||||
$client = self::getApiClient(
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
$this->getErrorsResponse(404, "dialog #123456789 not found")
|
||||
);
|
||||
|
||||
$tags[0] = new Tag();
|
||||
$tags[0]->setName('tag1');
|
||||
|
||||
$request = new DialogTagRequest();
|
||||
$request->setDialogId(123456789);
|
||||
$request->setTags($tags);
|
||||
|
||||
$client->dialogAddTag($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group("dialogs")
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function testDialogDeleteTagEmptyTagError()
|
||||
{
|
||||
$this->expectException(\TypeError::class);
|
||||
|
||||
$client = self::getApiClient();
|
||||
|
||||
$tags[0] = new Tag();
|
||||
|
||||
$request = new DialogTagRequest();
|
||||
$request->setTags($tags);
|
||||
|
||||
$client->dialogDeleteTag($request);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group("dialogs")
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function testDialogDeleteTag()
|
||||
{
|
||||
$client = self::getApiClient(
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
$this->getResponse('{}')
|
||||
);
|
||||
|
||||
$tags[0] = new Tag();
|
||||
$tags[0]->setName('tag1');
|
||||
|
||||
$request = new DialogTagRequest();
|
||||
$request->setDialogId(60);
|
||||
$request->setTags($tags);
|
||||
|
||||
$response = $client->dialogDeleteTag($request);
|
||||
|
||||
self::assertInstanceOF(ErrorOnlyResponse::class, $response);
|
||||
self::assertTrue($response->isSuccessful());
|
||||
self::assertEmpty($response->getErrors());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user