From a04d4b06054b024255ede3ba49e04eb32df074b2 Mon Sep 17 00:00:00 2001 From: Pavel Date: Mon, 24 Jun 2019 09:11:56 +0300 Subject: [PATCH] Full test case for messages --- tests/Bot/Tests/MessagesTest.php | 121 ++++++++++++++++++++++++++++++- 1 file changed, 120 insertions(+), 1 deletion(-) diff --git a/tests/Bot/Tests/MessagesTest.php b/tests/Bot/Tests/MessagesTest.php index 52c2400..e38d6ff 100644 --- a/tests/Bot/Tests/MessagesTest.php +++ b/tests/Bot/Tests/MessagesTest.php @@ -14,6 +14,7 @@ namespace RetailCrm\Mg\Bot\Tests; use RetailCrm\Mg\Bot\Model\Constants; +use RetailCrm\Mg\Bot\Model\Request\MessageEditRequest; use RetailCrm\Mg\Bot\Model\Request\MessageSendRequest; use RetailCrm\Mg\Bot\Test\TestCase; @@ -33,7 +34,7 @@ class MessagesTest extends TestCase * @group("messages") * @throws \Exception */ - public function testMessageSend() + public function testMessageSendError() { $client = self::getApiClient( null, @@ -55,4 +56,122 @@ class MessagesTest extends TestCase self::assertTrue(!$response->isSuccessful()); self::assertEquals(1, count($response->getErrors())); } + + /** + * @group("messages") + * @throws \Exception + */ + public function testMessageSend() + { + $client = self::getApiClient( + null, + null, + false, + $this->getResponse( + '{"message_id":3636,"time":"2019-06-24T06:02:04.434291791Z"}', + 201 + ) + ); + + $request = new MessageSendRequest(); + $request->setChatId(28); + $request->setScope(Constants::MESSAGE_SCOPE_PUBLIC); + $request->setContent("Hello"); + + $response = $client->messageSend($request); + + self::assertTrue($response->isSuccessful()); + self::assertEquals(0, count($response->getErrors())); + self::assertEquals(3636, $response->getMessageId()); + } + + /** + * @group("messages") + * @throws \Exception + */ + public function testMessageEditError() + { + $client = self::getApiClient( + null, + null, + false, + $this->getErrorsResponse( + 400, + 'Incorrect message_id' + ) + ); + + $request = new MessageEditRequest(); + $request->setId(0); + $request->setContent("Hello"); + + $response = $client->messageEdit($request); + + self::assertTrue(!$response->isSuccessful()); + self::assertEquals(1, count($response->getErrors())); + } + + /** + * @group("messages") + * @throws \Exception + */ + public function testMessageEdit() + { + $client = self::getApiClient( + null, + null, + false, + $this->getResponse('{}', 200) + ); + + $request = new MessageEditRequest(); + $request->setId(3636); + $request->setContent("123"); + + $response = $client->messageEdit($request); + + self::assertTrue($response->isSuccessful()); + self::assertEquals(0, count($response->getErrors())); + } + + /** + * @group("messages") + * @throws \Exception + */ + public function testMessageDeleteError() + { + $client = self::getApiClient( + null, + null, + false, + $this->getErrorsResponse( + 400, + 'Incorrect message_id' + ) + ); + + $response = $client->messageDelete('0'); + + self::assertTrue(!$response->isSuccessful()); + self::assertEquals(1, count($response->getErrors())); + } + + /** + * @group("messages") + * @throws \Exception + */ + public function testMessageDelete() + { + $client = self::getApiClient( + null, + null, + false, + $this->getResponse('{}', 200) + ); + + $response = $client->messageDelete('3636'); + + self::assertTrue($response->isSuccessful()); + self::assertEquals(0, count($response->getErrors())); + } }