From 5b91648590e93ab62ede28a20eb9d1c2d33e3a6b Mon Sep 17 00:00:00 2001 From: curse89 <58438482+curse89@users.noreply.github.com> Date: Thu, 9 Mar 2023 09:58:39 +0300 Subject: [PATCH] Add notifications section (#159) --- lib/RetailCrm/Client/ApiVersion5.php | 1 + lib/RetailCrm/Methods/V5/Notifications.php | 47 ++++++++ .../Version5/ApiClientNotificationsTest.php | 106 ++++++++++++++++++ 3 files changed, 154 insertions(+) create mode 100644 lib/RetailCrm/Methods/V5/Notifications.php create mode 100644 tests/RetailCrm/Tests/Methods/Version5/ApiClientNotificationsTest.php diff --git a/lib/RetailCrm/Client/ApiVersion5.php b/lib/RetailCrm/Client/ApiVersion5.php index b9af3d6..c4fd5c0 100644 --- a/lib/RetailCrm/Client/ApiVersion5.php +++ b/lib/RetailCrm/Client/ApiVersion5.php @@ -44,6 +44,7 @@ class ApiVersion5 extends AbstractLoader use V5\Delivery; use V5\Files; use V5\Module; + use V5\Notifications; use V5\Orders; use V5\Packs; use V5\References; diff --git a/lib/RetailCrm/Methods/V5/Notifications.php b/lib/RetailCrm/Methods/V5/Notifications.php new file mode 100644 index 0000000..e3121eb --- /dev/null +++ b/lib/RetailCrm/Methods/V5/Notifications.php @@ -0,0 +1,47 @@ +client->makeRequest( + "/notifications/send", + "POST", + ['notification' => \json_encode($notification, JSON_UNESCAPED_SLASHES)] + ); + } +} diff --git a/tests/RetailCrm/Tests/Methods/Version5/ApiClientNotificationsTest.php b/tests/RetailCrm/Tests/Methods/Version5/ApiClientNotificationsTest.php new file mode 100644 index 0000000..c214953 --- /dev/null +++ b/tests/RetailCrm/Tests/Methods/Version5/ApiClientNotificationsTest.php @@ -0,0 +1,106 @@ +expectException($exceptionClass); + } + $response = $client->request->sendNotification($getNotification()); + if (empty($exceptionClass)) { + static::assertTrue(in_array($response->getStatusCode(), [200, 201])); + static::assertTrue($response->isSuccessful()); + } + } + + /** + * @return array[] + */ + public function notificationsProvider() + { + return [ + 'error_type' => [ + static function () { + $notification = self::getErrorNotification(); + $notification['type'] = 'another'; + + return $notification; + }, + 'InvalidArgumentException', + ], + 'error_message' => [ + static function () { + $notification = self::getErrorNotification(); + $notification['message'] = []; + + return $notification; + }, + 'InvalidArgumentException', + ], + 'error_users_empty' => [ + static function () { + $notification = self::getErrorNotification(); + $notification['userGroups'] = []; + $notification['userIds'] = []; + + return $notification; + }, + 'InvalidArgumentException', + ], + 'error_users_filled' => [ + static function () { + return self::getErrorNotification();; + }, + 'InvalidArgumentException', + ], + 'success_group' => [ + static function () { + $notification = self::getErrorNotification(); + unset($notification['userIds']); + + return $notification; + }, + null, + ], + 'success_ids' => [ + static function () { + $notification = self::getErrorNotification(); + unset($notification['userGroups']); + + return $notification; + }, + null, + ], + ]; + } + + /** + * @return array + */ + protected static function getErrorNotification() + { + return [ + 'type' => 'api.error', + 'userIds' => [1], + 'userGroups' => ['superadmins'], + 'message' => '[Модуль МойСклад] +Возникли проблемы при проверке доступов входа. Введен неверный логин/пароль, проверьте корректность введенных данных.', + ]; + } +}