1
0
mirror of synced 2024-11-22 03:46:02 +03:00
mg-bot-api-client-php/tests/Bot/Tests/ClientListTest.php

260 lines
6.4 KiB
PHP
Raw Permalink 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;
2023-02-07 12:04:37 +03:00
use Psr\Http\Message\ResponseInterface;
use RetailCrm\Mg\Bot\Client;
use RetailCrm\Mg\Bot\HttpClient;
2019-06-10 16:24:22 +03:00
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);
2023-01-20 13:06:36 +03:00
static::assertCount(5, $response, "Incorrect channels count");
2019-10-23 21:35:21 +03:00
static::assertInstanceOf(Channel\Channel::class, $response[0], "Incorrect channel instance");
2024-02-05 19:21:42 +03:00
$textSuggestions = $response[0]->getSettings()->getSuggestions()->getText();
static::assertStringContainsString("both", $textSuggestions, "Incorrect text suggestions");
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);
2023-01-20 13:06:36 +03:00
static::assertCount(3, $response, "Incorrect chats count");
2019-10-23 21:35:21 +03:00
static::assertInstanceOf(Chat::class, $response[0], "Incorrect chat instance");
2019-06-10 16:24:22 +03:00
}
/**
* @group("list")
* @throws \Exception
*/
public function testGetChatsByCustomerId(): void
{
$client = self::getApiClient(
null,
null,
false,
$this->getJsonResponse('chatsByCustomerId')
);
$request = new Request\ChatsRequest();
$request->setCustomerId(39);
$response = $client->chats($request);
static::assertCount(1, $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);
2023-01-20 13:06:36 +03:00
static::assertCount(5, $response, "Incorrect members count");
2019-10-23 21:35:21 +03:00
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);
2023-10-26 09:50:02 +03:00
$request->setLimit(1000);
2019-06-10 16:24:22 +03:00
$response = $client->messages($request);
2023-01-20 13:06:36 +03:00
static::assertCount(3, $response, "Incorrect message count");
2019-10-23 21:35:21 +03:00
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
2023-01-20 13:06:36 +03:00
static::assertCount(4, $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);
2023-01-20 13:06:36 +03:00
self::assertCount(3, $response);
2019-10-23 21:35:21 +03:00
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);
2023-01-20 13:06:36 +03:00
self::assertCount(3, $response);
2019-10-23 21:35:21 +03:00
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);
2023-01-20 13:06:36 +03:00
self::assertCount(3, $response);
2019-10-23 21:35:21 +03:00
self::assertInstanceOf(Customer::class, $response[0]);
2024-05-21 20:19:22 +03:00
$utm = $response[0]->getUtm()->getCampaign();
static::assertEquals('spring_sale', $utm, "Incorrect utm data");
2019-06-10 16:24:22 +03:00
}
}