1
0
mirror of synced 2024-11-22 20:06:01 +03:00
mg-bot-api-client-php/tests/Bot/Tests/DialogsTest.php

149 lines
3.4 KiB
PHP
Raw Normal View History

2019-06-21 11:36:15 +03:00
<?php
/**
* PHP version 7.0
*
* Dialogs Test
*
* @package RetailCrm\Mg\Bot\Tests
2019-07-16 15:04:54 +03:00
* @category Test
2019-06-21 11:36:15 +03:00
*/
namespace RetailCrm\Mg\Bot\Tests;
use InvalidArgumentException;
2019-07-16 15:20:56 +03:00
use RetailCrm\Common\Exception\NotFoundException;
2019-06-21 11:36:15 +03:00
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
*/
class DialogsTest extends TestCase
{
/**
* @group("dialogs")
* @throws \Exception
*/
public function testDialogAssignError()
{
2019-07-16 15:20:56 +03:00
$this->expectException(\RuntimeException::class);
2019-06-21 11:36:15 +03:00
$client = self::getApiClient(
null,
null,
false,
2019-06-21 17:51:57 +03:00
$this->getErrorsResponse(400, "incorrect dialog_id")
2019-06-21 11:36:15 +03:00
);
$request = new DialogAssignRequest();
$request->setDialogId(-1);
2019-07-16 15:20:56 +03:00
$client->dialogAssign($request);
2019-06-21 11:36:15 +03:00
}
/**
* @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 testDialogUnassignError()
{
$this->expectException(\RuntimeException::class);
$client = self::getApiClient(
null,
null,
false,
$this->getErrorsResponse(400, "incorrect dialog_id")
);
$client->dialogUnassign(-1);
}
/**
* @group("dialogs")
* @throws \Exception
*/
public function testDialogUnassign()
{
$client = self::getApiClient(
null,
null,
false,
$this->getJsonResponse('dialogUnassigned')
);
$response = $client->dialogUnassign(60);
self::assertTrue($response->isSuccessful());
self::assertTrue($response->getPreviousResponsible() instanceof Responsible);
}
2019-06-21 11:36:15 +03:00
/**
* @group("dialogs")
* @throws \Exception
*/
public function testDialogCloseError()
{
2019-07-16 15:20:56 +03:00
self::expectException(NotFoundException::class);
2019-06-21 11:36:15 +03:00
$client = self::getApiClient(
null,
null,
false,
2019-06-21 17:51:57 +03:00
$this->getErrorsResponse(404, "dialog #2131231231 not found")
2019-06-21 11:36:15 +03:00
);
$client->dialogClose('2131231231');
}
/**
* @group("dialogs")
* @throws \Exception
*/
public function testDialogClose()
{
$client = self::getApiClient(
null,
null,
false,
$this->getResponse('{}')
);
$response = $client->dialogClose('62');
2019-10-23 21:35:21 +03:00
self::assertInstanceOF(ErrorOnlyResponse::class, $response);
2019-06-21 11:36:15 +03:00
self::assertTrue($response->isSuccessful());
self::assertEmpty($response->getErrors());
}
}