Tests
This commit is contained in:
parent
42669a71a4
commit
8d034be059
@ -166,7 +166,7 @@ class HttpClient
|
||||
* therefore they are not handled as exceptions
|
||||
*/
|
||||
if (in_array($statusCode, [403, 404, 500])) {
|
||||
throw new \Exception($errorMessage);
|
||||
throw new \InvalidArgumentException($errorMessage);
|
||||
}
|
||||
|
||||
if ($statusCode == 503) {
|
||||
@ -213,7 +213,7 @@ class HttpClient
|
||||
$errors = $validator->validate($class);
|
||||
}
|
||||
|
||||
if ($errors->count() > 0) {
|
||||
if ((is_object($errors) && $errors->count() > 0) || is_string($errors)) {
|
||||
$message = (string) $errors;
|
||||
throw new InvalidArgumentException($message);
|
||||
}
|
||||
|
@ -59,4 +59,11 @@ class CommandEditRequest extends LazyJsonMapper
|
||||
'name' => 'string',
|
||||
'description' => 'string'
|
||||
];
|
||||
|
||||
public function validate()
|
||||
{
|
||||
if (empty($this->getName())) {
|
||||
return 'Empty name';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -58,6 +58,6 @@ class CommonFields extends LazyJsonMapper
|
||||
*/
|
||||
public function isError()
|
||||
{
|
||||
return !empty($this->getErrors());
|
||||
return (bool) !empty($this->getErrors());
|
||||
}
|
||||
}
|
@ -15,7 +15,9 @@ namespace RetailCrm\Mg\Bot\Tests;
|
||||
|
||||
use Exception;
|
||||
use InvalidArgumentException;
|
||||
use RetailCrm\Common\Exception\InvalidJsonException;
|
||||
use RetailCrm\Mg\Bot\Model\Request\CommandEditRequest;
|
||||
use RetailCrm\Mg\Bot\Model\Response\ErrorOnlyResponse;
|
||||
use RetailCrm\Mg\Bot\Test\TestCase;
|
||||
|
||||
/**
|
||||
@ -38,7 +40,12 @@ class CommandsTest extends TestCase
|
||||
{
|
||||
self::expectException(InvalidArgumentException::class);
|
||||
|
||||
$client = self::getApiClient();
|
||||
$client = self::getApiClient(
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
$this->getResponse('EOF',400)
|
||||
);
|
||||
|
||||
$request = new CommandEditRequest();
|
||||
$request->setDescription("qwerty");
|
||||
@ -67,7 +74,12 @@ class CommandsTest extends TestCase
|
||||
*/
|
||||
public function testCommandEdit()
|
||||
{
|
||||
$client = self::getApiClient();
|
||||
$client = self::getApiClient(
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
$this->getJsonResponse('commandEdit')
|
||||
);
|
||||
|
||||
$request = new CommandEditRequest();
|
||||
$request->setBotId(1);
|
||||
@ -76,7 +88,8 @@ class CommandsTest extends TestCase
|
||||
|
||||
$response = $client->commandEdit($request);
|
||||
|
||||
self::assertTrue($response->isSuccessful() == true);
|
||||
self::assertTrue($response instanceof ErrorOnlyResponse);
|
||||
self::assertTrue(!$response->isError());
|
||||
}
|
||||
|
||||
/**
|
||||
@ -86,10 +99,15 @@ class CommandsTest extends TestCase
|
||||
*/
|
||||
public function testCommandDelete()
|
||||
{
|
||||
$client = self::getApiClient();
|
||||
$client = self::getApiClient(
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
$this->getJsonResponse('commandEdit')
|
||||
);
|
||||
|
||||
$response = $client->commandDelete("show_payment_types");
|
||||
|
||||
self::assertTrue($response->isSuccessful() == true);
|
||||
self::assertTrue($response->isError() == false);
|
||||
}
|
||||
}
|
||||
|
@ -35,15 +35,24 @@ class MessagesTest extends TestCase
|
||||
*/
|
||||
public function testMessageSend()
|
||||
{
|
||||
$client = self::getApiClient();
|
||||
$client = self::getApiClient(
|
||||
null,
|
||||
null,
|
||||
false,
|
||||
$this->getResponse(
|
||||
'{"errors":["chat_id is a required field"]}',
|
||||
400
|
||||
)
|
||||
);
|
||||
|
||||
$request = new MessageSendRequest();
|
||||
$request->setChatId(0);
|
||||
$request->setScope(Constants::MESSAGE_SCOPE_PUBLIC);
|
||||
$request->setContent("Hello");
|
||||
|
||||
$request = $client->messageSend($request);
|
||||
$response = $client->messageSend($request);
|
||||
|
||||
self::assertEquals($request->getStatusCode(), 400);
|
||||
self::assertTrue($response->isError());
|
||||
self::assertEquals(1, count($response->getErrors()));
|
||||
}
|
||||
}
|
||||
|
1
tests/Resources/commandEdit.json
Normal file
1
tests/Resources/commandEdit.json
Normal file
@ -0,0 +1 @@
|
||||
{"id":6,"name":"show_payment_types","description":"Get available payment types","created_at":"2019-06-19T09:02:35Z","updated_at":"2019-06-19T09:39:00Z"}
|
Loading…
Reference in New Issue
Block a user