1
0
mirror of synced 2024-12-01 07:16:02 +03:00
mg-bot-api-client-php/tests/Bot/Tests/ClientListTest.php

229 lines
5.4 KiB
PHP
Raw Normal View History

2019-06-10 16:24:22 +03:00
<?php
/**
2019-07-16 15:04:54 +03:00
* PHP version 7.1
2019-06-10 16:24:22 +03:00
*
* Client Test
*
* @package RetailCrm\Mg\Bot\Tests
*/
namespace RetailCrm\Mg\Bot\Tests;
use RetailCrm\Mg\Bot\Model\Constants;
2019-06-17 13:59:14 +03:00
use RetailCrm\Mg\Bot\Model\Entity\Channel;
use RetailCrm\Mg\Bot\Model\Entity\Chat\Chat;
use RetailCrm\Mg\Bot\Model\Entity\Chat\ChatMember;
use RetailCrm\Mg\Bot\Model\Entity\Customer;
2019-06-14 12:48:13 +03:00
use RetailCrm\Mg\Bot\Model\Entity\Dialog;
2019-06-17 13:59:14 +03:00
use RetailCrm\Mg\Bot\Model\Entity\Message\Message;
use RetailCrm\Mg\Bot\Model\Entity\User;
2019-06-10 16:24:22 +03:00
use RetailCrm\Mg\Bot\Model\Request;
use RetailCrm\Mg\Bot\Test\TestCase;
/**
* PHP version 7.0
*
* Class ClientListTest
*
* @package RetailCrm\Mg\Bot\Tests
*/
class ClientListTest extends TestCase
{
/**
* @group("list")
* @throws \Exception
*/
public function testChannels()
{
2019-06-17 13:59:14 +03:00
$client = self::getApiClient(
null,
null,
false,
$this->getJsonResponse('channels')
);
2019-06-10 16:24:22 +03:00
$request = new Request\ChannelsRequest();
$request->setActive(true);
2019-06-17 13:59:14 +03:00
$request->setTypes([Constants::CHANNEL_TYPE_TELEGRAM, Constants::CHANNEL_TYPE_INSTAGRAM]);
2019-06-10 16:24:22 +03:00
$response = $client->channels($request);
2019-10-23 21:35:21 +03:00
static::assertCount(4, $response, "Incorrect channels count");
static::assertInstanceOf(Channel\Channel::class, $response[0], "Incorrect channel instance");
2019-06-10 16:24:22 +03:00
}
/**
* @group("list")
* @throws \Exception
*/
public function testChats()
{
2019-06-17 13:59:14 +03:00
$client = self::getApiClient(
null,
null,
false,
$this->getJsonResponse('chats')
);
2019-06-10 16:24:22 +03:00
$request = new Request\ChatsRequest();
2019-06-17 13:59:14 +03:00
$request->setChannelType(Constants::CHANNEL_TYPE_TELEGRAM);
2019-06-10 16:24:22 +03:00
$response = $client->chats($request);
2019-10-23 21:35:21 +03:00
static::assertCount(2, $response, "Incorrect chats count");
static::assertInstanceOf(Chat::class, $response[0], "Incorrect chat instance");
2019-06-10 16:24:22 +03:00
}
/**
* @group("list")
* @throws \Exception
*/
public function testMembers()
{
2019-06-17 13:59:14 +03:00
$client = self::getApiClient(
null,
null,
false,
$this->getJsonResponse('members')
);
2019-06-10 16:24:22 +03:00
$request = new Request\MembersRequest();
$response = $client->members($request);
2019-10-23 21:35:21 +03:00
static::assertCount(4, $response, "Incorrect members count");
static::assertInstanceOf(ChatMember::class, $response[0], "Incorrect member instance");
2019-06-10 16:24:22 +03:00
}
/**
* @group("list")
* @throws \Exception
*/
public function testMessages()
{
2019-06-17 13:59:14 +03:00
$client = self::getApiClient(
null,
null,
false,
$this->getJsonResponse('messages')
);
2019-06-10 16:24:22 +03:00
$request = new Request\MessagesRequest();
$request->setChannelType(Constants::CHANNEL_TYPE_INSTAGRAM);
$request->setType(Constants::MESSAGE_TYPE_TEXT);
$response = $client->messages($request);
2019-10-23 21:35:21 +03:00
static::assertCount(2, $response, "Incorrect message count");
static::assertInstanceOf(Message::class, $response[0], "Incorrect message instance");
2019-06-10 16:24:22 +03:00
}
/**
* @group("list")
* @throws \Exception
*/
public function testCommands()
{
2019-06-17 13:59:14 +03:00
$client = self::getApiClient(
null,
null,
false,
$this->getResponse('[]')
);
2019-06-10 16:24:22 +03:00
$request = new Request\CommandsRequest();
$response = $client->commands($request);
2019-10-23 21:35:21 +03:00
self::assertCount(0, $response, "Invalid commands count");
2019-06-10 16:24:22 +03:00
}
/**
* @group("list")
* @throws \Exception
*/
public function testBots()
{
2019-06-17 13:59:14 +03:00
$client = self::getApiClient(
null,
null,
false,
$this->getJsonResponse('bots')
);
2019-06-10 16:24:22 +03:00
$request = new Request\BotsRequest();
$request->setActive(1);
$request->setRoles([Constants::BOT_ROLE_RESPONSIBLE]);
2019-06-14 08:56:11 +03:00
$data = $client->bots($request);
2019-06-10 16:24:22 +03:00
2019-10-23 21:35:21 +03:00
static::assertCount(3, $data);
2019-06-10 16:24:22 +03:00
}
/**
* @group("list")
* @throws \Exception
*/
public function testUsers()
{
$client = self::getApiClient(
null,
null,
false,
$this->getJsonResponse('users')
);
2019-06-10 16:24:22 +03:00
$request = new Request\UsersRequest();
$request->setActive(1);
$request->setOnline(0);
$response = $client->users($request);
2019-10-23 21:35:21 +03:00
self::assertCount(2, $response);
self::assertInstanceOf(User::class, $response[0]);
2019-06-10 16:24:22 +03:00
}
/**
* @group("list")
* @throws \Exception
*/
public function testDialogs()
{
$client = self::getApiClient(
null,
null,
false,
$this->getJsonResponse('dialogs')
);
2019-06-10 16:24:22 +03:00
$request = new Request\DialogsRequest();
$request->setActive(1);
$request->setAssign(1);
$response = $client->dialogs($request);
2019-10-23 21:35:21 +03:00
self::assertCount(2, $response);
self::assertInstanceOf(Dialog::class, $response[0]);
2019-06-10 16:24:22 +03:00
}
/**
* @group("list")
* @throws \Exception
*/
public function testCustomers()
{
$client = self::getApiClient(
null,
null,
false,
$this->getJsonResponse('customers')
);
2019-06-10 16:24:22 +03:00
$request = new Request\CustomersRequest();
$response = $client->customers($request);
2019-10-23 21:35:21 +03:00
self::assertCount(2, $response);
self::assertInstanceOf(Customer::class, $response[0]);
2019-06-10 16:24:22 +03:00
}
}